Debian Codegraph @

current/align2/AbstractIndex.java

raw symbols SCIP
1 package align2;
2
3 import java.util.ArrayList;
4
5 import shared.Shared;
6 import stream.SiteScore;
7
8 /**
9 * @author Brian Bushnell
10 * @date Oct 15, 2013
11 *
12 */
13 public abstract class AbstractIndex {
14
15 AbstractIndex(int keylen, int kfilter, int pointsMatch, int minChrom_, int maxChrom_, MSA msa_){
16 KEYLEN=keylen;
17 KEYSPACE=1<<(2*KEYLEN);
18 BASE_KEY_HIT_SCORE=pointsMatch*KEYLEN;
19 KFILTER=kfilter;
20 msa=msa_;
21
22 minChrom=minChrom_;
23 maxChrom=maxChrom_;
24 assert(minChrom==MINCHROM);
25 assert(maxChrom==MAXCHROM);
26 assert(minChrom<=maxChrom);
27 }
28
29 final int count(int key){
30 // assert(false);
31 if(COUNTS!=null){return COUNTS[key];} //TODO: Benchmark speed and memory usage with counts=null. Probably only works for single-block genomes.
32 // assert(false);
33 final Block b=index[0];
34 final int rkey=KeyRing.reverseComplementKey(key, KEYLEN);
35 int a=b.length(key);
36 return key==rkey ? a : a+b.length(rkey);
37 }
38
39 static final boolean overlap(int a1, int b1, int a2, int b2){
40 assert(a1<=b1 && a2<=b2) : a1+", "+b1+", "+a2+", "+b2;
41 return a2<=b1 && b2>=a1;
42 }
43
44 /** Is (a1, b1) within (a2, b2) ? */
45 static final boolean isWithin(int a1, int b1, int a2, int b2){
46 assert(a1<=b1 && a2<=b2) : a1+", "+b1+", "+a2+", "+b2;
47 return a1>=a2 && b1<=b2;
48 }
49
50
51 /** Generates a term that increases score with how far apart the two farthest perfect matches are.
52 * Assumes that the centerIndex corresponds to the leftmost perfect match. */
53 final static int scoreY(int[] locs, int centerIndex, int offsets[]){
54 int center=locs[centerIndex];
55 // int rightIndex=centerIndex;
56 // for(int i=centerIndex; i<offsets.length; i++){
57 // if(locs[i]==center){
58 // rightIndex=i;
59 // }
60 // }
61
62 int rightIndex=-1;
63 for(int i=offsets.length-1; rightIndex<centerIndex; i--){
64 if(locs[i]==center){
65 rightIndex=i;
66 }
67 }
68
69 //Assumed to not be necessary.
70 // for(int i=0; i<centerIndex; i++){
71 // if(locs[i]==center){
72 // centerIndex=i;
73 // }
74 // }
75
76 return offsets[rightIndex]-offsets[centerIndex];
77 }
78
79 abstract float[] keyProbArray();
80 abstract byte[] getBaseScoreArray(int len, int strand);
81 abstract int[] getKeyScoreArray(int len, int strand);
82
83 abstract int maxScore(int[] offsets, byte[] baseScores, int[] keyScores, int readlen, boolean useQuality);
84 public abstract ArrayList<SiteScore> findAdvanced(byte[] basesP, byte[] basesM, byte[] qual, byte[] baseScoresP, int[] keyScoresP, int[] offsets, long id);
85
86 long callsToScore=0;
87 long callsToExtendScore=0;
88 long initialKeys=0;
89 long initialKeyIterations=0;
90 long initialKeys2=0;
91 long initialKeyIterations2=0;
92 long usedKeys=0;
93 long usedKeyIterations=0;
94
95 static final int HIT_HIST_LEN=40;
96 final long[] hist_hits=new long[HIT_HIST_LEN+1];
97 final long[] hist_hits_score=new long[HIT_HIST_LEN+1];
98 final long[] hist_hits_extend=new long[HIT_HIST_LEN+1];
99
100 final int minChrom;
101 final int maxChrom;
102
103 static int MINCHROM=1;
104 static int MAXCHROM=Integer.MAX_VALUE;
105
106 static final boolean SUBSUME_SAME_START_SITES=true; //Not recommended if slow alignment is disabled.
107 static final boolean SUBSUME_SAME_STOP_SITES=true; //Not recommended if slow alignment is disabled.
108
109 /**
110 * True: Slightly slower.<br>
111 * False: Faster, but may mask detection of some ambiguously mapping reads.
112 */
113 static final boolean LIMIT_SUBSUMPTION_LENGTH_TO_2X=true;
114
115 /** Not recommended if slow alignment is disabled. Can conceal sites that should be marked as amiguous. */
116 static final boolean SUBSUME_OVERLAPPING_SITES=false;
117
118 static final boolean SHRINK_BEFORE_WALK=true;
119
120 /** More accurate but uses chromosome arrays while mapping */
121 static final boolean USE_EXTENDED_SCORE=true; //Calculate score more slowly by extending keys
122
123 /** Even more accurate but even slower than normal extended score calculation.
124 * Scores are compatible with slow-aligned scores. */
125 static final boolean USE_AFFINE_SCORE=true && USE_EXTENDED_SCORE; //Calculate score even more slowly
126
127
128 public static final boolean RETAIN_BEST_SCORES=true;
129 public static final boolean RETAIN_BEST_QCUTOFF=true;
130
131 public static boolean QUIT_AFTER_TWO_PERFECTS=true;
132 static final boolean DYNAMICALLY_TRIM_LOW_SCORES=true;
133
134
135 static final boolean REMOVE_CLUMPY=true; //Remove keys like AAAAAA or GCGCGC that self-overlap and thus occur in clumps
136
137
138 /** If no hits are found, search again with slower parameters (less of genome excluded) */
139 static final boolean DOUBLE_SEARCH_NO_HIT=false;
140 /** Only this fraction of the originally removed genome fraction (FRACTION_GENOME_TO_EXCLUDE)
141 * is removed for the second pass */
142 static final float DOUBLE_SEARCH_THRESH_MULT=0.25f; //Must be less than 1.
143
144 static boolean PERFECTMODE=false;
145 static boolean SEMIPERFECTMODE=false;
146
147 static boolean REMOVE_FREQUENT_GENOME_FRACTION=true;//Default true; false is more accurate
148 static boolean TRIM_BY_GREEDY=true;//default: true
149
150 /** Ignore longest site list(s) when doing a slow walk. */
151 static final boolean TRIM_LONG_HIT_LISTS=false; //Increases speed with tiny loss of accuracy. Default: true for clean or synthetic, false for noisy real data
152
153 public static int MIN_APPROX_HITS_TO_KEEP=1; //Default 2 for skimmer, 1 otherwise, min 1; lower is more accurate
154
155
156 public static final boolean TRIM_BY_TOTAL_SITE_COUNT=false; //default: false
157 /** Length histogram index of maximum average hit list length to use.
158 * The max number of sites to search is calculated by (#keys)*(lengthHistogram[chrom][MAX_AVERAGE_SITES_TO_SEARCH]).
159 * Then, while the actual number of sites exceeds this, the longest hit list should be removed.
160 */
161
162 static int MAX_USABLE_LENGTH=Integer.MAX_VALUE;
163 static int MAX_USABLE_LENGTH2=Integer.MAX_VALUE;
164
165
166 public static void clear(){
167 index=null;
168 lengthHistogram=null;
169 COUNTS=null;
170 }
171
172 static Block[] index;
173 static int[] lengthHistogram=null;
174 static int[] COUNTS=null;
175
176 final int KEYLEN; //default 12, suggested 10 ~ 13, max 15; bigger is faster but uses more RAM
177 final int KEYSPACE;
178 /** Site must have at least this many contiguous matches */
179 final int KFILTER;
180 final MSA msa;
181 final int BASE_KEY_HIT_SCORE;
182
183
184 boolean verbose=false;
185 static boolean verbose2=false;
186
187 static boolean SLOW=false;
188 static boolean VSLOW=false;
189
190 static int NUM_CHROM_BITS=3;
191 static int CHROMS_PER_BLOCK=(1<<(NUM_CHROM_BITS));
192
193 static final int MINGAP=Shared.MINGAP;
194 static final int MINGAP2=(MINGAP+128); //Depends on read length...
195
196 static boolean USE_CAMELWALK=false;
197
198 static final boolean ADD_LIST_SIZE_BONUS=false;
199 static final byte[] LIST_SIZE_BONUS=new byte[100];
200
201 public static boolean GENERATE_KEY_SCORES_FROM_QUALITY=true; //True: Much faster and more accurate.
202 public static boolean GENERATE_BASE_SCORES_FROM_QUALITY=true; //True: Faster, and at least as accurate.
203
204 static final int calcListSizeBonus(int[] array){
205 if(array==null || array.length>LIST_SIZE_BONUS.length-1){return 0;}
206 return LIST_SIZE_BONUS[array.length];
207 }
208
209 static final int calcListSizeBonus(int size){
210 if(size>LIST_SIZE_BONUS.length-1){return 0;}
211 return LIST_SIZE_BONUS[size];
212 }
213
214 static{
215 final int len=LIST_SIZE_BONUS.length;
216 // for(int i=1; i<len; i++){
217 // int x=(int)((len/(Math.sqrt(i)))/5)-1;
218 // LIST_SIZE_BONUS[i]=(byte)(x/2);
219 // }
220 LIST_SIZE_BONUS[0]=3;
221 LIST_SIZE_BONUS[1]=2;
222 LIST_SIZE_BONUS[2]=1;
223 LIST_SIZE_BONUS[len-1]=0;
224 // System.err.println(Arrays.toString(LIST_SIZE_BONUS));
225 }
226
227 }