| 1 |
package icecream; |
| 2 |
|
| 3 |
import stream.Read; |
| 4 |
import structures.ByteBuilder; |
| 5 |
|
| 6 |
class ReadBuilder { |
| 7 |
|
| 8 |
public ReadBuilder(byte[] bases_, float passes_, int movieStart_, long zmw_) { |
| 9 |
this(new ByteBuilder(bases_), passes_, movieStart_, zmw_); |
| 10 |
} |
| 11 |
|
| 12 |
public ReadBuilder(ByteBuilder bases_, float passes_, int movieStart_, long zmw_) { |
| 13 |
bases=bases_; |
| 14 |
passes=passes_; |
| 15 |
movieStart=movieStart_; |
| 16 |
movieStop=movieStart+bases.length(); |
| 17 |
zmw=zmw_; |
| 18 |
|
| 19 |
fullPasses=passes<1 ? 0 : 1; |
| 20 |
} |
| 21 |
|
| 22 |
public static boolean isIceCream(String id){ |
| 23 |
String[] terms=id.split("\t"); |
| 24 |
int subreads=Integer.parseInt(terms[3].split("=")[1]); |
| 25 |
return subreads>1; |
| 26 |
} |
| 27 |
|
| 28 |
public static ReadBuilder parse(Read r) { |
| 29 |
ByteBuilder bases=new ByteBuilder(r.bases); |
| 30 |
String[] terms=r.id.split("\t"); |
| 31 |
String[] name=terms[0].split("/"); |
| 32 |
String[] position=name[2].split("_"); |
| 33 |
|
| 34 |
int movieStart=Integer.parseInt(position[0]); |
| 35 |
int movieStop=Integer.parseInt(position[1]); |
| 36 |
long zmw=Long.parseLong(name[1]); |
| 37 |
|
| 38 |
float passes=Float.parseFloat(terms[1].split("=")[1]); |
| 39 |
int fullPasses=Integer.parseInt(terms[2].split("=")[1]); |
| 40 |
int subreads=Integer.parseInt(terms[3].split("=")[1]); |
| 41 |
int missing=Integer.parseInt(terms[4].split("=")[1]); |
| 42 |
int adapters=Integer.parseInt(terms[5].split("=")[1]); |
| 43 |
float errorRate=(terms.length<7 ? 0 : Float.parseFloat(terms[6].split("=")[1])); |
| 44 |
|
| 45 |
ReadBuilder rb=new ReadBuilder(bases, passes, movieStart, zmw); |
| 46 |
rb.movieStop=movieStop; |
| 47 |
rb.passes=passes; |
| 48 |
rb.fullPasses=fullPasses; |
| 49 |
rb.subreads=subreads; |
| 50 |
rb.missing=missing; |
| 51 |
rb.adapters=adapters; |
| 52 |
rb.errorRate=errorRate; |
| 53 |
return rb; |
| 54 |
} |
| 55 |
|
| 56 |
@Override |
| 57 |
public String toString(){ |
| 58 |
return toHeader().toString(); |
| 59 |
} |
| 60 |
|
| 61 |
public ByteBuilder toHeader(){ |
| 62 |
ByteBuilder id=new ByteBuilder(200); |
| 63 |
id.append("m1_2_3/"); |
| 64 |
id.append(zmw).append('/').append(movieStart).append('_').append(movieStop); |
| 65 |
id.tab().append("passes=").append(passes, 2); |
| 66 |
id.tab().append("fullPasses=").append(fullPasses); |
| 67 |
id.tab().append("subreads=").append(subreads); |
| 68 |
id.tab().append("missing=").append(missing); |
| 69 |
id.tab().append("adapters=").append(adapters); |
| 70 |
id.tab().append("errorRate=").append(errorRate, 3); |
| 71 |
return id; |
| 72 |
} |
| 73 |
|
| 74 |
public int length() { |
| 75 |
return bases.length(); |
| 76 |
} |
| 77 |
|
| 78 |
void add(ReadBuilder rb){ |
| 79 |
bases.append(rb.bases); |
| 80 |
|
| 81 |
movieStop+=rb.length(); |
| 82 |
missing+=rb.missing; |
| 83 |
adapters+=rb.adapters; |
| 84 |
fullPasses+=rb.fullPasses; |
| 85 |
subreads+=rb.subreads; |
| 86 |
passes+=rb.passes; |
| 87 |
} |
| 88 |
|
| 89 |
Read toRead() { |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
ByteBuilder id=toHeader(); |
| 96 |
Read r=new Read(bases.toBytes(), null, id.toString(), 0); |
| 97 |
return r; |
| 98 |
} |
| 99 |
|
| 100 |
ByteBuilder bases; |
| 101 |
|
| 102 |
final long zmw; |
| 103 |
final int movieStart; |
| 104 |
int movieStop; |
| 105 |
|
| 106 |
float passes; |
| 107 |
int fullPasses=0; |
| 108 |
int subreads=1; |
| 109 |
int missing=0; |
| 110 |
int adapters=0; |
| 111 |
float errorRate=0; |
| 112 |
} |