<classpathentry kind="lib" path="lib/htsjdk-2.12.0.jar"/>
<classpathentry kind="lib" path="lib/groovy-all-2.4.12-indy.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
- <classpathentry kind="lib" path="lib/intervalstore-v0.3.jar"/>
+ <classpathentry kind="lib" path="lib/intervalstore-v0.4.jar"/>
<classpathentry kind="output" path="classes"/>
</classpath>
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
*/
public class SequenceFeatures implements SequenceFeaturesI
{
- /**
- * a comparator for sorting features by start position ascending
- */
- private static Comparator<IntervalI> FORWARD_STRAND = new Comparator<IntervalI>()
- {
- @Override
- public int compare(IntervalI o1, IntervalI o2)
- {
- return Integer.compare(o1.getBegin(), o2.getBegin());
- }
- };
-
- /**
- * a comparator for sorting features by end position descending
- */
- private static Comparator<IntervalI> REVERSE_STRAND = new Comparator<IntervalI>()
- {
- @Override
- public int compare(IntervalI o1, IntervalI o2)
- {
- return Integer.compare(o2.getEnd(), o1.getEnd());
- }
- };
/*
* map from feature type to structured store of features for that type
* @param features
* @param forwardStrand
*/
- public static void sortFeatures(List<SequenceFeature> features,
+ public static void sortFeatures(List<? extends IntervalI> features,
final boolean forwardStrand)
{
- Collections.sort(features, forwardStrand ? FORWARD_STRAND
- : REVERSE_STRAND);
+ IntervalI.sortIntervals(features, forwardStrand);
}
/**
// verify attributes string is updated with reverse complement
assertEquals("x=y,z;alleles=" + revcomp + ";a=b,c", sf.getAttributes());
}
-
- @Test(groups = "Functional")
- public void testSortFeatures()
- {
- SequenceFeature sf1 = new SequenceFeature("", "", 10, 15, 0f, null);
- SequenceFeature sf2 = new SequenceFeature("", "", 8, 12, 0f, null);
- SequenceFeature sf3 = new SequenceFeature("", "", 8, 13, 0f, null);
- SequenceFeature sf4 = new SequenceFeature("", "", 11, 11, 0f, null);
- List<SequenceFeature> sfs = Arrays.asList(new SequenceFeature[] { sf1,
- sf2, sf3, sf4 });
-
- // sort by start position ascending (forward strand)
- // sf2 and sf3 tie and should not be reordered by sorting
- SequenceFeatures.sortFeatures(sfs, true);
- assertSame(sfs.get(0), sf2);
- assertSame(sfs.get(1), sf3);
- assertSame(sfs.get(2), sf1);
- assertSame(sfs.get(3), sf4);
-
- // sort by end position descending (reverse strand)
- SequenceFeatures.sortFeatures(sfs, false);
- assertSame(sfs.get(0), sf1);
- assertSame(sfs.get(1), sf3);
- assertSame(sfs.get(2), sf2);
- assertSame(sfs.get(3), sf4);
- }
}