package assemble; import java.util.ArrayList; import java.util.concurrent.atomic.AtomicInteger; import kmer.AbstractKmerTableSet; import kmer.KmerTableSet; import shared.Timer; import ukmer.KmerTableSetU; /** * Designed for removal of dead ends (aka hairs). * @author Brian Bushnell * @date Jun 26, 2015 * */ public abstract class Shaver extends ShaveObject { /*--------------------------------------------------------------*/ /*---------------- Factory ----------------*/ /*--------------------------------------------------------------*/ public static final Shaver makeShaver(AbstractKmerTableSet tables, int threads){ return makeShaver(tables, threads, 1, 1, 1, 1, 3, 100, 100, true, true); } public static final Shaver makeShaver(AbstractKmerTableSet tables, int threads, int minCount, int maxCount, int minSeed, int minCountExtend, float branchMult2, int maxLengthToDiscard, int maxDistanceToExplore, boolean removeHair, boolean removeBubbles){ final Class c=tables.getClass(); if(c==KmerTableSet.class){ return new Shaver1((KmerTableSet)tables, threads, minCount, maxCount, minSeed, minCountExtend, branchMult2, maxLengthToDiscard, maxDistanceToExplore, removeHair, removeBubbles); }else if(c==KmerTableSetU.class){ return new Shaver2((KmerTableSetU)tables, threads, minCount, maxCount, minSeed, minCountExtend, branchMult2, maxLengthToDiscard, maxDistanceToExplore, removeHair, removeBubbles); } throw new RuntimeException("Unhandled class "+c); } /*--------------------------------------------------------------*/ /*---------------- Constructor ----------------*/ /*--------------------------------------------------------------*/ public Shaver(AbstractKmerTableSet tables_, int threads_, int minCount_, int maxCount_, int minSeed_, int minCountExtend_, float branchMult2_, int maxLengthToDiscard_, int maxDistanceToExplore_, boolean removeHair_, boolean removeBubbles_){ threads=threads_; minCount=minCount_; maxCount=maxCount_; minSeed=minSeed_; minCountExtend=minCountExtend_; branchMult2=branchMult2_; maxLengthToDiscard=maxLengthToDiscard_; maxDistanceToExplore=maxDistanceToExplore_; removeHair=removeHair_; removeBubbles=removeBubbles_; kbig=tables_.kbig(); } /*--------------------------------------------------------------*/ /*---------------- Outer Methods ----------------*/ /*--------------------------------------------------------------*/ abstract AbstractExploreThread makeExploreThread(int id_); abstract AbstractShaveThread makeShaveThread(int id_); public final long shave(int minCount_, int maxCount_){ minCount=minCount_; maxCount=maxCount_; return shave(); } public final long shave(){ assert(minSeed>=minCount) : "Required: mincount >= minSeed >= maxCount. "+minCount+", "+minSeed+", "+maxCount; assert(minSeed<=maxCount) : "Required: mincount >= minSeed >= maxCount. "+minCount+", "+minSeed+", "+maxCount; assert(removeHair || removeBubbles); Timer t=new Timer(); long kmersTestedTemp=0; long deadEndsFoundTemp=0; long kmersRemovedTemp=0; long bubblesFoundTemp=0; tables().initializeOwnership(); countMatrix=new long[8][8]; removeMatrix=new long[8][8]; { nextTable.set(0); nextVictims.set(0); /* Create Explorethreads */ ArrayList alpt=new ArrayList(threads); for(int i=0; i alpt=new ArrayList(threads); for(int i=0; i