jpayne@68: package icecream; jpayne@68: jpayne@68: import java.util.ArrayList; jpayne@68: jpayne@68: import shared.Tools; jpayne@68: import stream.Read; jpayne@68: import stream.SamLine; jpayne@68: import structures.IntList; jpayne@68: jpayne@68: /** jpayne@68: * Container for the list of reads from a single jpayne@68: * PacBio ZMW. jpayne@68: * @author Brian Bushnell jpayne@68: * @date June 5, 2020 jpayne@68: */ jpayne@68: public class ZMW extends ArrayList { jpayne@68: jpayne@68: /** jpayne@68: * For serialization. jpayne@68: */ jpayne@68: private static final long serialVersionUID = -2580124131008824113L; jpayne@68: jpayne@68: public ZMW(){super();} jpayne@68: jpayne@68: public ZMW(int initialSize){super(initialSize);} jpayne@68: jpayne@68: public long countBases(){ jpayne@68: long x=0; jpayne@68: for(Read r : this){ jpayne@68: x+=r.length(); jpayne@68: } jpayne@68: return x; jpayne@68: } jpayne@68: jpayne@68: public int medianLength(boolean includeDiscarded){ jpayne@68: if(size()<3){return -1;} jpayne@68: IntList lengths=new IntList(size()-2); jpayne@68: jpayne@68: for(int i=1; imax.length())){max=r;} jpayne@68: } jpayne@68: return max; jpayne@68: } jpayne@68: jpayne@68: public int zid(){ jpayne@68: if(zid==-1){parseZID();} jpayne@68: return zid; jpayne@68: } jpayne@68: jpayne@68: private int parseZID(){ jpayne@68: return (size()<1 ? -1 : PBHeader.parseZMW(get(0).id)); jpayne@68: } jpayne@68: jpayne@68: public static void fixReadHeader(Read r, int leftTrim, int rightTrim){ jpayne@68: leftTrim=Tools.max(0, leftTrim); jpayne@68: rightTrim=Tools.max(0, rightTrim); jpayne@68: if(leftTrim<1 && rightTrim<1){return;} jpayne@68: final int idx=r.id.lastIndexOf('/'); jpayne@68: if(idx>0 && idx0){ jpayne@68: String coords=suffix, comment=""; jpayne@68: int tab=suffix.indexOf('\t'); jpayne@68: if(tab<0){tab=suffix.indexOf(' ');} jpayne@68: if(tab>0){ jpayne@68: coords=coords.substring(0, tab); jpayne@68: comment=coords.substring(tab); jpayne@68: } jpayne@68: String[] split=Tools.underscorePattern.split(coords); jpayne@68: int left=Integer.parseInt(split[0]); jpayne@68: int right=Integer.parseInt(split[1]); jpayne@68: left+=leftTrim; jpayne@68: right-=rightTrim; jpayne@68: if(left>right){left=right;} jpayne@68: jpayne@68: if(right-left!=r.length()){right=left+r.length();} jpayne@68: // System.err.println(r.length()+", "+(right-left)); jpayne@68: jpayne@68: r.id=prefix+left+"_"+right+comment; jpayne@68: final SamLine sl=r.samline; jpayne@68: if(sl!=null){ jpayne@68: sl.qname=r.id; jpayne@68: if(sl.optional!=null){ jpayne@68: for(int i=0; i