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