(ArrayList<? extends BitSequence> seqs, String outFasta,
long bfSize, int k, int w, int numHash, boolean stranded, boolean useHpcKmers,
int maxNonMatchingChainLength, float minMatchingProportion,
int maxMultiplicity)
| 48 | public class SeqSubsampler { |
| 49 | |
| 50 | public static void minimizerBased(ArrayList<? extends BitSequence> seqs, String outFasta, |
| 51 | long bfSize, int k, int w, int numHash, boolean stranded, boolean useHpcKmers, |
| 52 | int maxNonMatchingChainLength, float minMatchingProportion, |
| 53 | int maxMultiplicity) throws IOException { |
| 54 | |
| 55 | int numSeq = seqs.size(); |
| 56 | |
| 57 | HashFunction h = stranded ? new HashFunction(k) : new CanonicalHashFunction(k); |
| 58 | |
| 59 | MinimizerHashIterator itr = new MinimizerHashIterator(k, w, h.getHashIterator(1)); |
| 60 | CountingBloomFilter bf = new CountingBloomFilter(bfSize, numHash, h); |
| 61 | |
| 62 | FastaWriter fw = new FastaWriter(outFasta, false); |
| 63 | int seqID = 0; |
| 64 | long[] hVals = new long[numHash]; |
| 65 | for (BitSequence s : seqs) { |
| 66 | String seq = s.toString(); |
| 67 | String hpc = useHpcKmers ? compressHomoPolymers(seq) : seq; |
| 68 | |
| 69 | if (itr.start(hpc)) { |
| 70 | int numMinimizers = 0; |
| 71 | int numMinimizersSeen = 0; |
| 72 | int consecutiveMissing = 0; |
| 73 | int maxConsecutiveMissing = 0; |
| 74 | |
| 75 | if (itr.hasNext()) { |
| 76 | long prev = itr.next(); |
| 77 | ++numMinimizers; |
| 78 | itr.getMultipleHashValues(prev, hVals); |
| 79 | if (bf.incrementAndGet(hVals) > maxMultiplicity) { |
| 80 | ++numMinimizersSeen; |
| 81 | } |
| 82 | |
| 83 | while (itr.hasNext()) { |
| 84 | long mm = itr.next(); |
| 85 | if (mm != prev) { |
| 86 | ++numMinimizers; |
| 87 | itr.getMultipleHashValues(mm, hVals); |
| 88 | if (bf.incrementAndGet(hVals) > maxMultiplicity) { |
| 89 | ++numMinimizersSeen; |
| 90 | consecutiveMissing = 0; |
| 91 | } |
| 92 | else { |
| 93 | maxConsecutiveMissing = Math.max(maxConsecutiveMissing, ++consecutiveMissing); |
| 94 | } |
| 95 | } |
| 96 | prev = mm; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | if (maxConsecutiveMissing > maxNonMatchingChainLength || numMinimizersSeen < minMatchingProportion * numMinimizers) { |
| 101 | fw.write(Integer.toString(++seqID), seq); |
| 102 | } |
| 103 | } |
| 104 | else { |
| 105 | fw.write(Integer.toString(++seqID), seq); |
| 106 | } |
| 107 | } |
nothing calls this directly
no test coverage detected