annotate NGSrich_0.5.5/src/datastructures/TargetLine.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 import exceptions.ChromosomeFormatException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
6 import exceptions.ChromosomeNotFoundException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
7 import exceptions.NullOrNegativeRangeException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
8 import exceptions.RangeFormatException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
9 import exceptions.RangeLimitNotFoundException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
10
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
11 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
12 * Represents a target Line from the target file.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
13 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
14 * @author Ali Abdallah
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
15 * @version 19.07.2011
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
16 * @since Java 1.6
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
17 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
18
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
19 public class TargetLine {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
20
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
21 String line;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
22 String chrom;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
23 int start, end;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
24
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
25 public TargetLine(String line) throws RangeFormatException,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
26 ChromosomeFormatException,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
27 ChromosomeNotFoundException,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
28 RangeLimitNotFoundException,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
29 NullOrNegativeRangeException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
30 this.line = line;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
31 Scanner s = new Scanner(line);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
32 if(s.hasNext()){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
33 chrom = s.next();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
34 if(!(chrom.toLowerCase().startsWith("chr") || chrom.equals("*")))
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
35 throw new ChromosomeFormatException(chrom);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
36 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
37 else
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
38 throw new ChromosomeNotFoundException();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
39
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
40 if(s.hasNextInt()){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
41 start = s.nextInt();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
42 if(start < 0){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
43 throw new RangeFormatException("Start position of the target must be a " +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
44 "positive integer.");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
45 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
46 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
47 else if(!s.hasNext())
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
48 throw new RangeLimitNotFoundException("No target range start found!");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
49 else
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
50 throw new RangeFormatException("Target start position" +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
51 " is not an integer. It must be a positive" +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
52 " integer."+ " Found: "+start);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
53
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
54 if(s.hasNextInt()){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
55 end = s.nextInt();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
56 if(end < 0){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
57 throw new RangeFormatException("Target end position must be a positive " +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
58 "integer."+ " Found: "+end);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
59 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
60 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
61 else if(!s.hasNext())
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
62 throw new RangeLimitNotFoundException("No range end found!");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
63 else
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
64 throw new RangeFormatException("Found: "+end+". End position ist not an integer. " +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
65 "It must be a positive integer.");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
66
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
67 if(start >= end)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
68 throw new NullOrNegativeRangeException("Target line \""+line+"\"");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
69 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
70
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
71 public String chrom(){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
72 return chrom;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
73 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
74
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
75 public int start(){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
76 return start;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
77 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
78
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
79 public int end(){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
80 return end;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
81 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
82
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
83 public String toString(){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
84 return line;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
85 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
86
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
87 }