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