Debian Codegraph @

current/jgi/Orf.java

raw symbols SCIP
1 package jgi;
2
3 import java.util.Arrays;
4
5 import shared.Tools;
6 import structures.CoverageArray;
7
8 /**
9 * This class is designed to help calculate coverage of ORFs
10 * @author Brian Bushnell
11 * @date May 13, 2013
12 *
13 */
14 public class Orf implements Comparable<Orf>{
15
16 public Orf(String name_, int start_, int stop_, byte strand_){
17 name=name_;
18 start=start_;
19 stop=stop_;
20 strand=strand_;
21 assert(stop>start || (start==0 && stop==0));
22 }
23
24 @Override
25 public String toString(){
26 return name+"\t"+start+"\t"+stop+"\t"+strand;
27 }
28
29 public int length(){return stop-start+1;}
30
31 public double avgCoverage(){
32 int len=length();
33 return len<=0 ? 0 : baseDepth/(double)len;
34 }
35
36 public double fractionCovered(){
37 int len=length();
38 return len<=0 ? 0 : baseCoverage/(double)len;
39 }
40
41 public int[] readCoverageArray(CoverageArray ca){
42
43 final int len=length();
44 if(len<1 || ca==null){return null;}
45 final int[] array=new int[len];
46
47 baseCoverage=0;
48 baseDepth=0;
49 minDepth=Integer.MAX_VALUE;
50 maxDepth=0;
51 medianDepth=0;
52 stdevDepth=0;
53
54 for(int i=start, j=0; i<=stop; i++, j++){
55 int cov=ca.get(i);
56 array[j]=cov;
57 if(cov>1){
58 baseCoverage++;
59 baseDepth+=cov;
60 minDepth=Tools.min(minDepth, cov);
61 maxDepth=Tools.max(maxDepth, cov);
62 }
63 }
64 if(baseDepth>0){
65 Arrays.sort(array);
66 medianDepth=array[array.length/2];
67 stdevDepth=Tools.standardDeviation(array);
68 }
69 return array;
70 }
71
72 @Override
73 public int compareTo(Orf o) {
74 int x=name.compareTo(o.name);
75 if(x!=0){return x;}
76 x=o.start-start;
77 if(x!=0){return x;}
78 x=o.stop-stop;
79 if(x!=0){return x;}
80 return o.strand-strand;
81 }
82
83 @Override
84 public boolean equals(Object o){return equals((Orf)o);}
85 public boolean equals(Orf o){return compareTo(o)==0;}
86
87 @Override
88 public int hashCode(){return Integer.rotateLeft(name.hashCode(),16)^(start<<8)^(stop)^strand;}
89
90 /** Name of ORF (not necessarily the name of its scaffold) */
91 public String name;
92 public int start;
93 public int stop;
94 public byte strand;
95
96 /** Number of bases with nonzero coverage */
97 public long baseCoverage;
98 /** Number of reads mapped to this orf */
99 public long readDepth=0;
100 /** Number of bases mapped to this orf */
101 public long baseDepth=0;
102 /** Lowest base depth */
103 public long minDepth=0;
104 /** Highest base depth */
105 public long maxDepth=0;
106 /** Median base depth */
107 public long medianDepth=0;
108 /** Standard deviation of depth */
109 public double stdevDepth=0;
110
111
112 }