Source:
<code>public static SimpleInterval trimInterval(final Locatable interval, final TargetCollection<? extends Locatable> targets, final TargetCollection<? extends Locatable> snps) { Utils.nonNull(interval, "The interval cannot be null."); Utils.nonNull(targets, "The collection of targets cannot be null."); Utils.nonNull(snps, "The collection of SNPs cannot be null."); final IndexRange targetRange = targets.indexRange(interval); final IndexRange snpRange = snps.indexRange(interval); final int numTargetsInInterval = targetRange.size(); final int numSNPsInInterval = snpRange.size(); int start = interval.getStart(); int end = interval.getEnd(); if (numTargetsInInterval == 0 && numSNPsInInterval > 0) { start = snps.target(snpRange.from).getStart(); end = snps.target(snpRange.to - 1).getEnd(); } else if (numTargetsInInterval > 0) { <START> if (!(targets.target(targetRange.from).getStart() <= interval.getStart() && <END> interval.getStart() <= targets.target(targetRange.from).getEnd())) { start = targets.target(targetRange.from).getStart(); } if (!(targets.target(targetRange.to - 1).getStart() <= interval.getEnd() && interval.getEnd() <= targets.target(targetRange.to - 1).getEnd())) { end = targets.target(targetRange.to - 1).getEnd(); } if (numSNPsInInterval > 0) { start = Math.min(start, snps.target(snpRange.from).getStart()); end = Math.max(end, snps.target(snpRange.to - 1).getEnd()); } } if (start < interval.getStart() || end > interval.getEnd() || end < start) { throw new GATKException.ShouldNeverReachHereException("Something went wrong in trimming interval."); } return new SimpleInterval(interval.getContig(), start, end); }</code><technical_language>Extract variables for targets.target(targetRange.from) targets.target(targetRange.to - 1). name firstTarget lastTarget, for example</technical_language>

Target:
public static SimpleInterval trimInterval(final Locatable interval, final TargetCollection<? extends Locatable> targets, final TargetCollection<? extends Locatable> snps) { Utils.nonNull(interval, "The interval cannot be null."); Utils.nonNull(targets, "The collection of targets cannot be null."); Utils.nonNull(snps, "The collection of SNPs cannot be null."); final IndexRange targetRange = targets.indexRange(interval); final IndexRange snpRange = snps.indexRange(interval); final int numTargetsInInterval = targetRange.size(); final int numSNPsInInterval = snpRange.size(); int start = interval.getStart(); int end = interval.getEnd(); if (numTargetsInInterval == 0 && numSNPsInInterval > 0) { start = snps.target(snpRange.from).getStart(); end = snps.target(snpRange.to - 1).getEnd(); } else if (numTargetsInInterval > 0) { start = Math.max(start, targets.target(targetRange.from).getStart()); end = Math.min(end, targets.target(targetRange.to - 1).getEnd()); if (numSNPsInInterval > 0) { start = Math.min(start, snps.target(snpRange.from).getStart()); end = Math.max(end, snps.target(snpRange.to - 1).getEnd()); } } if (start < interval.getStart() || end > interval.getEnd() || end < start) { throw new GATKException.ShouldNeverReachHereException("Something went wrong in trimming interval."); } return new SimpleInterval(interval.getContig(), start, end); }