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