| 1 |
package stream; |
| 2 |
|
| 3 |
import java.util.ArrayList; |
| 4 |
|
| 5 |
import align2.RandomReads3; |
| 6 |
import dna.Data; |
| 7 |
import shared.Shared; |
| 8 |
import shared.Tools; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
public class RandomReadInputStream3 extends ReadInputStream { |
| 16 |
|
| 17 |
public RandomReadInputStream3(long number_, boolean paired_){ |
| 18 |
Data.setGenome(Data.GENOME_BUILD); |
| 19 |
number=number_; |
| 20 |
paired=paired_; |
| 21 |
maxChrom=Data.numChroms; |
| 22 |
minQual=6; |
| 23 |
midQual=18; |
| 24 |
maxQual=30; |
| 25 |
restart(); |
| 26 |
} |
| 27 |
|
| 28 |
public RandomReadInputStream3(long number_, int minreadlen_, int maxreadlen_, |
| 29 |
int maxSnps_, int maxInss_, int maxDels_, int maxSubs_, |
| 30 |
float snpRate_, float insRate_, float delRate_, float subRate_, |
| 31 |
int maxInsertionLen_, int maxDeletionLen_, int maxSubLen_, |
| 32 |
int minChrom_, int maxChrom_, boolean paired_, |
| 33 |
int minQual_, int midQual_, int maxQual_){ |
| 34 |
Data.setGenome(Data.GENOME_BUILD); |
| 35 |
number=number_; |
| 36 |
minreadlen=minreadlen_; |
| 37 |
maxreadlen=maxreadlen_; |
| 38 |
|
| 39 |
maxInsertionLen=maxInsertionLen_; |
| 40 |
maxSubLen=maxSubLen_; |
| 41 |
maxDeletionLen=maxDeletionLen_; |
| 42 |
|
| 43 |
|
| 44 |
minInsertionLen=1; |
| 45 |
minSubLen=1; |
| 46 |
minDeletionLen=1; |
| 47 |
minNLen=1; |
| 48 |
|
| 49 |
minChrom=minChrom_; |
| 50 |
maxChrom=maxChrom_; |
| 51 |
|
| 52 |
maxSnps=maxSnps_; |
| 53 |
maxInss=maxInss_; |
| 54 |
maxDels=maxDels_; |
| 55 |
maxSubs=maxSubs_; |
| 56 |
|
| 57 |
snpRate=snpRate_; |
| 58 |
insRate=insRate_; |
| 59 |
delRate=delRate_; |
| 60 |
subRate=subRate_; |
| 61 |
|
| 62 |
paired=paired_; |
| 63 |
|
| 64 |
minQual=(byte) minQual_; |
| 65 |
midQual=(byte) midQual_; |
| 66 |
maxQual=(byte) maxQual_; |
| 67 |
|
| 68 |
restart(); |
| 69 |
} |
| 70 |
|
| 71 |
@Override |
| 72 |
public void start() {} |
| 73 |
|
| 74 |
|
| 75 |
@Override |
| 76 |
public boolean hasMore() { |
| 77 |
return number>consumed; |
| 78 |
} |
| 79 |
|
| 80 |
@Override |
| 81 |
public Read next() { |
| 82 |
if(consumed>=number){return null;} |
| 83 |
if(buffer==null || next>=buffer.size()){fillBuffer();} |
| 84 |
Read r=buffer.get(next); |
| 85 |
buffer.set(next, null); |
| 86 |
next++; |
| 87 |
consumed++; |
| 88 |
return r; |
| 89 |
} |
| 90 |
|
| 91 |
@Override |
| 92 |
public synchronized ArrayList<Read> nextList() { |
| 93 |
if(next!=0){throw new RuntimeException("'next' should not be used when doing blockwise access.");} |
| 94 |
if(consumed>=number){return null;} |
| 95 |
if(buffer==null || next>=buffer.size()){fillBuffer();} |
| 96 |
ArrayList<Read> r=buffer; |
| 97 |
buffer=null; |
| 98 |
if(r!=null && r.size()==0){r=null;} |
| 99 |
consumed+=(r==null ? 0 : r.size()); |
| 100 |
|
| 101 |
return r; |
| 102 |
} |
| 103 |
|
| 104 |
private synchronized void fillBuffer(){ |
| 105 |
buffer=null; |
| 106 |
next=0; |
| 107 |
|
| 108 |
long toMake=number-generated; |
| 109 |
if(toMake<1){return;} |
| 110 |
toMake=Tools.min(toMake, BUF_LEN); |
| 111 |
|
| 112 |
ArrayList<Read> reads=rr.makeRandomReadsX((int)toMake, minreadlen, maxreadlen, -1, |
| 113 |
maxSnps, maxInss, maxDels, maxSubs, maxNs, |
| 114 |
snpRate, insRate, delRate, subRate, NRate, |
| 115 |
minInsertionLen, minDeletionLen, minSubLen, minNLen, |
| 116 |
maxInsertionLen, maxDeletionLen, maxSubLen, maxNLen, |
| 117 |
minChrom, maxChrom, |
| 118 |
minQual, midQual, maxQual); |
| 119 |
|
| 120 |
generated+=reads.size(); |
| 121 |
assert(generated<=number); |
| 122 |
buffer=reads; |
| 123 |
|
| 124 |
} |
| 125 |
|
| 126 |
@Override |
| 127 |
public synchronized void restart(){ |
| 128 |
next=0; |
| 129 |
buffer=null; |
| 130 |
consumed=0; |
| 131 |
generated=0; |
| 132 |
rr=new RandomReads3(1, paired); |
| 133 |
} |
| 134 |
|
| 135 |
@Override |
| 136 |
public boolean close() {return false;} |
| 137 |
|
| 138 |
@Override |
| 139 |
public boolean paired() { |
| 140 |
return paired; |
| 141 |
} |
| 142 |
|
| 143 |
@Override |
| 144 |
public String fname(){return "random";} |
| 145 |
|
| 146 |
private ArrayList<Read> buffer=null; |
| 147 |
private int next=0; |
| 148 |
|
| 149 |
private final int BUF_LEN=Shared.bufferLen();; |
| 150 |
|
| 151 |
public long generated=0; |
| 152 |
public long consumed=0; |
| 153 |
|
| 154 |
public long number=100000; |
| 155 |
public int minreadlen=100; |
| 156 |
public int maxreadlen=100; |
| 157 |
|
| 158 |
public int maxInsertionLen=6; |
| 159 |
public int maxSubLen=6; |
| 160 |
public int maxDeletionLen=100; |
| 161 |
public int maxNLen=6; |
| 162 |
|
| 163 |
public int minInsertionLen=1; |
| 164 |
public int minSubLen=1; |
| 165 |
public int minDeletionLen=1; |
| 166 |
public int minNLen=1; |
| 167 |
|
| 168 |
public int minChrom=1; |
| 169 |
public int maxChrom=22; |
| 170 |
|
| 171 |
public int maxSnps=4; |
| 172 |
public int maxInss=2; |
| 173 |
public int maxDels=2; |
| 174 |
public int maxSubs=2; |
| 175 |
public int maxNs=2; |
| 176 |
|
| 177 |
public float snpRate=0.5f; |
| 178 |
public float insRate=0.25f; |
| 179 |
public float delRate=0.25f; |
| 180 |
public float subRate=0.10f; |
| 181 |
public float NRate=0.10f; |
| 182 |
|
| 183 |
public final boolean paired; |
| 184 |
|
| 185 |
public final byte minQual; |
| 186 |
public final byte midQual; |
| 187 |
public final byte maxQual; |
| 188 |
|
| 189 |
private RandomReads3 rr; |
| 190 |
|
| 191 |
} |