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