-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
include recovered SVS in copy number segments
- Loading branch information
Showing
5 changed files
with
163 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...oidy-estimator/src/main/java/com/hartwig/hmftools/purple/sv/VariantContextCollection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.hartwig.hmftools.purple.sv; | ||
|
||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.TreeSet; | ||
import java.util.function.Predicate; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.hartwig.hmftools.common.variant.structural.StructuralVariant; | ||
import com.hartwig.hmftools.common.variant.structural.StructuralVariantFactory; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import htsjdk.samtools.SAMSequenceDictionary; | ||
import htsjdk.variant.variantcontext.VariantContext; | ||
import htsjdk.variant.variantcontext.VariantContextComparator; | ||
import htsjdk.variant.variantcontext.filter.PassingVariantFilter; | ||
import htsjdk.variant.vcf.VCFHeader; | ||
|
||
public class VariantContextCollection implements Iterable<VariantContext> { | ||
|
||
private final TreeSet<VariantContext> variantContexts; | ||
private final List<StructuralVariant> variants = Lists.newArrayList(); | ||
|
||
private boolean modified; | ||
|
||
public VariantContextCollection(@NotNull final VCFHeader header) { | ||
variantContexts = new TreeSet<>(new VCComparator(header.getSequenceDictionary())); | ||
} | ||
|
||
public VariantContextCollection(@NotNull final List<String> contigs) { | ||
variantContexts = new TreeSet<>(new VCComparator(contigs)); | ||
} | ||
|
||
public void add(@NotNull final VariantContext variantContext) { | ||
modified = true; | ||
if (variantContext.contains(variantContext)) { | ||
variantContexts.remove(variantContext); | ||
variantContexts.add(variantContext); | ||
} | ||
} | ||
|
||
public int remove(@NotNull final Predicate<VariantContext> removePredicate) { | ||
int removed = 0; | ||
final Iterator<VariantContext> iterator = variantContexts.iterator(); | ||
while (iterator.hasNext()) { | ||
final VariantContext variantContext = iterator.next(); | ||
if (removePredicate.test(variantContext)) { | ||
iterator.remove(); | ||
removed++; | ||
modified = true; | ||
} | ||
} | ||
return removed; | ||
} | ||
|
||
@NotNull | ||
public List<StructuralVariant> passingVariants() { | ||
if (modified) { | ||
modified = false; | ||
final StructuralVariantFactory factory = new StructuralVariantFactory(new PassingVariantFilter()); | ||
variantContexts.forEach(factory::addVariantContext); | ||
|
||
variants.clear(); | ||
variants.addAll(factory.results()); | ||
} | ||
|
||
return variants; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Iterator<VariantContext> iterator() { | ||
return variantContexts.iterator(); | ||
} | ||
|
||
private class VCComparator extends VariantContextComparator { | ||
|
||
VCComparator(final List<String> contigs) { | ||
super(contigs); | ||
} | ||
|
||
VCComparator(final SAMSequenceDictionary dictionary) { | ||
super(dictionary); | ||
} | ||
|
||
@Override | ||
public int compare(final VariantContext firstVariantContext, final VariantContext secondVariantContext) { | ||
int positionResult = super.compare(firstVariantContext, secondVariantContext); | ||
|
||
return positionResult == 0 ? firstVariantContext.getID().compareTo(secondVariantContext.getID()) : positionResult; | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...-estimator/src/test/java/com/hartwig/hmftools/purple/sv/VariantContextCollectionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.hartwig.hmftools.purple.sv; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.google.common.collect.Sets; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import htsjdk.variant.vcf.VCFCodec; | ||
import htsjdk.variant.vcf.VCFHeader; | ||
import htsjdk.variant.vcf.VCFHeaderVersion; | ||
|
||
public class VariantContextCollectionTest { | ||
private static final String SAMPLE = "sample"; | ||
|
||
private VCFCodec codec; | ||
|
||
@Before | ||
public void setup() { | ||
codec = createTestCodec(); | ||
} | ||
|
||
|
||
@Test | ||
public void testAddSetsModifiedFlag() { | ||
final VariantContextCollection victim = new VariantContextCollection(Lists.newArrayList("1")); | ||
assertEquals(0, victim.passingVariants().size()); | ||
|
||
victim.add(codec.decode("1\t192614842\tgridss14_291648b\tT\tTCTCTACACAAG.\t2076.59\tPASS\tSVTYPE=BND\tGT\t./.")); | ||
assertEquals(1, victim.passingVariants().size()); | ||
} | ||
|
||
@NotNull | ||
private static VCFCodec createTestCodec() { | ||
VCFCodec codec = new VCFCodec(); | ||
VCFHeader header = new VCFHeader(Sets.newHashSet(), Sets.newHashSet(SAMPLE)); | ||
codec.setVCFHeader(header, VCFHeaderVersion.VCF4_2); | ||
return codec; | ||
} | ||
} |