GATK now does dynamic type determination for VCF files
Added UnitTests covering all of the cases.
This commit is contained in:
parent
e36994e36b
commit
0810c42309
|
|
@ -27,6 +27,7 @@ package org.broadinstitute.sting.commandline;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.broad.tribble.Feature;
|
||||
import org.broadinstitute.sting.gatk.refdata.tracks.FeatureManager;
|
||||
import org.broadinstitute.sting.gatk.walkers.Multiplex;
|
||||
import org.broadinstitute.sting.gatk.walkers.Multiplexer;
|
||||
import org.broadinstitute.sting.utils.classloader.JVMUtils;
|
||||
|
|
@ -313,19 +314,42 @@ class RodBindingArgumentTypeDescriptor extends ArgumentTypeDescriptor {
|
|||
String value = getArgumentValue( defaultDefinition, matches );
|
||||
try {
|
||||
String name = defaultDefinition.fullName;
|
||||
String tribbleType;
|
||||
String tribbleType = null;
|
||||
Tags tags = getArgumentTags(matches);
|
||||
// must have one or two tag values here
|
||||
if ( tags.getPositionalTags().size() == 2 ) { // -X:name,type style
|
||||
name = tags.getPositionalTags().get(0);
|
||||
tribbleType = tags.getPositionalTags().get(1);
|
||||
} else if ( tags.getPositionalTags().size() == 1 ) { // -X:type style
|
||||
tribbleType = tags.getPositionalTags().get(0);
|
||||
} else
|
||||
throw new UserException.CommandLineException(
|
||||
String.format("Unexpected number of positional tags for argument %s : %s. " +
|
||||
"Rod bindings only suport -X:type and -X:name,type argument styles",
|
||||
value, source.field.getName()));
|
||||
} else {
|
||||
if ( tags.getPositionalTags().size() == 1 ) {
|
||||
// -X:type style is a type when we cannot determine the type dynamically
|
||||
tribbleType = tags.getPositionalTags().get(0);
|
||||
}
|
||||
|
||||
// try to determine the file type dynamically
|
||||
FeatureManager manager = new FeatureManager();
|
||||
File file = new File(value);
|
||||
if ( file.canRead() && file.isFile() ) {
|
||||
FeatureManager.FeatureDescriptor featureDescriptor = manager.getByFiletype(file);
|
||||
if ( featureDescriptor != null ) {
|
||||
tribbleType = featureDescriptor.getName();
|
||||
logger.warn("Dynamically determined of " + file + " to be " + tribbleType);
|
||||
|
||||
if ( tags.getPositionalTags().size() == 1 ) {
|
||||
// -X:type style is a name when we can determine the type dynamically
|
||||
name = tags.getPositionalTags().get(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// now, if we haven't found a type
|
||||
if ( tribbleType == null )
|
||||
throw new UserException.CommandLineException(
|
||||
String.format("Unexpected number of positional tags for argument %s : %s. " +
|
||||
"Rod bindings only suport -X:type and -X:name,type argument styles",
|
||||
value, source.field.getName()));
|
||||
}
|
||||
|
||||
Constructor ctor = (makeRawTypeIfNecessary(type)).getConstructor(Class.class, String.class, String.class, String.class, Tags.class);
|
||||
Class parameterType = getParameterizedTypeClass(type);
|
||||
RodBinding result = (RodBinding)ctor.newInstance(parameterType, name, value, tribbleType, tags);
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
package org.broadinstitute.sting.commandline;
|
||||
|
||||
import org.broad.tribble.Feature;
|
||||
import org.broadinstitute.sting.gatk.refdata.features.beagle.BeagleFeature;
|
||||
import org.broadinstitute.sting.utils.exceptions.UserException;
|
||||
import org.broadinstitute.sting.utils.variantcontext.VariantContext;
|
||||
import org.testng.Assert;
|
||||
|
|
@ -837,5 +838,87 @@ public class ParsingEngineUnitTest extends BaseTest {
|
|||
Assert.assertEquals(argProvider.bindings.get(1).getName(), "foo2", "Name isn't set properly");
|
||||
}
|
||||
|
||||
private final static String HISEQ_VCF = testDir + "HiSeq.10000.vcf";
|
||||
private final static String TRANCHES_FILE = testDir + "tranches.6.txt";
|
||||
|
||||
@Test
|
||||
public void variantContextBindingTestDynamicTyping1() {
|
||||
final String[] commandLine = new String[] {"-V", HISEQ_VCF};
|
||||
|
||||
parsingEngine.addArgumentSource( VariantContextRodBindingArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
|
||||
VariantContextRodBindingArgProvider argProvider = new VariantContextRodBindingArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider );
|
||||
|
||||
Assert.assertEquals(argProvider.binding.getName(), "binding", "Name isn't set properly");
|
||||
Assert.assertEquals(argProvider.binding.getSource(), HISEQ_VCF, "Source isn't set to its expected value");
|
||||
Assert.assertEquals(argProvider.binding.getType(), VariantContext.class, "Type isn't set to its expected value");
|
||||
Assert.assertEquals(argProvider.binding.getTags().getPositionalTags().size(), 0, "Tags aren't correctly set");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void variantContextBindingTestDynamicTypingNameAsSingleArgument() {
|
||||
final String[] commandLine = new String[] {"-V:name", HISEQ_VCF};
|
||||
|
||||
parsingEngine.addArgumentSource( VariantContextRodBindingArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
|
||||
VariantContextRodBindingArgProvider argProvider = new VariantContextRodBindingArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider );
|
||||
|
||||
Assert.assertEquals(argProvider.binding.getName(), "name", "Name isn't set properly");
|
||||
Assert.assertEquals(argProvider.binding.getSource(), HISEQ_VCF, "Source isn't set to its expected value");
|
||||
Assert.assertEquals(argProvider.binding.getType(), VariantContext.class, "Type isn't set to its expected value");
|
||||
Assert.assertEquals(argProvider.binding.getTags().getPositionalTags().size(), 1, "Tags aren't correctly set");
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void variantContextBindingTestDynamicTypingTwoTagsPassing() {
|
||||
final String[] commandLine = new String[] {"-V:name,vcf", HISEQ_VCF};
|
||||
|
||||
parsingEngine.addArgumentSource( VariantContextRodBindingArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
|
||||
VariantContextRodBindingArgProvider argProvider = new VariantContextRodBindingArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider );
|
||||
|
||||
Assert.assertEquals(argProvider.binding.getName(), "name", "Name isn't set properly");
|
||||
Assert.assertEquals(argProvider.binding.getSource(), HISEQ_VCF, "Source isn't set to its expected value");
|
||||
Assert.assertEquals(argProvider.binding.getType(), VariantContext.class, "Type isn't set to its expected value");
|
||||
Assert.assertEquals(argProvider.binding.getTags().getPositionalTags().size(), 2, "Tags aren't correctly set");
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void variantContextBindingTestDynamicTypingTwoTagsCausingTypeFailure() {
|
||||
final String[] commandLine = new String[] {"-V:name,beagle", HISEQ_VCF};
|
||||
|
||||
parsingEngine.addArgumentSource( VariantContextRodBindingArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
|
||||
VariantContextRodBindingArgProvider argProvider = new VariantContextRodBindingArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject(argProvider);
|
||||
|
||||
Assert.assertEquals(argProvider.binding.getName(), "name", "Name isn't set properly");
|
||||
Assert.assertEquals(argProvider.binding.getSource(), HISEQ_VCF, "Source isn't set to its expected value");
|
||||
Assert.assertEquals(argProvider.binding.getType(), VariantContext.class, "Type isn't set to its expected value");
|
||||
Assert.assertEquals(argProvider.binding.getTribbleType(), "beagle", "Type isn't set to its expected value");
|
||||
Assert.assertEquals(argProvider.binding.getTags().getPositionalTags().size(), 2, "Tags aren't correctly set");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = UserException.class)
|
||||
public void variantContextBindingTestDynamicTypingUnknownTribbleType() {
|
||||
final String[] commandLine = new String[] {"-V", TRANCHES_FILE};
|
||||
|
||||
parsingEngine.addArgumentSource( VariantContextRodBindingArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
|
||||
VariantContextRodBindingArgProvider argProvider = new VariantContextRodBindingArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue