| 1 |
package structures; |
| 2 |
import dna.Data; |
| 3 |
import fileIO.ReadWrite; |
| 4 |
import shared.KillSwitch; |
| 5 |
import shared.Tools; |
| 6 |
|
| 7 |
|
| 8 |
public class CoverageArray2 extends CoverageArray { |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
private static final long serialVersionUID = 8242586595591123194L; |
| 14 |
|
| 15 |
public static void main(String[] args){ |
| 16 |
runSpeedTest(args); |
| 17 |
|
| 18 |
|
| 19 |
} |
| 20 |
|
| 21 |
public static void runSpeedTest(String[] args){ |
| 22 |
|
| 23 |
long time1=System.nanoTime(); |
| 24 |
|
| 25 |
CoverageArray2 ca=(CoverageArray2)read(args[1]); |
| 26 |
ca.chromosome=Byte.parseByte(args[0]); |
| 27 |
long time2=System.nanoTime(); |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
args[1]=args[1].replace('\\', '/'); |
| 33 |
int slash=args[1].lastIndexOf('/'); |
| 34 |
String outfile; |
| 35 |
if(slash<1){ |
| 36 |
outfile="coverage-chr"+ca.chromosome+"-build"+Data.GENOME_BUILD+".ca"; |
| 37 |
}else{ |
| 38 |
outfile=args[1].substring(0,slash+1)+"coverage-chr"+ca.chromosome+"-build"+Data.GENOME_BUILD+".ca"; |
| 39 |
} |
| 40 |
|
| 41 |
System.out.println("minIndex="+ca.minIndex+", maxIndex="+ca.maxIndex+", length="+ca.array.length+ |
| 42 |
"; time="+Tools.format("%.3f seconds", (time2-time1)/1000000000d)); |
| 43 |
|
| 44 |
long time3=System.nanoTime(); |
| 45 |
ReadWrite.write(ca, outfile, false); |
| 46 |
ca=null; |
| 47 |
System.gc(); |
| 48 |
ca=(CoverageArray2)read(outfile); |
| 49 |
long time4=System.nanoTime(); |
| 50 |
|
| 51 |
System.out.println("minIndex="+ca.minIndex+", maxIndex="+ca.maxIndex+", length="+ca.array.length+ |
| 52 |
"; time="+Tools.format("%.3f seconds", (time4-time3)/1000000000d)); |
| 53 |
|
| 54 |
|
| 55 |
} |
| 56 |
|
| 57 |
public CoverageArray2(int chrom, int len){ |
| 58 |
super(chrom, len); |
| 59 |
array=KillSwitch.allocChar1D(len); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
@Override |
| 67 |
public void increment(int loc, int amt) { |
| 68 |
set(loc, get(loc)+amt); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
@Override |
| 75 |
public void increment(int loc) { |
| 76 |
set(loc, get(loc)+1); |
| 77 |
} |
| 78 |
|
| 79 |
@Override |
| 80 |
public synchronized void incrementRangeSynchronized(int min, int max, int amt) { |
| 81 |
incrementRange(min, max, amt); |
| 82 |
} |
| 83 |
|
| 84 |
@Override |
| 85 |
public void incrementRange(int min, int max, int amt) { |
| 86 |
if(min<0){min=0;} |
| 87 |
if(max>=array.length){ |
| 88 |
int newlen=1+(7*max(array.length, max))/4; |
| 89 |
assert(newlen>max); |
| 90 |
resize(newlen); |
| 91 |
assert(array.length==newlen); |
| 92 |
}else if(max<0){max=-1;} |
| 93 |
for(int i=min; i<=max; i++){ |
| 94 |
int val=array[i]+amt; |
| 95 |
if(val>Character.MAX_VALUE){ |
| 96 |
val=Character.MAX_VALUE; |
| 97 |
if(!OVERFLOWED){ |
| 98 |
System.err.println("Note: Coverage capped at "+(int)(Character.MAX_VALUE)+"; please use the flag 32bit for higher values."); |
| 99 |
OVERFLOWED=true; |
| 100 |
} |
| 101 |
} |
| 102 |
array[i]=(char)val; |
| 103 |
} |
| 104 |
minIndex=min(min, minIndex); |
| 105 |
maxIndex=max(max, maxIndex); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
@Override |
| 110 |
public void set(int loc, int val){ |
| 111 |
|
| 112 |
if(loc>=array.length){ |
| 113 |
int newlen=1+(7*max(array.length, loc))/4; |
| 114 |
assert(newlen>loc); |
| 115 |
resize(newlen); |
| 116 |
assert(array.length==newlen); |
| 117 |
}else if(loc<0){ |
| 118 |
|
| 119 |
|
| 120 |
return; |
| 121 |
} |
| 122 |
|
| 123 |
if(val>Character.MAX_VALUE && !OVERFLOWED){ |
| 124 |
System.err.println("Note: Coverage capped at "+(int)(Character.MAX_VALUE)+"; please use the flag 32bit for higher values."); |
| 125 |
OVERFLOWED=true; |
| 126 |
} |
| 127 |
array[loc]=(val>Character.MAX_VALUE ? Character.MAX_VALUE : (char)val); |
| 128 |
minIndex=min(loc, minIndex); |
| 129 |
maxIndex=max(loc, maxIndex); |
| 130 |
} |
| 131 |
|
| 132 |
@Override |
| 133 |
public int get(int loc){ |
| 134 |
return loc>=array.length || loc<0 ? 0 : array[loc]; |
| 135 |
} |
| 136 |
|
| 137 |
@Override |
| 138 |
public void resize(int newlen){ |
| 139 |
|
| 140 |
char[] temp=KillSwitch.allocChar1D(newlen); |
| 141 |
int lim=min(array.length, newlen); |
| 142 |
assert(lim>maxIndex) : lim+","+maxIndex; |
| 143 |
for(int i=0; i<lim; i++){ |
| 144 |
temp[i]=array[i]; |
| 145 |
} |
| 146 |
array=temp; |
| 147 |
} |
| 148 |
|
| 149 |
@Override |
| 150 |
public String toString(){ |
| 151 |
StringBuilder sb=new StringBuilder(); |
| 152 |
sb.append('['); |
| 153 |
for(int i=0; i<=maxIndex; i++){ |
| 154 |
if(i>0){sb.append(", ");} |
| 155 |
sb.append((int)array[i]); |
| 156 |
} |
| 157 |
sb.append(']'); |
| 158 |
return sb.toString(); |
| 159 |
} |
| 160 |
|
| 161 |
@Override |
| 162 |
public char[] toArray() {return array;} |
| 163 |
|
| 164 |
public char[] array; |
| 165 |
|
| 166 |
|
| 167 |
@Override |
| 168 |
public int arrayLength(){return array.length;} |
| 169 |
|
| 170 |
private static boolean OVERFLOWED=false; |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
} |