annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/opt/bbmap-39.01-1/current/icecream/ReadBuilder.java @ 68:5028fdace37b

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