add unit tests
This commit is contained in:
parent
839b918f58
commit
63ace685c9
|
|
@ -259,27 +259,24 @@ public final class QualifyMissingIntervals extends LocusWalker<Metrics, Metrics>
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getPositionInTarget(final GenomeLoc interval, final List<GenomeLoc> hits) {
|
protected static int getPositionInTarget(final GenomeLoc interval, final List<GenomeLoc> targets) {
|
||||||
if (hits.size() > 0) {
|
if (targets.size() > 0) {
|
||||||
final GenomeLoc hit = hits.get(0);
|
final GenomeLoc target = targets.get(0);
|
||||||
|
|
||||||
// interval is larger on both ends than the target -- return the maximum distance to either side as a negative number. (min of 2 negative numbers)
|
// interval is larger on both ends than the target -- return the maximum distance to either side as a negative number. (min of 2 negative numbers)
|
||||||
if (interval.getStart() < hit.getStart() && interval.getStop() > hit.getStop())
|
if (interval.getStart() < target.getStart() && interval.getStop() > target.getStop())
|
||||||
return Math.min(interval.getStart() - hit.getStart(),
|
return Math.min(target.getStart() - interval.getStart(), target.getStop() - interval.getStop());
|
||||||
interval.getStop() - hit.getStop());
|
|
||||||
|
|
||||||
// interval is a left overlap -- return a negative number representing the distance between the two starts
|
// interval is a left overlap -- return a negative number representing the distance between the two starts
|
||||||
else if (interval.getStart() < hit.getStart())
|
else if (interval.getStart() < target.getStart())
|
||||||
return hit.getStart() - interval.getStart();
|
return interval.getStart() - target.getStart();
|
||||||
|
|
||||||
// interval is a right overlap -- return a negative number representing the distance between the two stops
|
// interval is a right overlap -- return a negative number representing the distance between the two stops
|
||||||
else if (interval.getStop() > hit.getStop())
|
else if (interval.getStop() > target.getStop())
|
||||||
return hit.getStop() - interval.getStop();
|
return target.getStop() - interval.getStop();
|
||||||
|
|
||||||
// interval is fully contained -- return the smallest distance to the edge of the target (left or right) as a positive number
|
// interval is fully contained -- return the smallest distance to the edge of the target (left or right) as a positive number
|
||||||
else
|
return Math.min(interval.getStart() - target.getStart(), target.getStop() - interval.getStop());
|
||||||
return Math.min(Math.abs(hit.getStart() - interval.getStart()),
|
|
||||||
Math.abs(hit.getStop() - interval.getStop()));
|
|
||||||
}
|
}
|
||||||
// if there is no overlapping interval, return int min value.
|
// if there is no overlapping interval, return int min value.
|
||||||
return Integer.MIN_VALUE;
|
return Integer.MIN_VALUE;
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,8 @@
|
||||||
|
|
||||||
package org.broadinstitute.sting.gatk.walkers.diagnostics.missing;
|
package org.broadinstitute.sting.gatk.walkers.diagnostics.missing;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
|
import java.util.List;
|
||||||
import org.broadinstitute.sting.BaseTest;
|
import org.broadinstitute.sting.BaseTest;
|
||||||
import org.broadinstitute.sting.utils.GenomeLoc;
|
import org.broadinstitute.sting.utils.GenomeLoc;
|
||||||
import org.broadinstitute.sting.utils.UnvalidatingGenomeLoc;
|
import org.broadinstitute.sting.utils.UnvalidatingGenomeLoc;
|
||||||
|
|
@ -57,7 +59,6 @@ import org.testng.annotations.Test;
|
||||||
* User: carneiro
|
* User: carneiro
|
||||||
* Date: 9/20/13
|
* Date: 9/20/13
|
||||||
* Time: 3:59 PM
|
* Time: 3:59 PM
|
||||||
* To change this template use File | Settings | File Templates.
|
|
||||||
*/
|
*/
|
||||||
public class QualifyMissingIntervalsUnitTest extends BaseTest {
|
public class QualifyMissingIntervalsUnitTest extends BaseTest {
|
||||||
@Test(enabled = true)
|
@Test(enabled = true)
|
||||||
|
|
@ -92,4 +93,39 @@ public class QualifyMissingIntervalsUnitTest extends BaseTest {
|
||||||
for (Metrics m : array)
|
for (Metrics m : array)
|
||||||
Assert.assertEquals(tool.interpret(m, smallInterval), QualifyMissingIntervals.Interpretation.SMALL_INTERVAL.toString());
|
Assert.assertEquals(tool.interpret(m, smallInterval), QualifyMissingIntervals.Interpretation.SMALL_INTERVAL.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(enabled = true)
|
||||||
|
void testGetPositionInTarget () {
|
||||||
|
final UnvalidatingGenomeLoc target = new UnvalidatingGenomeLoc("a", 0, 30, 50);
|
||||||
|
final List<GenomeLoc> targets = new ObjectArrayList<>(1);
|
||||||
|
targets.add(target);
|
||||||
|
|
||||||
|
// left overlap
|
||||||
|
UnvalidatingGenomeLoc interval = new UnvalidatingGenomeLoc("a", 0, 10, 50);
|
||||||
|
Assert.assertEquals(QualifyMissingIntervals.getPositionInTarget(interval, targets), -20);
|
||||||
|
|
||||||
|
// right overlap
|
||||||
|
interval = new UnvalidatingGenomeLoc("a", 0, 40, 60);
|
||||||
|
Assert.assertEquals(QualifyMissingIntervals.getPositionInTarget(interval, targets), -10);
|
||||||
|
|
||||||
|
// interval > target with short right tail
|
||||||
|
interval = new UnvalidatingGenomeLoc("a", 0, 10, 60);
|
||||||
|
Assert.assertEquals(QualifyMissingIntervals.getPositionInTarget(interval, targets), -10);
|
||||||
|
|
||||||
|
// interval > target with short left tail
|
||||||
|
interval = new UnvalidatingGenomeLoc("a", 0, 10, 80);
|
||||||
|
Assert.assertEquals(QualifyMissingIntervals.getPositionInTarget(interval, targets), -30);
|
||||||
|
|
||||||
|
// interval < target with short right tail
|
||||||
|
interval = new UnvalidatingGenomeLoc("a", 0, 32, 40);
|
||||||
|
Assert.assertEquals(QualifyMissingIntervals.getPositionInTarget(interval, targets), 2);
|
||||||
|
|
||||||
|
// interval < target with short left tail
|
||||||
|
interval = new UnvalidatingGenomeLoc("a", 0, 40, 42);
|
||||||
|
Assert.assertEquals(QualifyMissingIntervals.getPositionInTarget(interval, targets), 8);
|
||||||
|
|
||||||
|
// no overlap
|
||||||
|
interval = new UnvalidatingGenomeLoc("a", 0, 40, 42);
|
||||||
|
Assert.assertEquals(QualifyMissingIntervals.getPositionInTarget(interval, new ObjectArrayList<GenomeLoc>()), Integer.MIN_VALUE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue