comparison NGSrich_0.5.5/src/datastructures/AnnotationLine.java @ 0:89ad0a9cca52 default tip

Uploaded
author pfrommolt
date Mon, 21 Nov 2011 08:12:19 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:89ad0a9cca52
1 package datastructures;
2
3 import java.util.Scanner;
4
5 public class AnnotationLine implements Comparable<Object>{
6
7 String seqName, chrom, gene;
8 int start, end;
9
10 public AnnotationLine(String seqName, String chrom, String gene,
11 int start, int end){
12 this.seqName = seqName;
13 this.chrom = chrom;
14 this.gene = gene;
15 this.start = start;
16 this.end = end;
17 }
18
19 public AnnotationLine(String line){
20 Scanner s = new Scanner(line);
21 seqName = s.next();
22 this.chrom = s.next();
23 this.start = s.nextInt();
24 this.end = s.nextInt();
25 this.gene = s.next();
26 }
27
28 public String seqName() {
29 return seqName;
30 }
31
32 public String chrom() {
33 return chrom;
34 }
35
36 public String gene() {
37 return gene;
38 }
39
40 public int start() {
41 return start;
42 }
43
44 public int end() {
45 return end;
46 }
47
48 public static AnnotationLine targetLine(String chrom, int tstart, int tend){
49 return new AnnotationLine("000\t"+chrom+"\t"+tstart+"\t"+tend+"\tdummy");
50 }
51
52 public int compareTo(Object otherLine) {
53 AnnotationLine other = (AnnotationLine)otherLine;
54
55 if(chrom.compareTo(other.chrom()) < 0
56 && !other.gene.equals("dummy"))
57 return -1;
58 else if(chrom.compareTo(other.chrom()) > 0
59 && !other.chrom().equals("dummy"))
60 return 1;
61 else{
62 /*
63 * 1. Eine Region überlappt mit einem Gen, wenn einer der folgenden
64 * 3 Fälle eintritt:
65 * a) Targetanfang kleiner als Genanfang und Targetende größer als
66 * Genende. (Gen ganz im Target enthalten)
67 * b) Targetanfang liegt zwischen Genanfang und Genende.
68 * c) Targetende liegt zwischen Genanfang und Genende.
69 */
70
71 // Für Targetsuche
72 if(this.gene().equals("dummy") &&
73 this.chrom().equals(other.chrom()) && (
74 (this.start() <= other.start() && this.end() >= other.end()) ||
75 (this.start() >= other.start() && this.start() <= other.end()) ||
76 (this.end() >= other.start() && this.end() <= other.end())
77 )
78 )
79 return 0;
80 // Für Gensuche zu Insertzwecken.
81 else if(start < other.start())
82 return -1;
83 else if(start > other.start())
84 return 1;
85 else{
86 if(end < other.end())
87 return -1;
88 else if(end > other.end())
89 return 1;
90 else return 0;
91 }
92 }
93 }
94
95 public String toString(){
96 return seqName +"\t" + chrom + "\t" + start + "\t" + end + "\t" + gene;
97 }
98
99 }