diff --git a/ivy.xml b/ivy.xml
index f47949227..f7893cb32 100644
--- a/ivy.xml
+++ b/ivy.xml
@@ -41,8 +41,8 @@
-
-
+
+
diff --git a/java/src/org/broadinstitute/sting/analyzecovariates/AnalyzeCovariates.java b/java/src/org/broadinstitute/sting/analyzecovariates/AnalyzeCovariates.java
index 41abd092c..e9b0035cd 100755
--- a/java/src/org/broadinstitute/sting/analyzecovariates/AnalyzeCovariates.java
+++ b/java/src/org/broadinstitute/sting/analyzecovariates/AnalyzeCovariates.java
@@ -27,13 +27,14 @@ package org.broadinstitute.sting.analyzecovariates;
import org.broadinstitute.sting.commandline.Input;
import org.broadinstitute.sting.gatk.walkers.recalibration.*;
-import org.broadinstitute.sting.utils.classloader.PackageUtils;
+import org.broadinstitute.sting.utils.classloader.PluginManager;
import org.broadinstitute.sting.utils.exceptions.DynamicClassResolutionException;
import org.broadinstitute.sting.utils.text.XReadLines;
import org.broadinstitute.sting.commandline.CommandLineProgram;
import org.broadinstitute.sting.commandline.Argument;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
@@ -114,7 +115,7 @@ class AnalyzeCovariatesCLP extends CommandLineProgram {
private void initializeData() {
// Get a list of all available covariates
- List> classes = PackageUtils.getClassesImplementingInterface(Covariate.class);
+ Collection> classes = new PluginManager(Covariate.class).getPlugins();
int lineNumber = 0;
boolean foundAllCovariates = false;
diff --git a/java/src/org/broadinstitute/sting/gatk/WalkerManager.java b/java/src/org/broadinstitute/sting/gatk/WalkerManager.java
index 45675092c..cb1da2b99 100755
--- a/java/src/org/broadinstitute/sting/gatk/WalkerManager.java
+++ b/java/src/org/broadinstitute/sting/gatk/WalkerManager.java
@@ -62,7 +62,7 @@ public class WalkerManager extends PluginManager {
*/
public Map>> getWalkerNamesByPackage(boolean visibleWalkersOnly) {
Map>> walkersByPackage = new HashMap>>();
- for(Class extends Walker> walker: pluginsByName.values()) {
+ for(Class extends Walker> walker: getPlugins()) {
if(visibleWalkersOnly && isHidden(walker))
continue;
@@ -157,7 +157,7 @@ public class WalkerManager extends PluginManager {
* @return Class representing the walker.
*/
public Class extends Walker> getWalkerClassByName(String walkerName) {
- return pluginsByName.get(walkerName);
+ return getPluginsByName().get(walkerName);
}
/**
diff --git a/java/src/org/broadinstitute/sting/gatk/filters/FilterManager.java b/java/src/org/broadinstitute/sting/gatk/filters/FilterManager.java
index bd899b80c..3bf11c0ac 100644
--- a/java/src/org/broadinstitute/sting/gatk/filters/FilterManager.java
+++ b/java/src/org/broadinstitute/sting/gatk/filters/FilterManager.java
@@ -55,6 +55,6 @@ public class FilterManager extends PluginManager {
}
public Collection> getValues() {
- return this.pluginsByName.values();
+ return this.getPlugins();
}
}
diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/tracks/builders/RMDTrackBuilder.java b/java/src/org/broadinstitute/sting/gatk/refdata/tracks/builders/RMDTrackBuilder.java
index b3bd6ef86..fb68a8e37 100644
--- a/java/src/org/broadinstitute/sting/gatk/refdata/tracks/builders/RMDTrackBuilder.java
+++ b/java/src/org/broadinstitute/sting/gatk/refdata/tracks/builders/RMDTrackBuilder.java
@@ -32,7 +32,6 @@ import org.broad.tribble.*;
import org.broad.tribble.index.Index;
import org.broad.tribble.index.IndexFactory;
import org.broad.tribble.source.BasicFeatureSource;
-import org.broad.tribble.source.CachingFeatureSource;
import org.broad.tribble.util.LittleEndianOutputStream;
import org.broadinstitute.sting.gatk.arguments.GATKArgumentCollection;
import org.broadinstitute.sting.gatk.refdata.ReferenceDependentFeatureCodec;
@@ -42,7 +41,6 @@ import org.broadinstitute.sting.gatk.refdata.utils.RMDTriplet;
import org.broadinstitute.sting.gatk.AbstractGenomeAnalysisEngine;
import org.broadinstitute.sting.gatk.refdata.utils.helpers.DbSNPHelper;
import org.broadinstitute.sting.utils.GenomeLocParser;
-import org.broadinstitute.sting.utils.Utils;
import org.broadinstitute.sting.utils.collections.Pair;
import org.broadinstitute.sting.utils.classloader.PluginManager;
import org.broadinstitute.sting.utils.exceptions.UserException;
@@ -114,8 +112,8 @@ public class RMDTrackBuilder extends PluginManager {
/** @return a list of all available track types we currently have access to create */
public Map getAvailableTrackNamesAndTypes() {
classes = new HashMap();
- for (String name: this.pluginsByName.keySet()) {
- classes.put(name.toUpperCase(), pluginsByName.get(name));
+ for (String name: this.getPluginsByName().keySet()) {
+ classes.put(name.toUpperCase(), getPluginsByName().get(name));
}
return classes;
}
@@ -123,7 +121,7 @@ public class RMDTrackBuilder extends PluginManager {
/** @return a list of all available track record types we currently have access to create */
public Map getAvailableTrackNamesAndRecordTypes() {
HashMap classToRecord = new HashMap();
- for (String name: this.pluginsByName.keySet()) {
+ for (String name: this.getPluginsByName().keySet()) {
FeatureCodec codec = this.createByName(name);
classToRecord.put(name, codec.getFeatureType());
}
@@ -133,7 +131,6 @@ public class RMDTrackBuilder extends PluginManager {
/**
* create a RMDTrack of the specified type
*
- * @param genomeLocParser GenomeLocParser to use, if case track needs additional reference context.
* @param targetClass the target class of track
* @param name what to call the track
* @param inputFile the input file
diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java
index ab4bf068b..be80ede2f 100755
--- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java
+++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java
@@ -38,7 +38,7 @@ import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.AnnotationType
import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.GenotypeAnnotation;
import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.InfoFieldAnnotation;
import org.broadinstitute.sting.utils.BaseUtils;
-import org.broadinstitute.sting.utils.classloader.PackageUtils;
+import org.broadinstitute.sting.utils.classloader.PluginManager;
import org.broadinstitute.sting.utils.SampleUtils;
import org.broadinstitute.sting.commandline.Argument;
import org.broadinstitute.sting.commandline.Output;
@@ -93,18 +93,18 @@ public class VariantAnnotator extends RodWalker {
private void listAnnotationsAndExit() {
- List> infoAnnotationClasses = PackageUtils.getClassesImplementingInterface(InfoFieldAnnotation.class);
+ List> infoAnnotationClasses = new PluginManager(InfoFieldAnnotation.class).getPlugins();
System.out.println("\nAvailable annotations for the VCF INFO field:");
for (int i = 0; i < infoAnnotationClasses.size(); i++)
System.out.println("\t" + infoAnnotationClasses.get(i).getSimpleName());
System.out.println();
- List> genotypeAnnotationClasses = PackageUtils.getClassesImplementingInterface(GenotypeAnnotation.class);
+ List> genotypeAnnotationClasses = new PluginManager(GenotypeAnnotation.class).getPlugins();
System.out.println("\nAvailable annotations for the VCF FORMAT field:");
for (int i = 0; i < genotypeAnnotationClasses.size(); i++)
System.out.println("\t" + genotypeAnnotationClasses.get(i).getSimpleName());
System.out.println();
System.out.println("\nAvailable classes/groups of annotations:");
- for ( Class c : PackageUtils.getInterfacesExtendingInterface(AnnotationType.class) )
+ for ( Class c : new PluginManager(AnnotationType.class).getInterfaces() )
System.out.println("\t" + c.getSimpleName());
System.out.println();
System.exit(0);
diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java
index 65aca754b..6347f2e4e 100755
--- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java
+++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java
@@ -50,7 +50,6 @@ import org.broadinstitute.sting.gatk.refdata.utils.helpers.DbSNPHelper;
import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.*;
import org.broadinstitute.sting.gatk.walkers.annotator.genomicannotator.*;
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
-import org.broadinstitute.sting.utils.classloader.PackageUtils;
import org.broadinstitute.sting.utils.exceptions.UserException;
@@ -94,8 +93,8 @@ public class VariantAnnotatorEngine {
// use this constructor if you want all possible annotations
public VariantAnnotatorEngine(GenomeAnalysisEngine engine) {
- requestedInfoAnnotations = PackageUtils.getInstancesOfClassesImplementingInterface(InfoFieldAnnotation.class);
- requestedGenotypeAnnotations = PackageUtils.getInstancesOfClassesImplementingInterface(GenotypeAnnotation.class);
+ requestedInfoAnnotations = AnnotationInterfaceManager.createAllInfoFieldAnnotations();
+ requestedGenotypeAnnotations = AnnotationInterfaceManager.createAllGenotypeAnnotations();
initializeDBs(engine);
}
@@ -116,49 +115,9 @@ public class VariantAnnotatorEngine {
}
private void initializeAnnotations(List annotationGroupsToUse, List annotationsToUse) {
- // create a map for all annotation classes which implement our top-level interfaces
- HashMap classMap = new HashMap();
- for ( Class c : PackageUtils.getClassesImplementingInterface(InfoFieldAnnotation.class) )
- classMap.put(c.getSimpleName(), c);
- for ( Class c : PackageUtils.getClassesImplementingInterface(GenotypeAnnotation.class) )
- classMap.put(c.getSimpleName(), c);
- for ( Class c : PackageUtils.getInterfacesExtendingInterface(AnnotationType.class) )
- classMap.put(c.getSimpleName(), c);
-
- HashSet classes = new HashSet();
- // get the classes from the provided groups (interfaces)
- if ( annotationGroupsToUse.size() != 1 || ! annotationGroupsToUse.get(0).toLowerCase().equals("none") ) {
- for ( String group : annotationGroupsToUse ) {
- Class interfaceClass = classMap.get(group);
- if ( interfaceClass == null )
- interfaceClass = classMap.get(group + "Annotation");
- if ( interfaceClass == null )
- throw new UserException.BadArgumentValue("group", "Class " + group + " is not found; please check that you have specified the class name correctly");
- classes.addAll(PackageUtils.getClassesImplementingInterface(interfaceClass));
- }
- }
-
- // get the specific classes provided
- for ( String annotation : annotationsToUse ) {
- Class annotationClass = classMap.get(annotation);
- if ( annotationClass == null )
- annotationClass = classMap.get(annotation + "Annotation");
- if ( annotationClass == null )
- throw new UserException.BadArgumentValue("annotation", "Class " + annotation + " is not found; please check that you have specified the class name correctly");
- classes.add(annotationClass);
- }
-
- // get the instances
- requestedInfoAnnotations = new ArrayList();
- requestedGenotypeAnnotations = new ArrayList();
-
- for ( Class c : classes ) {
- // note that technically an annotation can work on both the INFO and FORMAT fields
- if ( InfoFieldAnnotation.class.isAssignableFrom(c) )
- requestedInfoAnnotations.add((InfoFieldAnnotation)PackageUtils.getSimpleInstance(c));
- if ( GenotypeAnnotation.class.isAssignableFrom(c) )
- requestedGenotypeAnnotations.add((GenotypeAnnotation)PackageUtils.getSimpleInstance(c));
- }
+ AnnotationInterfaceManager.validateAnnotations(annotationGroupsToUse, annotationsToUse);
+ requestedInfoAnnotations = AnnotationInterfaceManager.createInfoFieldAnnotations(annotationGroupsToUse, annotationsToUse);
+ requestedGenotypeAnnotations = AnnotationInterfaceManager.createGenotypeAnnotations(annotationGroupsToUse, annotationsToUse);
}
private void initializeDBs(GenomeAnalysisEngine engine) {
diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/interfaces/AnnotationInterfaceManager.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/interfaces/AnnotationInterfaceManager.java
new file mode 100644
index 000000000..89106a360
--- /dev/null
+++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/interfaces/AnnotationInterfaceManager.java
@@ -0,0 +1,100 @@
+package org.broadinstitute.sting.gatk.walkers.annotator.interfaces;
+
+import org.broadinstitute.sting.utils.classloader.PluginManager;
+import org.broadinstitute.sting.utils.exceptions.UserException;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+
+public class AnnotationInterfaceManager {
+ private static PluginManager infoFieldAnnotationPluginManager = new PluginManager(InfoFieldAnnotation.class);
+ private static PluginManager genotypeAnnotationPluginManager = new PluginManager(GenotypeAnnotation.class);
+ private static PluginManager annotationTypePluginManager = new PluginManager(AnnotationType.class);
+
+ public static List createAllInfoFieldAnnotations() {
+ return infoFieldAnnotationPluginManager.createAllTypes();
+ }
+
+ public static List createAllGenotypeAnnotations() {
+ return genotypeAnnotationPluginManager.createAllTypes();
+ }
+
+ public static void validateAnnotations(List annotationGroupsToUse, List annotationsToUse) {
+ HashMap classMap = new HashMap();
+ for ( Class c : infoFieldAnnotationPluginManager.getPlugins() )
+ classMap.put(c.getSimpleName(), c);
+ for ( Class c : genotypeAnnotationPluginManager.getPlugins() )
+ classMap.put(c.getSimpleName(), c);
+ for ( Class c : annotationTypePluginManager.getInterfaces() )
+ classMap.put(c.getSimpleName(), c);
+
+ if ( annotationGroupsToUse.size() != 1 || !"none".equals(annotationGroupsToUse.get(0)) ) {
+ for ( String group : annotationGroupsToUse ) {
+ Class interfaceClass = classMap.get(group);
+ if ( interfaceClass == null )
+ interfaceClass = classMap.get(group + "Annotation");
+ if ( interfaceClass == null )
+ throw new UserException.BadArgumentValue("group", "Class " + group + " is not found; please check that you have specified the class name correctly");
+ }
+ }
+
+ // validate the specific classes provided
+ for ( String annotation : annotationsToUse ) {
+ Class annotationClass = classMap.get(annotation);
+ if ( annotationClass == null )
+ annotationClass = classMap.get(annotation + "Annotation");
+ if ( annotationClass == null )
+ throw new UserException.BadArgumentValue("annotation", "Class " + annotation + " is not found; please check that you have specified the class name correctly");
+ }
+ }
+
+ public static List createInfoFieldAnnotations(List annotationGroupsToUse, List annotationsToUse) {
+ return createAnnotations(infoFieldAnnotationPluginManager, annotationGroupsToUse, annotationsToUse);
+ }
+
+ public static List createGenotypeAnnotations(List annotationGroupsToUse, List annotationsToUse) {
+ return createAnnotations(genotypeAnnotationPluginManager, annotationGroupsToUse, annotationsToUse);
+ }
+
+ private static List createAnnotations(PluginManager pluginManager, List annotationGroupsToUse, List annotationsToUse) {
+ // get the instances
+ List annotations = new ArrayList();
+
+ // get the classes from the provided groups (interfaces)
+ // create a map for all annotation classes which implement our top-level interfaces
+ HashMap classMap = new HashMap();
+ for ( Class c : pluginManager.getPlugins() )
+ classMap.put(c.getSimpleName(), c);
+ for ( Class c : annotationTypePluginManager.getInterfaces() )
+ classMap.put(c.getSimpleName(), c);
+
+ HashSet classes = new HashSet();
+
+ if ( annotationGroupsToUse.size() != 1 || !"none".equals(annotationGroupsToUse.get(0)) ) {
+ for ( String group : annotationGroupsToUse ) {
+ Class interfaceClass = classMap.get(group);
+ if ( interfaceClass == null )
+ interfaceClass = classMap.get(group + "Annotation");
+ if ( interfaceClass != null )
+ classes.addAll(pluginManager.getPluginsImplementing(interfaceClass));
+ }
+ }
+
+ // get the specific classes provided
+ for ( String annotation : annotationsToUse ) {
+ Class annotationClass = classMap.get(annotation);
+ if ( annotationClass == null )
+ annotationClass = classMap.get(annotation + "Annotation");
+ if ( annotationClass != null )
+ classes.add(annotationClass);
+ }
+
+ // note that technically an annotation can work on both the INFO and FORMAT fields
+ for ( Class c : classes )
+ annotations.add(pluginManager.createByType(c));
+
+ return annotations;
+ }
+}
diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/CovariateCounterWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/CovariateCounterWalker.java
index 0df273eab..211ebb95c 100755
--- a/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/CovariateCounterWalker.java
+++ b/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/CovariateCounterWalker.java
@@ -37,7 +37,7 @@ import org.broadinstitute.sting.gatk.filters.ZeroMappingQualityReadFilter;
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
import org.broadinstitute.sting.gatk.walkers.*;
import org.broadinstitute.sting.utils.*;
-import org.broadinstitute.sting.utils.classloader.PackageUtils;
+import org.broadinstitute.sting.utils.classloader.PluginManager;
import org.broadinstitute.sting.utils.collections.NestedHashMap;
import org.broadinstitute.sting.commandline.Argument;
import org.broadinstitute.sting.commandline.ArgumentCollection;
@@ -167,9 +167,9 @@ public class CovariateCounterWalker extends LocusWalker> covariateClasses = PackageUtils.getClassesImplementingInterface( Covariate.class );
- final List> requiredClasses = PackageUtils.getClassesImplementingInterface( RequiredCovariate.class );
- final List> standardClasses = PackageUtils.getClassesImplementingInterface( StandardCovariate.class );
+ final List> covariateClasses = new PluginManager( Covariate.class ).getPlugins();
+ final List> requiredClasses = new PluginManager( RequiredCovariate.class ).getPlugins();
+ final List> standardClasses = new PluginManager( StandardCovariate.class ).getPlugins();
// Print and exit if that's what was requested
if ( LIST_ONLY ) {
diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/TableRecalibrationWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/TableRecalibrationWalker.java
index 2e6bf8543..a498dd501 100644
--- a/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/TableRecalibrationWalker.java
+++ b/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/TableRecalibrationWalker.java
@@ -42,7 +42,7 @@ import org.broadinstitute.sting.gatk.walkers.ReadWalker;
import org.broadinstitute.sting.gatk.walkers.Requires;
import org.broadinstitute.sting.gatk.walkers.WalkerName;
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
-import org.broadinstitute.sting.utils.classloader.PackageUtils;
+import org.broadinstitute.sting.utils.classloader.PluginManager;
import org.broadinstitute.sting.utils.collections.NestedHashMap;
import org.broadinstitute.sting.utils.QualityUtils;
import org.broadinstitute.sting.utils.exceptions.DynamicClassResolutionException;
@@ -149,7 +149,7 @@ public class TableRecalibrationWalker extends ReadWalker> classes = PackageUtils.getClassesImplementingInterface(Covariate.class);
+ final List> classes = new PluginManager(Covariate.class).getPlugins();
int lineNumber = 0;
boolean foundAllCovariates = false;
diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/VariantEvalWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/VariantEvalWalker.java
index 53a336464..7cfdbcafa 100755
--- a/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/VariantEvalWalker.java
+++ b/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/VariantEvalWalker.java
@@ -49,7 +49,7 @@ import org.broadinstitute.sting.utils.report.VE2ReportFactory;
import org.broadinstitute.sting.utils.report.templates.ReportFormat;
import org.broadinstitute.sting.utils.report.utils.Node;
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
-import org.broadinstitute.sting.utils.classloader.PackageUtils;
+import org.broadinstitute.sting.utils.classloader.PluginManager;
import org.broadinstitute.sting.utils.Utils;
import org.broadinstitute.sting.commandline.Argument;
import org.broadinstitute.sting.commandline.Output;
@@ -351,7 +351,7 @@ public class VariantEvalWalker extends RodWalker implements Tr
}
private void listModulesAndExit() {
- List> veClasses = PackageUtils.getClassesImplementingInterface(VariantEvaluator.class);
+ List> veClasses = new PluginManager( VariantEvaluator.class ).getPlugins();
out.println("\nAvailable eval modules:");
out.println("(Standard modules are starred)");
for (Class extends VariantEvaluator> veClass : veClasses)
@@ -399,14 +399,14 @@ public class VariantEvalWalker extends RodWalker implements Tr
private void determineEvalations() {
// create a map for all eval modules for easy lookup
HashMap> classMap = new HashMap>();
- for ( Class extends VariantEvaluator> c : PackageUtils.getClassesImplementingInterface(VariantEvaluator.class) )
+ for ( Class extends VariantEvaluator> c : new PluginManager( VariantEvaluator.class ).getPlugins() )
classMap.put(c.getSimpleName(), c);
evaluationClasses = new HashSet>();
// by default, use standard eval modules
if ( !NO_STANDARD ) {
- for ( Class extends StandardEval> myClass : PackageUtils.getClassesImplementingInterface(StandardEval.class) ) {
+ for ( Class extends StandardEval> myClass : new PluginManager( StandardEval.class ).getPlugins() ) {
if ( classMap.containsKey(myClass.getSimpleName()) )
evaluationClasses.add(classMap.get(myClass.getSimpleName()));
}
diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/AnnotationByAlleleFrequencyWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/AnnotationByAlleleFrequencyWalker.java
index 0e10b2c6c..926842b7f 100755
--- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/AnnotationByAlleleFrequencyWalker.java
+++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/AnnotationByAlleleFrequencyWalker.java
@@ -31,13 +31,11 @@ import org.broadinstitute.sting.gatk.contexts.AlignmentContext;
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
import org.broadinstitute.sting.gatk.walkers.RodWalker;
-import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.AnnotationType;
+import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.AnnotationInterfaceManager;
import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.GenotypeAnnotation;
import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.InfoFieldAnnotation;
import org.broadinstitute.sting.utils.GenomeLoc;
-import org.broadinstitute.sting.utils.classloader.PackageUtils;
import org.broadinstitute.sting.utils.exceptions.DynamicClassResolutionException;
-import org.broadinstitute.sting.utils.exceptions.UserException;
import java.util.*;
@@ -63,8 +61,8 @@ public class AnnotationByAlleleFrequencyWalker extends RodWalker requestedInfoAnnotations;
- private ArrayList requestedGenotypeAnnotations;
+ private List requestedInfoAnnotations;
+ private List requestedGenotypeAnnotations;
//---------------------------------------------------------------------------------------------------------------
@@ -74,49 +72,11 @@ public class AnnotationByAlleleFrequencyWalker extends RodWalker classMap = new HashMap();
- for ( Class c : PackageUtils.getClassesImplementingInterface(InfoFieldAnnotation.class) )
- classMap.put(c.getSimpleName(), c);
- for ( Class c : PackageUtils.getClassesImplementingInterface(GenotypeAnnotation.class) )
- classMap.put(c.getSimpleName(), c);
- for ( Class c : PackageUtils.getInterfacesExtendingInterface(AnnotationType.class) )
- classMap.put(c.getSimpleName(), c);
-
- HashSet classes = new HashSet();
- // get the classes from the provided groups (interfaces)
- for ( String group : annotationClassesToUse ) {
- Class interfaceClass = classMap.get(group);
- if ( interfaceClass == null )
- interfaceClass = classMap.get(group + "Annotation");
- if ( interfaceClass == null )
- throw new UserException.BadArgumentValue("group", "Class " + group + " is not found; please check that you have specified the class name correctly");
- classes.addAll(PackageUtils.getClassesImplementingInterface(interfaceClass));
- }
-
- // get the specific classes provided
- for ( String annotation : annotationsToUse ) {
- Class annotationClass = classMap.get(annotation);
- if ( annotationClass == null )
- annotationClass = classMap.get(annotation + "Annotation");
- if ( annotationClass == null )
- throw new UserException.BadArgumentValue("annotation", "Class " + annotation + " is not found; please check that you have specified the class name correctly");
- classes.add(annotationClass);
- }
-
- // get the instances
- requestedInfoAnnotations = new ArrayList();
- requestedGenotypeAnnotations = new ArrayList();
-
- for ( Class c : classes ) {
- // note that technically an annotation can work on both the INFO and FORMAT fields
- if ( InfoFieldAnnotation.class.isAssignableFrom(c) )
- requestedInfoAnnotations.add((InfoFieldAnnotation)getInstance(c));
- if ( GenotypeAnnotation.class.isAssignableFrom(c) )
- requestedGenotypeAnnotations.add((GenotypeAnnotation)getInstance(c));
- }
-
+ List annotationClasses = Arrays.asList(annotationClassesToUse);
+ List annotations = Arrays.asList(annotationsToUse);
+ AnnotationInterfaceManager.validateAnnotations(annotationClasses, annotations);
+ requestedInfoAnnotations = AnnotationInterfaceManager.createInfoFieldAnnotations(annotationClasses, annotations);
+ requestedGenotypeAnnotations = AnnotationInterfaceManager.createGenotypeAnnotations(annotationClasses, annotations);
}
private static ArrayList getInstances(List> classes) {
diff --git a/java/src/org/broadinstitute/sting/queue/extensions/gatk/CommandLineProgramManager.java b/java/src/org/broadinstitute/sting/queue/extensions/gatk/CommandLineProgramManager.java
deleted file mode 100644
index cefca44da..000000000
--- a/java/src/org/broadinstitute/sting/queue/extensions/gatk/CommandLineProgramManager.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2010, The Broad Institute
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-package org.broadinstitute.sting.queue.extensions.gatk;
-
-import org.broadinstitute.sting.commandline.CommandLineProgram;
-import org.broadinstitute.sting.utils.classloader.PluginManager;
-
-import java.util.Collection;
-
-/**
- * Finds all command line programs.
- */
-public class CommandLineProgramManager extends PluginManager {
- public CommandLineProgramManager() {
- super(CommandLineProgram.class, "CommandLineProgram", "CLP");
- }
-
- public Collection> getValues() {
- return this.pluginsByName.values();
- }
-}
diff --git a/java/src/org/broadinstitute/sting/queue/extensions/gatk/GATKExtensionsGenerator.java b/java/src/org/broadinstitute/sting/queue/extensions/gatk/GATKExtensionsGenerator.java
index 53736586b..06d7cadef 100644
--- a/java/src/org/broadinstitute/sting/queue/extensions/gatk/GATKExtensionsGenerator.java
+++ b/java/src/org/broadinstitute/sting/queue/extensions/gatk/GATKExtensionsGenerator.java
@@ -40,6 +40,7 @@ import org.broadinstitute.sting.gatk.io.stubs.SAMFileWriterArgumentTypeDescripto
import org.broadinstitute.sting.gatk.refdata.tracks.builders.RMDTrackBuilder;
import org.broadinstitute.sting.gatk.walkers.ReadWalker;
import org.broadinstitute.sting.gatk.walkers.Walker;
+import org.broadinstitute.sting.utils.classloader.PluginManager;
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
import java.io.File;
@@ -62,7 +63,7 @@ public class GATKExtensionsGenerator extends CommandLineProgram {
@Output(fullName="output_directory", shortName="outDir", doc="Directory to output the generated scala", required=true)
public File outputDirectory;
- CommandLineProgramManager clpManager = new CommandLineProgramManager();
+ PluginManager clpManager = new PluginManager(CommandLineProgram.class, "CommandLineProgram", "CLP");
GenomeAnalysisEngine GATKEngine = new GenomeAnalysisEngine();
WalkerManager walkerManager = new WalkerManager();
FilterManager filterManager = new FilterManager();
@@ -97,7 +98,7 @@ public class GATKExtensionsGenerator extends CommandLineProgram {
if (!outputDirectory.isDirectory() && !outputDirectory.mkdirs())
throw new ReviewedStingException("Unable to create output directory: " + outputDirectory);
- for (Class extends CommandLineProgram> clp: clpManager.getValues()) {
+ for (Class extends CommandLineProgram> clp: clpManager.getPlugins()) {
if (!isGatkProgram(clp))
continue;
diff --git a/java/src/org/broadinstitute/sting/utils/Utils.java b/java/src/org/broadinstitute/sting/utils/Utils.java
index f902100ef..31fe6252d 100755
--- a/java/src/org/broadinstitute/sting/utils/Utils.java
+++ b/java/src/org/broadinstitute/sting/utils/Utils.java
@@ -312,6 +312,44 @@ public class Utils {
return new Pair(max, index);
}
+ /**
+ * Splits expressions in command args by spaces and returns the array of expressions.
+ * Expressions may use single or double quotes to group any individual expression, but not both.
+ * @param args Arguments to parse.
+ * @return Parsed expressions.
+ */
+ public static String[] escapeExpressions(String args) {
+ // special case for ' and " so we can allow expressions
+ if (args.indexOf('\'') != -1)
+ return escapeExpressions(args, "'");
+ else if (args.indexOf('\"') != -1)
+ return escapeExpressions(args, "\"");
+ else
+ return args.split(" ");
+ }
+
+ /**
+ * Splits expressions in command args by spaces and the supplied delimiter and returns the array of expressions.
+ * @param args Arguments to parse.
+ * @param delimiter Delimiter for grouping expressions.
+ * @return Parsed expressions.
+ */
+ private static String[] escapeExpressions(String args, String delimiter) {
+ String[] command = {};
+ String[] split = args.split(delimiter);
+ for (int i = 0; i < split.length - 1; i += 2) {
+ command = Utils.concatArrays(command, split[i].trim().split(" "));
+ command = Utils.concatArrays(command, new String[]{split[i + 1]});
+ }
+ return Utils.concatArrays(command, split[split.length - 1].trim().split(" "));
+ }
+
+ /**
+ * Concatenates two String arrays.
+ * @param A First array.
+ * @param B Second array.
+ * @return Concatenation of A then B.
+ */
public static String[] concatArrays(String[] A, String[] B) {
String[] C = new String[A.length + B.length];
System.arraycopy(A, 0, C, 0, A.length);
@@ -319,8 +357,22 @@ public class Utils {
return C;
}
+ /**
+ * Appends String(s) B to array A.
+ * @param A First array.
+ * @param B Strings to append.
+ * @return A with B(s) appended.
+ */
+ public static String[] appendArray(String[] A, String... B) {
+ return concatArrays(A, B);
+ }
- /** Returns indices of all occurrences of the specified symbol in the string */
+ /**
+ * Returns indices of all occurrences of the specified symbol in the string
+ * @param s Search string
+ * @param ch Character to search for
+ * @return Indices of all occurrences of the specified symbol
+ */
public static int[] indexOfAll(String s, int ch) {
int[] pos = new int[64];
int z = 0;
@@ -339,10 +391,10 @@ public class Utils {
* with zeros up to the new size. Finally, if new size is the same as original size, no memory reallocation
* will be performed and the original array will be returned instead.
*
- * @param orig
- * @param newSize
+ * @param orig Original size.
+ * @param newSize New Size.
*
- * @return
+ * @return New array with length equal to newSize.
*/
public static int[] reallocate(int[] orig, int newSize) {
if (orig.length == newSize) return orig;
@@ -360,7 +412,8 @@ public class Utils {
* array a.
* @param a original array
* @param n number of (v-filled) elements to append to a on the right (n>0) or on the left (n<0)
- * @return
+ * @param v element value
+ * @return the extended copy of array a with additional n elements
*/
public static byte [] extend(final byte[] a, int n, byte v) {
@@ -396,7 +449,8 @@ public class Utils {
* array a.
* @param a original array
* @param n number of (v-filled) elements to append to a on the right (n>0) or on the left (n<0)
- * @return
+ * @param v element value
+ * @return the extended copy of array a with additional n elements
*/
public static short [] extend(final short[] a, int n, short v) {
diff --git a/java/src/org/broadinstitute/sting/utils/classloader/JVMUtils.java b/java/src/org/broadinstitute/sting/utils/classloader/JVMUtils.java
index 83258aaf9..1aac9b565 100755
--- a/java/src/org/broadinstitute/sting/utils/classloader/JVMUtils.java
+++ b/java/src/org/broadinstitute/sting/utils/classloader/JVMUtils.java
@@ -26,15 +26,14 @@
package org.broadinstitute.sting.utils.classloader;
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
+import org.reflections.util.ClasspathHelper;
import java.lang.reflect.Modifier;
import java.lang.reflect.Field;
import java.io.File;
import java.io.IOException;
-import java.util.Collection;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Arrays;
+import java.net.URL;
+import java.util.*;
/**
* Created by IntelliJ IDEA.
@@ -178,4 +177,11 @@ public class JVMUtils {
return selectedObjects;
}
+ /**
+ * Returns the list of class path urls.
+ * @return the list of class path urls.
+ */
+ public static Set getClasspathURLs() {
+ return ClasspathHelper.getUrlsForManifestsCurrentClasspath();
+ }
}
diff --git a/java/src/org/broadinstitute/sting/utils/classloader/PackageUtils.java b/java/src/org/broadinstitute/sting/utils/classloader/PackageUtils.java
deleted file mode 100755
index 7d49de573..000000000
--- a/java/src/org/broadinstitute/sting/utils/classloader/PackageUtils.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Copyright (c) 2010 The Broad Institute
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
- * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-package org.broadinstitute.sting.utils.classloader;
-
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
-import org.broadinstitute.sting.utils.exceptions.DynamicClassResolutionException;
-import org.reflections.Reflections;
-import org.reflections.scanners.SubTypesScanner;
-import org.reflections.util.ClasspathHelper;
-import org.reflections.util.ConfigurationBuilder;
-import org.slf4j.LoggerFactory;
-
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.Set;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * PackageUtils contains some useful methods for package introspection.
- */
-public class PackageUtils {
-
- /**
- * A reference into our introspection utility.
- */
- private static Reflections reflections = null;
-
- static {
- // turn off logging in the reflections library - they talk too much (to the wrong logger factory as well, logback)
- Logger logger = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger(Reflections.class);
- logger.setLevel(Level.OFF);
- }
-
- /**
- * Private constructor. No instantiating this class!
- */
- private PackageUtils() {}
-
- /**
- * Return the classes that implement the specified interface.
- *
- * @param iface the interface which returned classes should implement.
- * @return the list of classes that implement the interface.
- */
- public static List> getClassesImplementingInterface(Class iface) {
- // Load all classes implementing the given interface, then filter out any class that isn't concrete.
- initReflections();
- Set> allTypes = reflections.getSubTypesOf(iface);
- List> concreteTypes = new ArrayList>();
- for( Class extends T> type: allTypes ) {
- if( JVMUtils.isConcrete(type) )
- concreteTypes.add(type);
- }
-
- return concreteTypes;
- }
-
- public static List getInstancesOfClassesImplementingInterface(Class iface) {
- List> classes = PackageUtils.getClassesImplementingInterface(iface);
- List instances = new ArrayList();
- for ( Class extends T> c : classes )
- instances.add(getSimpleInstance(c));
- return instances;
- }
-
- public static T getSimpleInstance(Class c) {
- try {
- return c.newInstance();
- } catch (Exception e) {
- throw new DynamicClassResolutionException(c, e);
- }
- }
-
- /**
- * Return the interface classes that extend the specified interface.
- *
- * @param iface the interface which returned classes should extend.
- * @return the list of interface classes that implement the interface.
- */
- public static List> getInterfacesExtendingInterface(Class iface) {
- // Load all classes extending the given interface, then filter out any class that is concrete.
- initReflections();
- Set> allTypes = reflections.getSubTypesOf(iface);
- List> nonConcreteTypes = new ArrayList>();
- for( Class extends T> type: allTypes ) {
- if( !JVMUtils.isConcrete(type) )
- nonConcreteTypes.add(type);
- }
-
- return nonConcreteTypes;
- }
-
- public static Set getClassPathURLs() {
- return ClasspathHelper.getUrlsForManifestsCurrentClasspath();
- }
-
- /**
- * Adds the URL to the system class loader classpath using reflection.
- * HACK: Uses reflection to modify the class path, and assumes loader is a URLClassLoader.
- * @param url URL to add to the system class loader classpath.
- */
- public static void addClasspath(URL url) {
- try {
- Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
- if (!method.isAccessible())
- method.setAccessible(true);
- method.invoke(ClassLoader.getSystemClassLoader(), url);
- resetReflections();
- } catch (Exception e) {
- throw new ReviewedStingException("Error adding url to the current classloader.", e);
- }
- }
-
- /**
- * Create new reflections object if it does not currently exists.
- */
- private static void initReflections() {
- if (reflections == null) {
- // Initialize general-purpose source tree reflector.
- reflections = new Reflections( new ConfigurationBuilder()
- .setUrls(getClassPathURLs())
- .setScanners(new SubTypesScanner()));
- }
- }
-
- /**
- * Resets the reflections object after a class has been dynamically added to the classpath.
- */
- private static void resetReflections() {
- reflections = null;
- }
-}
diff --git a/java/src/org/broadinstitute/sting/utils/classloader/PluginManager.java b/java/src/org/broadinstitute/sting/utils/classloader/PluginManager.java
index 463e25cd3..c34f3c75d 100644
--- a/java/src/org/broadinstitute/sting/utils/classloader/PluginManager.java
+++ b/java/src/org/broadinstitute/sting/utils/classloader/PluginManager.java
@@ -25,20 +25,42 @@
package org.broadinstitute.sting.utils.classloader;
-import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
import org.broadinstitute.sting.utils.exceptions.DynamicClassResolutionException;
+import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
import org.broadinstitute.sting.utils.exceptions.UserException;
+import org.reflections.Reflections;
+import org.reflections.scanners.SubTypesScanner;
+import org.reflections.util.ConfigurationBuilder;
+import org.slf4j.LoggerFactory;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.*;
/**
* Manage plugins and plugin configuration.
* @author mhanna
* @version 0.1
*/
-public abstract class PluginManager {
+public class PluginManager {
+ /**
+ * A reference into our introspection utility.
+ */
+ private static final Reflections defaultReflections;
+
+ static {
+ // turn off logging in the reflections library - they talk too much (to the wrong logger factory as well, logback)
+ Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Reflections.class);
+ logger.setLevel(Level.OFF);
+
+ defaultReflections = new Reflections( new ConfigurationBuilder()
+ .setUrls(JVMUtils.getClasspathURLs())
+ .setScanners(new SubTypesScanner()));
+ }
+
/**
* Defines the category of plugin defined by the subclass.
*/
@@ -48,11 +70,31 @@ public abstract class PluginManager {
* Define common strings to trim off the end of the name.
*/
protected final String pluginSuffix;
-
+
/**
* Plugins stored based on their name.
*/
- protected final Map> pluginsByName;
+ private SortedMap> pluginsByName = null;
+
+ private List> plugins;
+ private List> interfaces;
+
+ /**
+ * Create a new plugin manager.
+ * @param pluginType Core type for a plugin.
+ */
+ public PluginManager(Class pluginType) {
+ this(pluginType, pluginType.getSimpleName().toLowerCase(), pluginType.getSimpleName(), null);
+ }
+
+ /**
+ * Create a new plugin manager.
+ * @param pluginType Core type for a plugin.
+ * @param classpath Custom class path to search for classes.
+ */
+ public PluginManager(Class pluginType, List classpath) {
+ this(pluginType, pluginType.getSimpleName().toLowerCase(), pluginType.getSimpleName(), classpath);
+ }
/**
* Create a new plugin manager.
@@ -60,11 +102,75 @@ public abstract class PluginManager {
* @param pluginCategory Provides a category name to the plugin. Must not be null.
* @param pluginSuffix Provides a suffix that will be trimmed off when converting to a plugin name. Can be null.
*/
- protected PluginManager(Class pluginType, String pluginCategory, String pluginSuffix) {
+ public PluginManager(Class pluginType, String pluginCategory, String pluginSuffix) {
+ this(pluginType, pluginCategory, pluginSuffix, null);
+ }
+
+ /**
+ * Create a new plugin manager.
+ * @param pluginType Core type for a plugin.
+ * @param pluginCategory Provides a category name to the plugin. Must not be null.
+ * @param pluginSuffix Provides a suffix that will be trimmed off when converting to a plugin name. Can be null.
+ * @param classpath Custom class path to search for classes.
+ */
+ public PluginManager(Class pluginType, String pluginCategory, String pluginSuffix, List classpath) {
this.pluginCategory = pluginCategory;
this.pluginSuffix = pluginSuffix;
- List> plugins = PackageUtils.getClassesImplementingInterface(pluginType);
- pluginsByName = createPluginDatabase(plugins);
+
+ this.plugins = new ArrayList>();
+ this.interfaces = new ArrayList>();
+
+ Reflections reflections;
+ if (classpath == null) {
+ reflections = defaultReflections;
+ } else {
+ addClasspath(classpath);
+ reflections = new Reflections( new ConfigurationBuilder()
+ .setUrls(classpath)
+ .setScanners(new SubTypesScanner()));
+ }
+
+ // Load all classes types filtering them by concrete.
+ Set> allTypes = reflections.getSubTypesOf(pluginType);
+ for( Class extends PluginType> type: allTypes ) {
+ if( JVMUtils.isConcrete(type) )
+ plugins.add(type);
+ else
+ interfaces.add(type);
+ }
+ }
+
+ /**
+ * Adds the URL to the system class loader classpath using reflection.
+ * HACK: Uses reflection to modify the class path, and assumes loader is a URLClassLoader.
+ * @param urls URLs to add to the system class loader classpath.
+ */
+ private static void addClasspath(List urls) {
+ Set existing = JVMUtils.getClasspathURLs();
+ for (URL url : urls) {
+ if (existing.contains(url))
+ continue;
+ try {
+ Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
+ if (!method.isAccessible())
+ method.setAccessible(true);
+ method.invoke(ClassLoader.getSystemClassLoader(), url);
+ } catch (Exception e) {
+ throw new ReviewedStingException("Error adding url to the current classloader.", e);
+ }
+ }
+ }
+
+ protected SortedMap> getPluginsByName() {
+ if (pluginsByName == null) {
+ SortedMap> newPlugins = new TreeMap>();
+ for (Class extends PluginType> pluginClass : plugins) {
+ String pluginName = getName(pluginClass);
+ newPlugins.put(pluginName, pluginClass);
+ }
+ pluginsByName = newPlugins;
+ }
+ return pluginsByName;
}
/**
@@ -74,9 +180,49 @@ public abstract class PluginManager {
* @return True if the plugin exists, false otherwise.
*/
public boolean exists(String pluginName) {
- return pluginsByName.containsKey(pluginName);
+ return getPluginsByName().containsKey(pluginName);
}
+ /**
+ * Does a plugin with the given name exist?
+ *
+ * @param plugin Name of the plugin for which to search.
+ * @return True if the plugin exists, false otherwise.
+ */
+ public boolean exists(Class> plugin) {
+ return getPluginsByName().containsValue(plugin);
+ }
+
+ /**
+ * Returns the plugin classes
+ * @return the plugin classes
+ */
+ public List> getPlugins() {
+ return plugins;
+ }
+
+ /**
+ * Returns the interface classes
+ * @return the interface classes
+ */
+ public List> getInterfaces() {
+ return interfaces;
+ }
+
+ /**
+ * Returns the plugin classes implementing interface or base clase
+ * @param type type of interface or base class
+ * @return the plugin classes implementing interface or base class
+ */
+ public List> getPluginsImplementing(Class> type) {
+ List> implementing = new ArrayList>();
+ for (Class extends PluginType> plugin: getPlugins())
+ if (type.isAssignableFrom(plugin))
+ implementing.add(plugin);
+ return implementing;
+ }
+
+
/**
* Gets a plugin with the given name
@@ -85,7 +231,7 @@ public abstract class PluginManager {
* @return The plugin object if found; null otherwise.
*/
public PluginType createByName(String pluginName) {
- Class extends PluginType> plugin = pluginsByName.get(pluginName);
+ Class extends PluginType> plugin = getPluginsByName().get(pluginName);
if( plugin == null )
throw new UserException(String.format("Could not find %s with name: %s", pluginCategory,pluginName));
try {
@@ -101,6 +247,7 @@ public abstract class PluginManager {
* @param pluginType type of the plugin to create.
* @return The plugin object if created; null otherwise.
*/
+ @SuppressWarnings("unchecked")
public PluginType createByType(Class pluginType) {
try {
return ((Class extends PluginType>) pluginType).newInstance();
@@ -110,20 +257,19 @@ public abstract class PluginManager {
}
/**
- * Create the list of available plugins and add them to the database.
- *
- * @param pluginClasses Classes to record.
- * @return map of plugin name -> plugin.
+ * Returns concrete instances of the plugins
+ * @return concrete instances of the plugins
*/
- private Map> createPluginDatabase(List> pluginClasses) {
- Map> plugins = new HashMap>();
-
- for (Class extends PluginType> pluginClass : pluginClasses) {
- String pluginName = getName(pluginClass);
- plugins.put(pluginName, pluginClass);
+ public List createAllTypes() {
+ List instances = new ArrayList();
+ for ( Class extends PluginType> c : getPlugins() ) {
+ try {
+ instances.add(c.newInstance());
+ } catch (Exception e) {
+ throw new DynamicClassResolutionException(c, e);
+ }
}
-
- return plugins;
+ return instances;
}
/**
diff --git a/java/src/org/broadinstitute/sting/utils/interval/IntervalUtils.java b/java/src/org/broadinstitute/sting/utils/interval/IntervalUtils.java
index a2967d455..7b10ccf86 100644
--- a/java/src/org/broadinstitute/sting/utils/interval/IntervalUtils.java
+++ b/java/src/org/broadinstitute/sting/utils/interval/IntervalUtils.java
@@ -1,8 +1,12 @@
package org.broadinstitute.sting.utils.interval;
+import net.sf.picard.util.IntervalList;
+import net.sf.samtools.SAMFileHeader;
+import org.broadinstitute.sting.gatk.datasources.simpleDataSources.ReferenceDataSource;
import org.broadinstitute.sting.utils.GenomeLocSortedSet;
import org.broadinstitute.sting.utils.GenomeLoc;
import org.broadinstitute.sting.utils.GenomeLocParser;
+import org.broadinstitute.sting.utils.Utils;
import org.broadinstitute.sting.utils.exceptions.UserException;
import java.util.LinkedList;
@@ -25,6 +29,7 @@ public class IntervalUtils {
* 'all' can be supplied to indicate all possible intervals, but 'all' must be exclusive of all other interval
* specifications.
*
+ * @param parser Genome loc parser.
* @param argList A list of strings containing interval data.
* @param allowEmptyIntervalList If false instead of an empty interval list will return null.
* @return an unsorted, unmerged representation of the given intervals. Null is used to indicate that all intervals should be used.
@@ -107,7 +112,7 @@ public class IntervalUtils {
if (setOne.get(iOne).getStop() < setTwo.get(iTwo).getStop()) iOne++;
else iTwo++;
}
-
+
// we don't need to add the rest of remaining locations, since we know they don't overlap. return what we have
return retList;
}
@@ -117,6 +122,7 @@ public class IntervalUtils {
* all overlapping and abutting intervals into an interval that spans the union of all covered bases, and
* OVERLAPPING_ONLY, which unions overlapping intervals but keeps abutting intervals separate.
*
+ * @param parser Genome loc parser for the intervals.
* @param intervals A collection of intervals to merge.
* @param mergingRule A descriptor for the type of merging to perform.
* @return A sorted, merged version of the intervals passed in.
@@ -158,6 +164,131 @@ public class IntervalUtils {
else return false;
}
+ /**
+ * Returns the list of GenomeLocs from the list of intervals.
+ * @param referenceSource The reference for the intervals.
+ * @param intervals The interval as strings or file paths.
+ * @return The list of GenomeLocs.
+ */
+ private static List parseIntervalArguments(ReferenceDataSource referenceSource, List intervals) {
+ GenomeLocParser parser = new GenomeLocParser(referenceSource.getReference());
+ GenomeLocSortedSet locs;
+ // TODO: Abstract genome analysis engine has richer logic for parsing. We need to use it!
+ if (intervals.size() == 0) {
+ locs = GenomeLocSortedSet.createSetFromSequenceDictionary(referenceSource.getReference().getSequenceDictionary());
+ } else {
+ locs = new GenomeLocSortedSet(parser, IntervalUtils.parseIntervalArguments(parser, intervals, false));
+ }
+ if (locs == null || locs.size() == 0)
+ throw new UserException.MalformedFile("Intervals are empty: " + Utils.join(", ", intervals));
+ return locs.toList();
+ }
+
+ /**
+ * Returns the list of contigs from the list of intervals.
+ * @param reference The reference for the intervals.
+ * @return The list of contig names.
+ */
+ public static List distinctContigs(File reference) {
+ return distinctContigs(reference, Collections.emptyList());
+ }
+
+ /**
+ * Returns the list of contigs from the list of intervals.
+ * @param reference The reference for the intervals.
+ * @param intervals The interval as strings or file paths.
+ * @return The list of contig names.
+ */
+ public static List distinctContigs(File reference, List intervals) {
+ ReferenceDataSource referenceSource = new ReferenceDataSource(reference);
+ List locs = parseIntervalArguments(referenceSource, intervals);
+ String contig = null;
+ List contigs = new ArrayList();
+ for (GenomeLoc loc: locs) {
+ if (contig == null || !contig.equals(loc.getContig())) {
+ contig = loc.getContig();
+ contigs.add(contig);
+ }
+ }
+ return contigs;
+ }
+
+ /**
+ * Splits an interval list into multiple files.
+ * @param reference The reference for the intervals.
+ * @param intervals The interval as strings or file paths.
+ * @param scatterParts The output interval lists to write to.
+ * @param splitByContig If true then one contig will not be written to multiple files.
+ */
+ public static void scatterIntervalArguments(File reference, List intervals, List scatterParts, boolean splitByContig) {
+ ReferenceDataSource referenceSource = new ReferenceDataSource(reference);
+ List locs = parseIntervalArguments(referenceSource, intervals);
+ SAMFileHeader fileHeader = new SAMFileHeader();
+ fileHeader.setSequenceDictionary(referenceSource.getReference().getSequenceDictionary());
+
+ IntervalList intervalList = null;
+ int fileIndex = -1;
+ int locIndex = 0;
+
+ if (splitByContig) {
+ String contig = null;
+ for (GenomeLoc loc: locs) {
+ // If there are still more files to write and the contig doesn't match...
+ if ((fileIndex+1 < scatterParts.size()) && (contig == null || !contig.equals(loc.getContig()))) {
+ // Then close the current file and start a new one.
+ if (intervalList != null) {
+ intervalList.write(scatterParts.get(fileIndex));
+ intervalList = null;
+ }
+ fileIndex++;
+ contig = loc.getContig();
+ }
+ if (intervalList == null)
+ intervalList = new IntervalList(fileHeader);
+ intervalList.add(toInterval(loc, ++locIndex));
+ }
+ if (intervalList != null)
+ intervalList.write(scatterParts.get(fileIndex));
+ } else {
+ int locsPerFile = locs.size() / scatterParts.size();
+ int locRemainder = locs.size() % scatterParts.size();
+
+ // At the start, put an extra loc per file
+ locsPerFile++;
+ int locsLeftFile = 0;
+
+ for (GenomeLoc loc: locs) {
+ if (locsLeftFile == 0) {
+ if (intervalList != null)
+ intervalList.write(scatterParts.get(fileIndex));
+
+ fileIndex++;
+ intervalList = new IntervalList(fileHeader);
+
+ // When we have put enough locs into each file,
+ // reduce the number of locs per file back
+ // to the original calculated value.
+ if (fileIndex == locRemainder)
+ locsPerFile -= 1;
+ locsLeftFile = locsPerFile;
+ }
+ locsLeftFile -= 1;
+ intervalList.add(toInterval(loc, ++locIndex));
+ }
+ if (intervalList != null)
+ intervalList.write(scatterParts.get(fileIndex));
+ }
+ if ((fileIndex + 1) != scatterParts.size())
+ throw new UserException.BadArgumentValue("scatterParts", String.format("Only able to write contigs into %d of %d files.", fileIndex + 1, scatterParts.size()));
+ }
+
+ /**
+ * Converts a GenomeLoc to a picard interval.
+ * @param loc The GenomeLoc.
+ * @param locIndex The loc index for use in the file.
+ * @return The picard interval.
+ */
+ private static net.sf.picard.util.Interval toInterval(GenomeLoc loc, int locIndex) {
+ return new net.sf.picard.util.Interval(loc.getContig(), loc.getStart(), loc.getStop(), false, "interval_" + locIndex);
+ }
}
-
-
diff --git a/java/test/org/broadinstitute/sting/WalkerTest.java b/java/test/org/broadinstitute/sting/WalkerTest.java
index e8712fcb0..22a5180d5 100755
--- a/java/test/org/broadinstitute/sting/WalkerTest.java
+++ b/java/test/org/broadinstitute/sting/WalkerTest.java
@@ -311,35 +311,19 @@ public class WalkerTest extends BaseTest {
*/
private Pair, List> executeTest(String name, List md5s, List tmpFiles, String args, Class expectedException) {
CommandLineGATK instance = new CommandLineGATK();
- String[] command;
+ String[] command = Utils.escapeExpressions(args);
- // special case for ' and " so we can allow expressions
- if (args.indexOf('\'') != -1)
- command = escapeExpressions(args, "'");
- else if (args.indexOf('\"') != -1)
- command = escapeExpressions(args, "\"");
- else
- command = args.split(" ");
-
- if (outputFileLocation != null) {
- String[] cmd2 = Arrays.copyOf(command, command.length + 2);
- cmd2[command.length] = "-o";
- cmd2[command.length + 1] = this.outputFileLocation.getAbsolutePath();
- command = cmd2;
- }
+ if (outputFileLocation != null)
+ command = Utils.appendArray(command, "-o", this.outputFileLocation.getAbsolutePath());
// add the logging level to each of the integration test commands
- String[] cmd2 = Arrays.copyOf(command, command.length + 4);
- cmd2[command.length] = "-l";
- cmd2[command.length+1] = "WARN";
- cmd2[command.length+2] = "-et";
- cmd2[command.length+3] = ENABLE_REPORTING ? "STANDARD" : "NO_ET";
+ command = Utils.appendArray(command, "-l", "WARN", "-et", ENABLE_REPORTING ? "STANDARD" : "NO_ET");
// run the executable
boolean gotAnException = false;
try {
- System.out.println(String.format("Executing test %s with GATK arguments: %s", name, Utils.join(" ",cmd2)));
- CommandLineExecutable.start(instance, cmd2);
+ System.out.println(String.format("Executing test %s with GATK arguments: %s", name, Utils.join(" ",command)));
+ CommandLineExecutable.start(instance, command);
} catch (Exception e) {
gotAnException = true;
if ( expectedException != null ) {
@@ -370,25 +354,11 @@ public class WalkerTest extends BaseTest {
throw new RuntimeException("Error running the GATK with arguments: " + args);
}
- // clean up some memory
- instance = null;
- cmd2 = null;
-
// we need to check MD5s
return new Pair, List>(tmpFiles, assertMatchingMD5s(name, tmpFiles, md5s));
}
}
- private static String[] escapeExpressions(String args, String delimiter) {
- String[] command = {};
- String[] split = args.split(delimiter);
- for (int i = 0; i < split.length - 1; i += 2) {
- command = Utils.concatArrays(command, split[i].trim().split(" "));
- command = Utils.concatArrays(command, new String[]{split[i + 1]});
- }
- return Utils.concatArrays(command, split[split.length - 1].trim().split(" "));
- }
-
@Test
public void testWalkerUnitTest() {
//System.out.println("WalkerTest is just a framework");
diff --git a/java/test/org/broadinstitute/sting/utils/interval/IntervalUtilsTest.java b/java/test/org/broadinstitute/sting/utils/interval/IntervalUtilsTest.java
deleted file mode 100644
index d4fcb8b9f..000000000
--- a/java/test/org/broadinstitute/sting/utils/interval/IntervalUtilsTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-package org.broadinstitute.sting.utils.interval;
-
-import net.sf.picard.reference.IndexedFastaSequenceFile;
-import net.sf.picard.reference.ReferenceSequenceFile;
-import org.broadinstitute.sting.BaseTest;
-import org.testng.Assert;
-import org.broadinstitute.sting.utils.GenomeLoc;
-import org.broadinstitute.sting.utils.GenomeLocParser;
-
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * test out the interval utility methods
- */
-public class IntervalUtilsTest extends BaseTest {
- // used to seed the genome loc parser with a sequence dictionary
- private static ReferenceSequenceFile seq;
- private GenomeLocParser genomeLocParser;
-
- @BeforeClass
- public void init() throws FileNotFoundException {
- seq = new IndexedFastaSequenceFile(new File(hg18Reference));
- genomeLocParser = new GenomeLocParser(seq);
-
- }
-
- @Test
- public void testMergeListsBySetOperatorNoOverlap() {
- // a couple of lists we'll use for the testing
- List listEveryTwoFromOne = new ArrayList();
- List listEveryTwoFromTwo = new ArrayList();
-
- // create the two lists we'll use
- for (int x = 1; x < 101; x++) {
- if (x % 2 == 0)
- listEveryTwoFromTwo.add(genomeLocParser.createGenomeLoc("chr1",x,x));
- else
- listEveryTwoFromOne.add(genomeLocParser.createGenomeLoc("chr1",x,x));
- }
-
- List ret = IntervalUtils.mergeListsBySetOperator(listEveryTwoFromTwo, listEveryTwoFromOne, IntervalSetRule.UNION);
- Assert.assertEquals(ret.size(), 100);
- ret = IntervalUtils.mergeListsBySetOperator(listEveryTwoFromTwo, listEveryTwoFromOne, IntervalSetRule.INTERSECTION);
- Assert.assertEquals(ret.size(), 0);
- }
-
- @Test
- public void testMergeListsBySetOperatorAllOverlap() {
- // a couple of lists we'll use for the testing
- List allSites = new ArrayList();
- List listEveryTwoFromTwo = new ArrayList();
-
- // create the two lists we'll use
- for (int x = 1; x < 101; x++) {
- if (x % 2 == 0)
- listEveryTwoFromTwo.add(genomeLocParser.createGenomeLoc("chr1",x,x));
- allSites.add(genomeLocParser.createGenomeLoc("chr1",x,x));
- }
-
- List ret = IntervalUtils.mergeListsBySetOperator(listEveryTwoFromTwo, allSites, IntervalSetRule.UNION);
- Assert.assertEquals(ret.size(), 150);
- ret = IntervalUtils.mergeListsBySetOperator(listEveryTwoFromTwo, allSites, IntervalSetRule.INTERSECTION);
- Assert.assertEquals(ret.size(), 50);
- }
-
- @Test
- public void testMergeListsBySetOperator() {
- // a couple of lists we'll use for the testing
- List allSites = new ArrayList();
- List listEveryTwoFromTwo = new ArrayList();
-
- // create the two lists we'll use
- for (int x = 1; x < 101; x++) {
- if (x % 5 == 0) {
- listEveryTwoFromTwo.add(genomeLocParser.createGenomeLoc("chr1",x,x));
- allSites.add(genomeLocParser.createGenomeLoc("chr1",x,x));
- }
- }
-
- List ret = IntervalUtils.mergeListsBySetOperator(listEveryTwoFromTwo, allSites, IntervalSetRule.UNION);
- Assert.assertEquals(ret.size(), 40);
- ret = IntervalUtils.mergeListsBySetOperator(listEveryTwoFromTwo, allSites, IntervalSetRule.INTERSECTION);
- Assert.assertEquals(ret.size(), 20);
- }
-}
diff --git a/java/test/org/broadinstitute/sting/utils/interval/IntervalUtilsUnitTest.java b/java/test/org/broadinstitute/sting/utils/interval/IntervalUtilsUnitTest.java
new file mode 100644
index 000000000..9bd541866
--- /dev/null
+++ b/java/test/org/broadinstitute/sting/utils/interval/IntervalUtilsUnitTest.java
@@ -0,0 +1,356 @@
+package org.broadinstitute.sting.utils.interval;
+
+import net.sf.picard.reference.IndexedFastaSequenceFile;
+import net.sf.picard.reference.ReferenceSequenceFile;
+import org.broadinstitute.sting.BaseTest;
+import org.testng.Assert;
+import org.broadinstitute.sting.utils.exceptions.UserException;
+import org.broadinstitute.sting.utils.GenomeLoc;
+import org.broadinstitute.sting.utils.GenomeLocParser;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * test out the interval utility methods
+ */
+public class IntervalUtilsUnitTest extends BaseTest {
+ // used to seed the genome loc parser with a sequence dictionary
+ private static File reference = new File(BaseTest.hg18Reference);
+ private GenomeLocParser genomeLocParser;
+
+ @BeforeClass
+ public void init() {
+ ReferenceSequenceFile seq = new IndexedFastaSequenceFile(reference);
+ genomeLocParser = new GenomeLocParser(seq);
+ }
+
+ @Test
+ public void testMergeListsBySetOperatorNoOverlap() {
+ // a couple of lists we'll use for the testing
+ List listEveryTwoFromOne = new ArrayList();
+ List listEveryTwoFromTwo = new ArrayList();
+
+ // create the two lists we'll use
+ for (int x = 1; x < 101; x++) {
+ if (x % 2 == 0)
+ listEveryTwoFromTwo.add(genomeLocParser.createGenomeLoc("chr1",x,x));
+ else
+ listEveryTwoFromOne.add(genomeLocParser.createGenomeLoc("chr1",x,x));
+ }
+
+ List ret = IntervalUtils.mergeListsBySetOperator(listEveryTwoFromTwo, listEveryTwoFromOne, IntervalSetRule.UNION);
+ Assert.assertEquals(ret.size(), 100);
+ ret = IntervalUtils.mergeListsBySetOperator(listEveryTwoFromTwo, listEveryTwoFromOne, IntervalSetRule.INTERSECTION);
+ Assert.assertEquals(ret.size(), 0);
+ }
+
+ @Test
+ public void testMergeListsBySetOperatorAllOverlap() {
+ // a couple of lists we'll use for the testing
+ List allSites = new ArrayList();
+ List listEveryTwoFromTwo = new ArrayList();
+
+ // create the two lists we'll use
+ for (int x = 1; x < 101; x++) {
+ if (x % 2 == 0)
+ listEveryTwoFromTwo.add(genomeLocParser.createGenomeLoc("chr1",x,x));
+ allSites.add(genomeLocParser.createGenomeLoc("chr1",x,x));
+ }
+
+ List ret = IntervalUtils.mergeListsBySetOperator(listEveryTwoFromTwo, allSites, IntervalSetRule.UNION);
+ Assert.assertEquals(ret.size(), 150);
+ ret = IntervalUtils.mergeListsBySetOperator(listEveryTwoFromTwo, allSites, IntervalSetRule.INTERSECTION);
+ Assert.assertEquals(ret.size(), 50);
+ }
+
+ @Test
+ public void testMergeListsBySetOperator() {
+ // a couple of lists we'll use for the testing
+ List allSites = new ArrayList();
+ List listEveryTwoFromTwo = new ArrayList();
+
+ // create the two lists we'll use
+ for (int x = 1; x < 101; x++) {
+ if (x % 5 == 0) {
+ listEveryTwoFromTwo.add(genomeLocParser.createGenomeLoc("chr1",x,x));
+ allSites.add(genomeLocParser.createGenomeLoc("chr1",x,x));
+ }
+ }
+
+ List ret = IntervalUtils.mergeListsBySetOperator(listEveryTwoFromTwo, allSites, IntervalSetRule.UNION);
+ Assert.assertEquals(ret.size(), 40);
+ ret = IntervalUtils.mergeListsBySetOperator(listEveryTwoFromTwo, allSites, IntervalSetRule.INTERSECTION);
+ Assert.assertEquals(ret.size(), 20);
+ }
+
+ @Test
+ public void testCountContigs() {
+ List chrs = new ArrayList();
+ for (int i = 1; i <= 22; i++)
+ chrs.add("chr" + i);
+ chrs.add("chrX");
+ chrs.add("chrY");
+
+ List chrsNoRandom = Arrays.asList("chr12", "chr14", "chr20", "chrY");
+ List chrsWithRandom = new ArrayList();
+ chrsWithRandom.add("chrM");
+ chrsWithRandom.addAll(chrs);
+ for (String chr: chrs)
+ if(!chrsNoRandom.contains(chr))
+ chrsWithRandom.add(chr + "_random");
+
+ Assert.assertEquals(IntervalUtils.distinctContigs(reference), chrsWithRandom);
+ Assert.assertEquals(IntervalUtils.distinctContigs(reference, Arrays.asList(BaseTest.validationDataLocation + "TCGA-06-0188.interval_list")), chrs);
+ Assert.assertEquals(IntervalUtils.distinctContigs(reference, Arrays.asList("chr1:1-1", "chr2:1-1", "chr3:2-2")), Arrays.asList("chr1","chr2","chr3"));
+ Assert.assertEquals(IntervalUtils.distinctContigs(reference, Arrays.asList("chr2:1-1", "chr1:1-1", "chr3:2-2")), Arrays.asList("chr1","chr2","chr3"));
+ }
+
+ @Test
+ public void testBasicScatter() {
+ GenomeLoc chr1 = genomeLocParser.parseGenomeInterval("chr1");
+ GenomeLoc chr2 = genomeLocParser.parseGenomeInterval("chr2");
+ GenomeLoc chr3 = genomeLocParser.parseGenomeInterval("chr3");
+
+ List files = testFiles("basic.", 3, ".intervals");
+
+ IntervalUtils.scatterIntervalArguments(reference, Arrays.asList("chr1", "chr2", "chr3"), files, false);
+
+ List locs1 = IntervalUtils.parseIntervalArguments(genomeLocParser, Arrays.asList(files.get(0).toString()), false);
+ List locs2 = IntervalUtils.parseIntervalArguments(genomeLocParser, Arrays.asList(files.get(1).toString()), false);
+ List locs3 = IntervalUtils.parseIntervalArguments(genomeLocParser, Arrays.asList(files.get(2).toString()), false);
+
+ Assert.assertEquals(locs1.size(), 1);
+ Assert.assertEquals(locs2.size(), 1);
+ Assert.assertEquals(locs3.size(), 1);
+
+ Assert.assertEquals(locs1.get(0), chr1);
+ Assert.assertEquals(locs2.get(0), chr2);
+ Assert.assertEquals(locs3.get(0), chr3);
+ }
+
+ @Test
+ public void testScatterLessFiles() {
+ GenomeLoc chr1 = genomeLocParser.parseGenomeInterval("chr1");
+ GenomeLoc chr2 = genomeLocParser.parseGenomeInterval("chr2");
+ GenomeLoc chr3 = genomeLocParser.parseGenomeInterval("chr3");
+ GenomeLoc chr4 = genomeLocParser.parseGenomeInterval("chr4");
+
+ List files = testFiles("less.", 3, ".intervals");
+
+ IntervalUtils.scatterIntervalArguments(reference, Arrays.asList("chr1", "chr2", "chr3", "chr4"), files, false);
+
+ List locs1 = IntervalUtils.parseIntervalArguments(genomeLocParser, Arrays.asList(files.get(0).toString()), false);
+ List locs2 = IntervalUtils.parseIntervalArguments(genomeLocParser, Arrays.asList(files.get(1).toString()), false);
+ List locs3 = IntervalUtils.parseIntervalArguments(genomeLocParser, Arrays.asList(files.get(2).toString()), false);
+
+ Assert.assertEquals(locs1.size(), 2);
+ Assert.assertEquals(locs2.size(), 1);
+ Assert.assertEquals(locs3.size(), 1);
+
+ Assert.assertEquals(locs1.get(0), chr1);
+ Assert.assertEquals(locs1.get(1), chr2);
+ Assert.assertEquals(locs2.get(0), chr3);
+ Assert.assertEquals(locs3.get(0), chr4);
+ }
+
+ @Test(expectedExceptions=UserException.BadArgumentValue.class)
+ public void testScatterMoreFiles() {
+ List files = testFiles("more.", 3, ".intervals");
+ IntervalUtils.scatterIntervalArguments(reference, Arrays.asList("chr1", "chr2"), files, false);
+ }
+
+ @Test
+ public void testScatterIntervals() {
+ List intervals = Arrays.asList("chr1:1-2", "chr1:4-5", "chr2:1-1", "chr3:2-2");
+ GenomeLoc chr1a = genomeLocParser.parseGenomeInterval("chr1:1-2");
+ GenomeLoc chr1b = genomeLocParser.parseGenomeInterval("chr1:4-5");
+ GenomeLoc chr2 = genomeLocParser.parseGenomeInterval("chr2:1-1");
+ GenomeLoc chr3 = genomeLocParser.parseGenomeInterval("chr3:2-2");
+
+ List files = testFiles("split.", 3, ".intervals");
+
+ IntervalUtils.scatterIntervalArguments(reference, intervals, files, true);
+
+ List locs1 = IntervalUtils.parseIntervalArguments(genomeLocParser, Arrays.asList(files.get(0).toString()), false);
+ List locs2 = IntervalUtils.parseIntervalArguments(genomeLocParser, Arrays.asList(files.get(1).toString()), false);
+ List locs3 = IntervalUtils.parseIntervalArguments(genomeLocParser, Arrays.asList(files.get(2).toString()), false);
+
+ Assert.assertEquals(locs1.size(), 2);
+ Assert.assertEquals(locs2.size(), 1);
+ Assert.assertEquals(locs3.size(), 1);
+
+ Assert.assertEquals(locs1.get(0), chr1a);
+ Assert.assertEquals(locs1.get(1), chr1b);
+ Assert.assertEquals(locs2.get(0), chr2);
+ Assert.assertEquals(locs3.get(0), chr3);
+ }
+
+ @Test
+ public void testScatterOrder() {
+ List intervals = Arrays.asList("chr2:1-1", "chr1:1-1", "chr3:2-2");
+ GenomeLoc chr1 = genomeLocParser.parseGenomeInterval("chr1:1-1");
+ GenomeLoc chr2 = genomeLocParser.parseGenomeInterval("chr2:1-1");
+ GenomeLoc chr3 = genomeLocParser.parseGenomeInterval("chr3:2-2");
+
+ List files = testFiles("split.", 3, ".intervals");
+
+ IntervalUtils.scatterIntervalArguments(reference, intervals, files, true);
+
+ List locs1 = IntervalUtils.parseIntervalArguments(genomeLocParser, Arrays.asList(files.get(0).toString()), false);
+ List locs2 = IntervalUtils.parseIntervalArguments(genomeLocParser, Arrays.asList(files.get(1).toString()), false);
+ List locs3 = IntervalUtils.parseIntervalArguments(genomeLocParser, Arrays.asList(files.get(2).toString()), false);
+
+ Assert.assertEquals(locs1.size(), 1);
+ Assert.assertEquals(locs2.size(), 1);
+ Assert.assertEquals(locs3.size(), 1);
+
+ Assert.assertEquals(locs1.get(0), chr1);
+ Assert.assertEquals(locs2.get(0), chr2);
+ Assert.assertEquals(locs3.get(0), chr3);
+ }
+
+ @Test
+ public void testBasicScatterByContig() {
+ GenomeLoc chr1 = genomeLocParser.parseGenomeInterval("chr1");
+ GenomeLoc chr2 = genomeLocParser.parseGenomeInterval("chr2");
+ GenomeLoc chr3 = genomeLocParser.parseGenomeInterval("chr3");
+
+ List files = testFiles("contig_basic.", 3, ".intervals");
+
+ IntervalUtils.scatterIntervalArguments(reference, Arrays.asList("chr1", "chr2", "chr3"), files, true);
+
+ List locs1 = IntervalUtils.parseIntervalArguments(genomeLocParser, Arrays.asList(files.get(0).toString()), false);
+ List locs2 = IntervalUtils.parseIntervalArguments(genomeLocParser, Arrays.asList(files.get(1).toString()), false);
+ List locs3 = IntervalUtils.parseIntervalArguments(genomeLocParser, Arrays.asList(files.get(2).toString()), false);
+
+ Assert.assertEquals(locs1.size(), 1);
+ Assert.assertEquals(locs2.size(), 1);
+ Assert.assertEquals(locs3.size(), 1);
+
+ Assert.assertEquals(locs1.get(0), chr1);
+ Assert.assertEquals(locs2.get(0), chr2);
+ Assert.assertEquals(locs3.get(0), chr3);
+ }
+
+ @Test
+ public void testScatterByContigLessFiles() {
+ GenomeLoc chr1 = genomeLocParser.parseGenomeInterval("chr1");
+ GenomeLoc chr2 = genomeLocParser.parseGenomeInterval("chr2");
+ GenomeLoc chr3 = genomeLocParser.parseGenomeInterval("chr3");
+ GenomeLoc chr4 = genomeLocParser.parseGenomeInterval("chr4");
+
+ List files = testFiles("contig_less.", 3, ".intervals");
+
+ IntervalUtils.scatterIntervalArguments(reference, Arrays.asList("chr1", "chr2", "chr3", "chr4"), files, true);
+
+ List locs1 = IntervalUtils.parseIntervalArguments(genomeLocParser, Arrays.asList(files.get(0).toString()), false);
+ List locs2 = IntervalUtils.parseIntervalArguments(genomeLocParser, Arrays.asList(files.get(1).toString()), false);
+ List locs3 = IntervalUtils.parseIntervalArguments(genomeLocParser, Arrays.asList(files.get(2).toString()), false);
+
+ Assert.assertEquals(locs1.size(), 1);
+ Assert.assertEquals(locs2.size(), 1);
+ Assert.assertEquals(locs3.size(), 2);
+
+ Assert.assertEquals(locs1.get(0), chr1);
+ Assert.assertEquals(locs2.get(0), chr2);
+ Assert.assertEquals(locs3.get(0), chr3);
+ Assert.assertEquals(locs3.get(1), chr4);
+ }
+
+ @Test(expectedExceptions=UserException.BadArgumentValue.class)
+ public void testScatterByContigMoreFiles() {
+ List files = testFiles("contig_more.", 3, ".intervals");
+ IntervalUtils.scatterIntervalArguments(reference, Arrays.asList("chr1", "chr2"), files, true);
+ }
+
+ @Test
+ public void testScatterByContigIntervalsStart() {
+ List intervals = Arrays.asList("chr1:1-2", "chr1:4-5", "chr2:1-1", "chr3:2-2");
+ GenomeLoc chr1a = genomeLocParser.parseGenomeInterval("chr1:1-2");
+ GenomeLoc chr1b = genomeLocParser.parseGenomeInterval("chr1:4-5");
+ GenomeLoc chr2 = genomeLocParser.parseGenomeInterval("chr2:1-1");
+ GenomeLoc chr3 = genomeLocParser.parseGenomeInterval("chr3:2-2");
+
+ List files = testFiles("contig_split_start.", 3, ".intervals");
+
+ IntervalUtils.scatterIntervalArguments(reference, intervals, files, true);
+
+ List locs1 = IntervalUtils.parseIntervalArguments(genomeLocParser, Arrays.asList(files.get(0).toString()), false);
+ List locs2 = IntervalUtils.parseIntervalArguments(genomeLocParser, Arrays.asList(files.get(1).toString()), false);
+ List locs3 = IntervalUtils.parseIntervalArguments(genomeLocParser, Arrays.asList(files.get(2).toString()), false);
+
+ Assert.assertEquals(locs1.size(), 2);
+ Assert.assertEquals(locs2.size(), 1);
+ Assert.assertEquals(locs3.size(), 1);
+
+ Assert.assertEquals(locs1.get(0), chr1a);
+ Assert.assertEquals(locs1.get(1), chr1b);
+ Assert.assertEquals(locs2.get(0), chr2);
+ Assert.assertEquals(locs3.get(0), chr3);
+ }
+
+ @Test
+ public void testScatterByContigIntervalsMiddle() {
+ List intervals = Arrays.asList("chr1:1-1", "chr2:1-2", "chr2:4-5", "chr3:2-2");
+ GenomeLoc chr1 = genomeLocParser.parseGenomeInterval("chr1:1-1");
+ GenomeLoc chr2a = genomeLocParser.parseGenomeInterval("chr2:1-2");
+ GenomeLoc chr2b = genomeLocParser.parseGenomeInterval("chr2:4-5");
+ GenomeLoc chr3 = genomeLocParser.parseGenomeInterval("chr3:2-2");
+
+ List files = testFiles("contig_split_middle.", 3, ".intervals");
+
+ IntervalUtils.scatterIntervalArguments(reference, intervals, files, true);
+
+ List