use of au.edu.wehi.idsv.ProcessingContext in project gridss by PapenfussLab.
the class PairedEvidenceTracker method allMatched.
private boolean allMatched() {
List<DirectedBreakpoint> list = new ArrayList<>(unpaired.values());
list.sort(DirectedBreakpoint.ByStartEnd);
for (DirectedBreakpoint e : list) {
ProcessingContext context = e.getEvidenceSource().getContext();
if (!MessageThrottler.Current.shouldSupress(log, "unpaired evidence")) {
log.error(String.format("%s (%s, %f) unpaired", e.getEvidenceID(), e.getBreakendSummary().toString(context), e.getBreakpointQual()));
}
}
return unpaired.isEmpty();
}
use of au.edu.wehi.idsv.ProcessingContext in project gridss by PapenfussLab.
the class AnnotateReferenceCoverage method iterator.
@Override
public CloseableIterator<VariantContextDirectedBreakpoint> iterator(CloseableIterator<VariantContextDirectedBreakpoint> calls, ExecutorService threadpool) {
ProcessingContext context = getContext();
List<SAMEvidenceSource> sources = getSamEvidenceSources();
AssemblyEvidenceSource asm = getAssemblySource();
int windowSize = SAMEvidenceSource.maximumWindowSize(context, sources, asm);
return new SequentialCoverageAnnotator<VariantContextDirectedBreakpoint>(context, sources, calls, 2 * windowSize + WINDOW_SIZE_SAFETY_MARGIN, threadpool);
}
use of au.edu.wehi.idsv.ProcessingContext in project gridss by PapenfussLab.
the class MultipleSamFileCommandLineProgram method getContext.
public ProcessingContext getContext() {
if (processContext == null) {
GridssConfiguration config;
try {
config = new GridssConfiguration(CONFIGURATION_FILE, WORKING_DIR);
} catch (ConfigurationException e) {
throw new RuntimeException(e);
}
processContext = new ProcessingContext(getFileSystemContext(), REFERENCE_SEQUENCE, null, getDefaultHeaders(), config);
processContext.setCommandLineProgram(this);
processContext.setFilterDuplicates(IGNORE_DUPLICATES);
processContext.setWorkerThreadCount(WORKER_THREADS);
if (BLACKLIST != null) {
try {
processContext.setBlacklist(BLACKLIST);
} catch (IOException e) {
log.error(e, "Error loading BED blacklist. ", BLACKLIST);
throw new RuntimeException(e);
}
}
}
return processContext;
}
use of au.edu.wehi.idsv.ProcessingContext in project gridss by PapenfussLab.
the class PairedEvidenceTracker method isValidNext.
private boolean isValidNext(T evidence) {
if (evidence instanceof DirectedBreakpoint) {
DirectedBreakpoint e = (DirectedBreakpoint) evidence;
ProcessingContext context = e.getEvidenceSource().getContext();
String evidenceId = evidence.getEvidenceID();
String partnerId = e.getRemoteEvidenceID();
if (unpaired.containsKey(evidenceId)) {
String msg = String.format("%s: encountered %s multiple times.", name, evidenceId);
if (!MessageThrottler.Current.shouldSupress(log, "duplicate evidence")) {
log.error(msg);
}
return false;
}
if (unpaired.containsKey(partnerId)) {
DirectedBreakpoint partner = unpaired.remove(partnerId);
// Breakpoints must be the same
if (!partner.getBreakendSummary().remoteBreakpoint().equals(e.getBreakendSummary())) {
String msg = String.format("%s: breakpoints %s and %s differ for evidence pair %s %s", name, e.getBreakendSummary().toString(context), partner.getBreakendSummary().toString(context), e.getEvidenceID(), partner.getEvidenceID());
if (!MessageThrottler.Current.shouldSupress(log, "asymetric evidence breakpoint positions")) {
log.error(msg);
}
return false;
}
// Scores must be the same
if (partner.getBreakpointQual() != e.getBreakpointQual()) {
String msg = String.format("%s: scores %f and %f differ for evidence pair %s %s", name, e.getBreakpointQual(), partner.getBreakpointQual(), e.getEvidenceID(), partner.getEvidenceID());
if (!MessageThrottler.Current.shouldSupress(log, "asymetric evidence backpoint quality")) {
log.error(msg);
}
return false;
}
} else {
unpaired.put(evidenceId, e);
}
}
return true;
}
use of au.edu.wehi.idsv.ProcessingContext in project gridss by PapenfussLab.
the class AllocateEvidenceTest method should_uniquely_assign.
@Test
public void should_uniquely_assign() throws IOException, InterruptedException, ExecutionException {
final int fragSize = 4;
final int testSize = 64;
final List<SAMRecord> in = new ArrayList<SAMRecord>();
final ProcessingContext pc = getCommandlineContext();
pc.getVariantCallingParameters().writeFiltered = true;
pc.getVariantCallingParameters().minScore = 0;
StubSAMEvidenceSource ses = new StubSAMEvidenceSource(pc, input, 0, 0, fragSize);
for (int i = 1; i < testSize; i++) {
for (int j = 1; j < testSize; j++) {
SAMRecord[] dp = withReadName(String.format("read-%d-%d", i, j), DP(0, i, "1M", true, 1, j, "1M", false));
ses.evidence.add(NonReferenceReadPair.create(dp[0], dp[1], ses));
ses.evidence.add(NonReferenceReadPair.create(dp[1], dp[0], ses));
in.add(dp[0]);
in.add(dp[1]);
}
}
StubAssemblyEvidenceSource aes = new StubAssemblyEvidenceSource(pc);
aes.fragSize = fragSize;
Collections.sort(ses.evidence, DirectedEvidenceOrder.ByNatural);
createInput(in);
VariantCaller vc = new VariantCaller(pc, ImmutableList.<SAMEvidenceSource>of(ses), aes);
ExecutorService threadpool = Executors.newSingleThreadExecutor();
vc.callBreakends(output, threadpool);
threadpool.shutdown();
AllocateEvidence cmd = new AllocateEvidence();
cmd.INPUT_VCF = output;
cmd.setContext(pc);
cmd.setAssemblySource(aes);
cmd.setSamEvidenceSources(ImmutableList.of(ses));
cmd.OUTPUT_VCF = new File(testFolder.getRoot(), "annotated.vcf");
cmd.ASSEMBLY = new File(testFolder.getRoot(), "assembly.bam");
// to shut up the command-line parsing
createBAM(cmd.ASSEMBLY, SortOrder.coordinate, Collections.emptyList());
cmd.doWork(null);
// 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);
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) {
DiscordantReadPair bp = (DiscordantReadPair) e;
expectedEvidence += bp.getBreakpointQual();
}
double annotatedEvidence = 0;
for (IdsvVariantContext e : calls) {
annotatedEvidence += e.getPhredScaledQual();
}
double rawEvidence = rawcalls.stream().mapToDouble(e -> e.getPhredScaledQual()).sum();
// unique assignment must result in the evidence total being, at most, the same
assertTrue(annotatedEvidence <= rawEvidence);
// each piece of evidence should be assigned to a single breakpoint so totals should match
int rpCalls = calls.stream().mapToInt(v -> ((VariantContextDirectedBreakpoint) v).getBreakpointEvidenceCount()).sum();
assertEquals(ses.evidence.size(), rpCalls);
// floating point truncation on VCF is severe!
assertEquals(expectedEvidence, annotatedEvidence, 20);
}
Aggregations