package bin; import java.io.PrintStream; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.concurrent.locks.ReadWriteLock; import fileIO.FileFormat; import shared.Shared; import shared.Tools; import stream.SamLine; import stream.SamLineStreamer; import structures.IntHashMap; import structures.ListNum; import template.Accumulator; import template.ThreadWaiter; import tracker.EntropyTracker; public class SamLoader implements Accumulator { public SamLoader(PrintStream outstream_) { outstream=outstream_; } @Deprecated public void load(ArrayList fnames, HashMap contigMap, IntHashMap[] graph) { //Contig list should already be sorted and numbered. ArrayList list=new ArrayList(contigMap.values()); Collections.sort(list); for(int i=0; i fnames, HashMap contigMap, ArrayList contigs, IntHashMap[] graph){ //Do anything necessary prior to processing //Determine how many threads may be used final int threads=fnames.size(); //Fill a list with LoadThreads ArrayList alpt=new ArrayList(threads); for(int i=0; i contigMap_, ArrayList contigs_, IntHashMap[] graph_) { fname=fname_; sample=sample_; contigMap=contigMap_; contigs=contigs_; graph=graph_; } @Override public void run() { synchronized(this) {runInner();} } private void runInner() { long[] depthArray=new long[contigs.size()]; SamLineStreamer ss=null; outstream.println("Loading "+fname); final int streamerThreads=Tools.min(3, Shared.threads()); FileFormat ff=FileFormat.testInput(fname, FileFormat.SAM, null, true, false); ss=new SamLineStreamer(ff, streamerThreads, false, -1); ss.start(); processSam_Thread(ss, depthArray); postprocess(depthArray); depthArray=null; success=true; } private void postprocess(long[] depthArray) { for(int cnum=0; cnum ln=ss.nextLines(); ArrayList reads=(ln==null ? null : ln.list); while(ln!=null && reads!=null && reads.size()>0){ for(int idx=0; idx=contigStart && lineStop<=contigStop) {return aligned;} return Tools.overlapLength(lineStart, lineStop, contigStart, contigStop); } private boolean addSamLine(SamLine sl, long[] depthArray) { if(!sl.mapped()) {return false;} if(maxSubs<999 && sl.countSubs()>maxSubs) {return false;} if(minID>0 && sl.calcIdentity()0) { int mateq=sl.mateq(); if(mateq>=0 && mateq0){ float mateid=sl.mateID(); if(mateid>0 && mateid<100*minMateID) { // System.err.println("mateid too low: "+mateid); return true; } } final String rnext=ContigRenamer.toShortName(sl.rnext()); assert(rnext!=null && !"*".equals(rnext) && !"=".equals(rnext)); final Contig c2=contigMap.get(rnext); if(c2==null) { System.err.println("Can't find "+rnext); return true; }//Contig not found // System.err.println("Adding edge: "+rname+" - "+rnext); if(minEntropy>0 && sl.seq!=null && !et.passes(sl.seq, true)) {return true;} // if(minEntropy>0 && sl.seq!=null && EntropyTracker.calcEntropy(sl.seq, kmerCounts, 4) contigMap; final ArrayList contigs; final IntHashMap[] graph; final EntropyTracker et=new EntropyTracker(5, 80, false, minEntropy, true); final int[] kmerCounts=new int[256]; long readsInT=0; long readsUsedT=0; long basesInT=0; long bytesInT=0; boolean success=false; } public PrintStream outstream=System.err; public long readsIn=0; public long readsUsed=0; public long basesIn=0; public long bytesIn=0; public int minMapq=4; public int minMateq=4; public float minID=0f; public float minMateID=0f; public int maxSubs=999; public int tipLimit=100; public float minEntropy=0; public int minAlignedBases=0; public boolean errorState=false; }