From ee6a90a8144fd26a5b80b69b5ba0d3a53d3e8b78 Mon Sep 17 00:00:00 2001 From: Nils Homer Date: Thu, 18 May 2017 12:37:07 -0700 Subject: [PATCH] Add auxiliary baits and targets to BaitDesigner. This is useful if you re-designing just a sub-set of your targets. --- src/main/java/picard/util/BaitDesigner.java | 44 ++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/main/java/picard/util/BaitDesigner.java b/src/main/java/picard/util/BaitDesigner.java index 2dbb05584..d096fae07 100644 --- a/src/main/java/picard/util/BaitDesigner.java +++ b/src/main/java/picard/util/BaitDesigner.java @@ -1,6 +1,8 @@ package picard.util; +import htsjdk.samtools.SAMFileHeader; import htsjdk.samtools.SAMSequenceDictionary; +import htsjdk.samtools.SamFlagField; import htsjdk.samtools.reference.ReferenceSequence; import htsjdk.samtools.reference.ReferenceSequenceFileWalker; import htsjdk.samtools.util.CloserUtil; @@ -274,6 +276,12 @@ public String toString() { @Option(shortName = "T", doc = "The file with design parameters and targets") public File TARGETS; + @Option(shortName = "AUX_T", doc = "The file with targets to include when calculating statistics (ex. re-design)", optional = true) + public File AUX_TARGETS; + + @Option(shortName = "AUX_B", doc = "The file with baits to include when calculating statistics (ex. re-design)", optional = true) + public File AUX_BAITS; + @Option(doc = "The name of the bait design") public String DESIGN_NAME; @@ -428,7 +436,7 @@ protected int doWork() { if (MERGE_NEARBY_TARGETS) { final ListIterator iterator = padded.getIntervals().listIterator(); - Interval previous = iterator.next(); + Interval previous = iterator.hasNext() ? iterator.next() : null; targets = new IntervalList(padded.getHeader()); @@ -489,6 +497,40 @@ protected int doWork() { } } + if (AUX_BAITS != null) { + final IntervalList auxBaits = IntervalList.fromFile(AUX_BAITS); + SequenceUtil.assertSequenceDictionariesEqual(auxBaits.getHeader().getSequenceDictionary(), + baits.getHeader().getSequenceDictionary()); + + final ReferenceSequenceFileWalker walker = new ReferenceSequenceFileWalker(REFERENCE_SEQUENCE); + ReferenceSequence reference = null; + final SAMSequenceDictionary dict = auxBaits.getHeader().getSequenceDictionary(); + for (final Interval interval : auxBaits.getIntervals()) { + final int contigIndex = dict.getSequenceIndex(interval.getContig()); + if (reference == null || contigIndex != reference.getContigIndex()) { + reference = walker.get(contigIndex); + } + final Bait bait = new Bait(interval.getContig(), + interval.getStart(), + interval.getEnd(), + interval.isNegativeStrand(), + interval.getName() + ); + bait.addBases(reference, DESIGN_ON_TARGET_STRAND); + baits.add(bait); + } + log.info("Added " + auxBaits.size() + " auxiliary baits"); + } + + if (AUX_TARGETS != null) { + final IntervalList auxTargets = IntervalList.fromFile(AUX_TARGETS); + SequenceUtil.assertSequenceDictionariesEqual(auxTargets.getHeader().getSequenceDictionary(), + targets.getHeader().getSequenceDictionary()); + targets.addall(auxTargets.getIntervals()); + log.info("Added " + auxTargets.size() + " auxiliary targets"); + + } + calculateStatistics(targets, baits); log.info("Designed and kept " + baits.size() + " baits, discarded " + discardedBaits);