Skip to content

Commit

Permalink
Bug fix: remote breakend of breakpoint spanning parallelisation bound…
Browse files Browse the repository at this point in the history
…s no longer filtered by bounds check
  • Loading branch information
d-cameron committed Jan 20, 2017
1 parent 367498e commit 2c8243d
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>au.edu.wehi</groupId>
<artifactId>gridss</artifactId>
<packaging>jar</packaging>
<version>1.1.0</version>
<version>1.1.1</version>
<name>gridss</name>
<url>https://github.com/PapenfussLab/gridss</url>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
* @author Daniel Cameron
*
*/
public class MaximalEvidenceCliqueIterator extends AbstractIterator<VariantContextDirectedEvidence> {
public class MaximalEvidenceCliqueIterator extends AbstractIterator<VariantContextDirectedBreakpoint> {
private static final Log log = Log.getInstance(MaximalEvidenceCliqueIterator.class);
public static final String BREAKEND_ID_SUFFIX_HIGH = "h";
public static final String BREAKEND_ID_SUFFIX_LOW = "o";
private VariantContextDirectedEvidence lastHigh = null;
private VariantContextDirectedBreakpoint lastHigh = null;
private final BreakendDirection targetLowDir;
private final BreakendDirection targetHighDir;
private final RectangleGraphMaximalCliqueIterator calc;
Expand Down Expand Up @@ -102,7 +102,7 @@ private RectangleGraphNode toGraphNode(DirectedEvidence e) {
if (lowDir != targetLowDir || highDir != targetHighDir) return null;
return node;
}
private VariantContextDirectedEvidence toVariant(String event, RectangleGraphNode node, BreakpointSummary breakpoint, boolean isHighBreakend) {
private VariantContextDirectedBreakpoint toVariant(String event, RectangleGraphNode node, BreakpointSummary breakpoint, boolean isHighBreakend) {
IdsvVariantContextBuilder builder = new IdsvVariantContextBuilder(context);
builder.attribute(VcfSvConstants.BREAKEND_EVENT_ID_KEY, event);
builder.attribute(VcfSvConstants.PARTNER_BREAKEND_ID_KEY, event + (isHighBreakend ? BREAKEND_ID_SUFFIX_LOW : BREAKEND_ID_SUFFIX_HIGH));
Expand All @@ -115,7 +115,7 @@ private VariantContextDirectedEvidence toVariant(String event, RectangleGraphNod
double weight = ScalingHelper.toUnscaledWeight(scaledWeight);
builder.phredScore(weight);
builder.attribute(VcfAttributes.CALLED_QUAL, weight);
VariantContextDirectedEvidence v = (VariantContextDirectedBreakpoint)builder.make();
VariantContextDirectedBreakpoint v = (VariantContextDirectedBreakpoint)builder.make();
assert(v != null);
return v;
}
Expand All @@ -140,17 +140,17 @@ private BreakpointSummary toBreakpointSummary(RectangleGraphNode node) {
return breakpoint;
}
@Override
protected VariantContextDirectedEvidence computeNext() {
protected VariantContextDirectedBreakpoint computeNext() {
if (lastHigh != null) {
VariantContextDirectedEvidence result = lastHigh;
VariantContextDirectedBreakpoint result = lastHigh;
lastHigh = null;
return result;
}
if (calc.hasNext()) {
RectangleGraphNode node = calc.next();
BreakpointSummary breakpoint = toBreakpointSummary(node);
String id = idGenerator.generate(breakpoint);
VariantContextDirectedEvidence result = toVariant(id, node, breakpoint, false);
VariantContextDirectedBreakpoint result = toVariant(id, node, breakpoint, false);
lastHigh = toVariant(id, node, breakpoint, true);
return result;
}
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/au/edu/wehi/idsv/VariantCallIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @author Daniel Cameron
*/
public class VariantCallIterator implements CloseableIterator<VariantContextDirectedEvidence> {
public class VariantCallIterator implements CloseableIterator<VariantContextDirectedBreakpoint> {
private static final List<Pair<BreakendDirection, BreakendDirection>> DIRECTION_ORDER = ImmutableList.of(
Pair.of(BreakendDirection.Forward, BreakendDirection.Forward),
Pair.of(BreakendDirection.Forward, BreakendDirection.Backward),
Expand All @@ -28,7 +28,7 @@ public class VariantCallIterator implements CloseableIterator<VariantContextDire
private final VariantIdGenerator idGenerator;
private final Supplier<Iterator<DirectedEvidence>> iteratorGenerator;
private final QueryInterval filterInterval;
private Iterator<VariantContextDirectedEvidence> currentIterator;
private Iterator<VariantContextDirectedBreakpoint> currentIterator;
private int currentDirectionOrdinal;
public VariantCallIterator(ProcessingContext processContext, Iterable<DirectedEvidence> evidence) throws InterruptedException {
this.processContext = processContext;
Expand Down Expand Up @@ -68,8 +68,9 @@ private void reinitialiseIterator() {
idGenerator);
if (filterInterval != null) {
currentIterator = Iterators.filter(currentIterator, v -> {
BreakendSummary bs = v.getBreakendSummary();
return bs.start >= filterInterval.start && bs.start <= filterInterval.end;
BreakpointSummary bs = v.getBreakendSummary();
return (bs.referenceIndex == filterInterval.referenceIndex && bs.start >= filterInterval.start && bs.start <= filterInterval.end) ||
(bs.referenceIndex2 == filterInterval.referenceIndex && bs.start2 >= filterInterval.start && bs.start2 <= filterInterval.end);
});
}
}
Expand All @@ -84,7 +85,7 @@ public boolean hasNext() {
return true;
}
@Override
public VariantContextDirectedEvidence next() {
public VariantContextDirectedBreakpoint next() {
if (!hasNext()) throw new NoSuchElementException();
return currentIterator.next();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/au/edu/wehi/idsv/VariantCaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ private void callChunk(File output, AggregateEvidenceSource es, int chunkNumber,
try (VariantCallIterator rawit = new VariantCallIterator(es, chunck, chunkNumber)) {
try (VariantContextWriter vcfWriter = processContext.getVariantContextWriter(tmp, false)) {
log.info("Start ", msg);
try (AsyncBufferedIterator<VariantContextDirectedEvidence> it = new AsyncBufferedIterator<>(rawit, "VariantCaller " + chunkMsg)) {
try (AsyncBufferedIterator<VariantContextDirectedBreakpoint> it = new AsyncBufferedIterator<>(rawit, "VariantCaller " + chunkMsg)) {
while (it.hasNext()) {
VariantContextDirectedEvidence loc = it.next();
VariantContextDirectedBreakpoint loc = it.next();
if (loc.getBreakendQual() >= processContext.getVariantCallingParameters().minScore || processContext.getVariantCallingParameters().writeFiltered) {
// If we're under min score with all possible evidence allocated, we're definitely going to fail
// when we restrict evidence to single breakpoint support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,6 @@ public DirectedBreakpoint asRemote() {
}
@Override
public String getRemoteEvidenceID() {
throw new NotImplementedException("Not required by GRIDSS");
return getAttributeAsString(VcfSvConstants.PARTNER_BREAKEND_ID_KEY, null);
}
}
18 changes: 17 additions & 1 deletion src/test/java/au/edu/wehi/idsv/VariantCallIteratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@

import org.junit.Test;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

public class VariantCallIteratorTest extends TestHelper {
import htsjdk.samtools.QueryInterval;

public class VariantCallIteratorTest extends IntermediateFilesTest {
@Test
public void margin_should_expand_and_contract_past_chromosome_end() throws InterruptedException {
List<DirectedEvidence> list = new ArrayList<DirectedEvidence>();
Expand Down Expand Up @@ -70,4 +73,17 @@ public void should_call_orientations() throws InterruptedException {
List<VariantContextDirectedEvidence> result = Lists.newArrayList(ecp);
assertEquals(4 * 2, result.size());
}
@Test
public void interval_caller_should_filter_calls_in_which_neither_breakend_starts_in_interval() throws InterruptedException {
createInput(
RP(0, 1, 2, 1),
DP(0, 1, "1M", true, 1, 100, "1M", false));
SAMEvidenceSource ses = new SAMEvidenceSource(getCommandlineContext(), input, null, 0);
VariantCallIterator ecp = new VariantCallIterator(
new AggregateEvidenceSource(getCommandlineContext(), ImmutableList.of(ses), null),
new QueryInterval(0, 1, 10),
0);
List<VariantContextDirectedEvidence> result = Lists.newArrayList(ecp);
assertEquals(2, result.size());
}
}
15 changes: 14 additions & 1 deletion src/test/java/gridss/AllocateEvidenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

import org.junit.Test;

Expand All @@ -35,6 +37,11 @@
import htsjdk.samtools.SAMRecord;

public class AllocateEvidenceTest extends IntermediateFilesTest {
private void assertSymmetrical(List<VariantContextDirectedBreakpoint> breakpoints) {
Set<String> evidenceId = breakpoints.stream().map(bp -> bp.getEvidenceID()).collect(Collectors.toSet());
Set<String> remoteEvidenceId = breakpoints.stream().map(bp -> bp.getRemoteEvidenceID()).collect(Collectors.toSet());
assertEquals(evidenceId, remoteEvidenceId);
}
@Test
public void should_annotate_reads() throws IOException {
final ProcessingContext pc = getCommandlineContext();
Expand All @@ -60,7 +67,9 @@ public void should_annotate_reads() throws IOException {
cmd.OUTPUT_VCF = new File(testFolder.getRoot(), "annotated.vcf");
List<VariantContextDirectedBreakpoint> vcfs = Lists.newArrayList(Iterables.filter(getVcf(output, null), VariantContextDirectedBreakpoint.class));
assertEquals(2 * 1, vcfs.size()); // both breakends
assertSymmetrical(vcfs);
List<VariantContextDirectedBreakpoint> results = Lists.newArrayList(cmd.iterator(new AutoClosingIterator<>(vcfs.iterator()), MoreExecutors.newDirectExecutorService()));
assertSymmetrical(results);
assertEquals(vcfs.size(), results.size());
VariantContextDirectedBreakpoint e = results.get(0);
assertEquals(2, e.getBreakpointEvidenceCount());
Expand Down Expand Up @@ -90,7 +99,9 @@ public void should_apply_filters() throws IOException {
cmd.OUTPUT_VCF = new File(testFolder.getRoot(), "annotated.vcf");
List<VariantContextDirectedBreakpoint> vcfs = Lists.newArrayList(Iterables.filter(getVcf(output, null), VariantContextDirectedBreakpoint.class));
assertEquals(2 * 1, vcfs.size()); // both breakends
assertSymmetrical(vcfs);
List<VariantContextDirectedBreakpoint> results = Lists.newArrayList(cmd.iterator(new AutoClosingIterator<>(vcfs.iterator()), MoreExecutors.newDirectExecutorService()));
assertSymmetrical(results);
// single read support
assertEquals(0, results.size());
}
Expand Down Expand Up @@ -133,7 +144,9 @@ public void should_uniquely_assign() throws IOException, InterruptedException, E

//List<IdsvVariantContext> annotated = getVcf(new File(testFolder.getRoot(), "out.vcf"), null);
List<IdsvVariantContext> rawcalls = getVcf(output, null);
List<IdsvVariantContext> calls = getVcf(cmd.OUTPUT_VCF, null);
List<IdsvVariantContext> calls = getVcf(cmd.OUTPUT_VCF, null);
assertSymmetrical(rawcalls.stream().map(x -> (VariantContextDirectedBreakpoint)x).collect(Collectors.toList()));
assertSymmetrical(calls.stream().map(x -> (VariantContextDirectedBreakpoint)x).collect(Collectors.toList()));
// with no filtering, annotation should not change call set
double expectedEvidence = 0;
for (DirectedEvidence e : ses.evidence) {
Expand Down

0 comments on commit 2c8243d

Please sign in to comment.