private void writeDifferences( final List<VariantContext> source1Alleles, final List<VariantContext> source2Alleles) { int currentIndex1 = 0, currentIndex2 = 0; final int size1 = source1Alleles.size(), size2 = source2Alleles.size(); VariantContext current1 = source1Alleles.get(0); VariantContext current2 = source2Alleles.get(0); while (currentIndex1 < size1 || currentIndex2 < size2) { if (current1 == null) { writeOne(current2, source2, null); currentIndex2++; current2 = (currentIndex2 < size2 ? source2Alleles.get(currentIndex2) : null); } else if (current2 == null) { writeOne(current1, source1, null); currentIndex1++; current1 = (currentIndex1 < size1 ? source1Alleles.get(currentIndex1) : null); } else { final GenomeLoc loc1 = getToolkit().getGenomeLocParser().createGenomeLoc(current1); final GenomeLoc loc2 = getToolkit().getGenomeLocParser().createGenomeLoc(current2); if (loc1.getStart() == loc2.getStart() || loc1.overlapsP(loc2)) { String status; if (loc1.getStart() == loc2.getStart()) { final String allele1 = current1.getAlternateAllele(0).getBaseString(); final String allele2 = current2.getAlternateAllele(0).getBaseString(); if (allele1.indexOf(allele2) != -1 || allele2.indexOf(allele1) != -1) status = ONE_ALLELE_SUBSET_OF_OTHER_STATUS; else status = SAME_START_DIFFERENT_ALLELES_STATUS; } else { status = OVERLAPPING_EVENTS_STATUS; } writeOne(current1, INTERSECTION_SET, status); currentIndex1++; currentIndex2++; current1 = (currentIndex1 < size1 ? source1Alleles.get(currentIndex1) : null); current2 = (currentIndex2 < size2 ? source2Alleles.get(currentIndex2) : null); } else if (loc1.isBefore(loc2)) { writeOne(current1, source1, null); currentIndex1++; current1 = (currentIndex1 < size1 ? source1Alleles.get(currentIndex1) : null); } else { writeOne(current2, source2, null); currentIndex2++; current2 = (currentIndex2 < size2 ? source2Alleles.get(currentIndex2) : null); } } } }
/** * Outputs all intervals that are behind the current reference locus * * @param refLocus the current reference locus * @param refBase the reference allele */ private void outputFinishedIntervals(final GenomeLoc refLocus, final byte refBase) { // output any intervals that were finished final List<GenomeLoc> toRemove = new LinkedList<>(); for (GenomeLoc key : intervalMap.keySet()) { if (key.isBefore(refLocus)) { final IntervalStratification intervalStats = intervalMap.get(key); outputStatsToVCF(intervalStats, Allele.create(refBase, true)); if (hasMissingLoci(intervalStats)) { outputMissingInterval(intervalStats); } toRemove.add(key); } } for (GenomeLoc key : toRemove) { intervalMap.remove(key); } }
private void writeAndPurgeAllEqualVariants( final List<VariantContext> sourceVCs1, final List<VariantContext> sourceVCs2, final String status) { int currentIndex1 = 0, currentIndex2 = 0; int size1 = sourceVCs1.size(), size2 = sourceVCs2.size(); VariantContext current1 = (currentIndex1 < size1 ? sourceVCs1.get(currentIndex1) : null); VariantContext current2 = (currentIndex2 < size2 ? sourceVCs2.get(currentIndex2) : null); while (current1 != null && current2 != null) { final GenomeLoc loc1 = getToolkit().getGenomeLocParser().createGenomeLoc(current1); final GenomeLoc loc2 = getToolkit().getGenomeLocParser().createGenomeLoc(current2); if (loc1.equals(loc2) || (loc1.getStart() == loc2.getStart() && (current1.getAlternateAlleles().size() > 1 || current2.getAlternateAlleles().size() > 1))) { // test the alleles if (determineAndWriteOverlap(current1, current2, status)) { sourceVCs1.remove(currentIndex1); sourceVCs2.remove(currentIndex2); size1--; size2--; } else { currentIndex1++; currentIndex2++; } current1 = (currentIndex1 < size1 ? sourceVCs1.get(currentIndex1) : null); current2 = (currentIndex2 < size2 ? sourceVCs2.get(currentIndex2) : null); } else if (loc1.isBefore(loc2)) { currentIndex1++; current1 = (currentIndex1 < size1 ? sourceVCs1.get(currentIndex1) : null); } else { currentIndex2++; current2 = (currentIndex2 < size2 ? sourceVCs2.get(currentIndex2) : null); } } }