Enum support for command-line argument system, and some cleanup for hacks to the CleanedReadInjector that were required because Enum support was missing.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1199 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
aacec3aeb0
commit
da4d26b1ea
|
|
@ -157,7 +157,7 @@ public class CommandLineGATK extends CommandLineProgram {
|
|||
public Object createArgument( Class type, String repr ) {
|
||||
if (type == SAMFileReader.class) {
|
||||
SAMFileReader samFileReader = new SAMFileReader(new File(repr),true);
|
||||
samFileReader.setValidationStringency(GenomeAnalysisEngine.getValidationStringency(argCollection));
|
||||
samFileReader.setValidationStringency(argCollection.strictnessLevel);
|
||||
return samFileReader;
|
||||
}
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.samtools.SAMFileReader;
|
||||
|
||||
/**
|
||||
*
|
||||
* User: aaron
|
||||
|
|
@ -118,7 +120,7 @@ public class GATKArgumentCollection {
|
|||
|
||||
@Element(required = false)
|
||||
@Argument(fullName = "validation_strictness", shortName = "S", doc = "How strict should we be with validation (LENIENT|SILENT|STRICT)", required = false)
|
||||
public String strictnessLevel = "silent";
|
||||
public SAMFileReader.ValidationStringency strictnessLevel = SAMFileReader.ValidationStringency.SILENT;
|
||||
|
||||
@Element(required = false)
|
||||
@Argument(fullName = "unsafe", shortName = "U", doc = "If set, enables unsafe operations, nothing will be checked at runtime.", required = false)
|
||||
|
|
|
|||
|
|
@ -124,10 +124,7 @@ public class GenomeAnalysisEngine {
|
|||
GenomeLocParser.setupRefContigOrdering(refFile);
|
||||
}
|
||||
|
||||
// Determine the validation stringency. Default to ValidationStringency.STRICT.
|
||||
ValidationStringency strictness = getValidationStringency(argCollection);
|
||||
|
||||
logger.info("Strictness is " + strictness);
|
||||
logger.info("Strictness is " + argCollection.strictnessLevel);
|
||||
|
||||
// perform validation steps that are common to all the engines
|
||||
genericEngineSetup();
|
||||
|
|
@ -219,7 +216,7 @@ public class GenomeAnalysisEngine {
|
|||
*/
|
||||
private Reads extractSourceInfoFromArguments( GATKArgumentCollection argCollection ) {
|
||||
return new Reads( argCollection.samFiles,
|
||||
getValidationStringency(argCollection),
|
||||
argCollection.strictnessLevel,
|
||||
argCollection.downsampleFraction,
|
||||
argCollection.downsampleCoverage,
|
||||
!argCollection.unsafe,
|
||||
|
|
@ -262,22 +259,6 @@ public class GenomeAnalysisEngine {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Default to ValidationStringency.STRICT.
|
||||
* TODO: Store ValidationStringency as pre-parsed enum in GATKArgumentCollection.
|
||||
* @return the validation stringency
|
||||
*/
|
||||
public static ValidationStringency getValidationStringency( GATKArgumentCollection argCollection ) {
|
||||
ValidationStringency strictness = ValidationStringency.SILENT;
|
||||
try {
|
||||
strictness = Enum.valueOf(ValidationStringency.class, argCollection.strictnessLevel.toUpperCase().trim());
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
logger.debug("Unable to parse strictness from command line. Assuming SILENT");
|
||||
}
|
||||
return strictness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default to 5 (based on research by Alec Wysoker)
|
||||
*
|
||||
|
|
|
|||
|
|
@ -468,6 +468,8 @@ public class ParsingEngine {
|
|||
throw new StingException("Unable to parse argument '" + str + "' into a character.");
|
||||
Character c = str.trim().charAt(0);
|
||||
return c;
|
||||
} else if (type.isEnum()) {
|
||||
return Enum.valueOf(type,str.toUpperCase().trim());
|
||||
} else {
|
||||
Constructor ctor = null;
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import org.junit.Test;
|
|||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import net.sf.samtools.SAMFileReader;
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 The Broad Institute
|
||||
*
|
||||
|
|
@ -79,7 +81,7 @@ public class GATKArgumentCollectionTest extends BaseTest {
|
|||
input.add(new File("test.file"));
|
||||
collect.samFiles = input;
|
||||
collect.maximumEngineIterations = -1;
|
||||
collect.strictnessLevel = "strict";
|
||||
collect.strictnessLevel = SAMFileReader.ValidationStringency.STRICT;
|
||||
collect.referenceFile = new File("referenceFile".toLowerCase());
|
||||
collect.analysisName = "analysisName".toLowerCase();
|
||||
collect.DBSNPFile = "DBSNPFile".toLowerCase();
|
||||
|
|
|
|||
|
|
@ -140,6 +140,55 @@ public class ParsingEngineTest extends BaseTest {
|
|||
public String[] inputFile;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enumTest() {
|
||||
final String[] commandLine = new String[] { "--test_enum", "TWO" };
|
||||
|
||||
parsingEngine.addArgumentSource( EnumArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
|
||||
EnumArgProvider argProvider = new EnumArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider );
|
||||
|
||||
Assert.assertEquals("Enum value is not correct", TestEnum.TWO, argProvider.testEnum);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enumMixedCaseTest() {
|
||||
final String[] commandLine = new String[] { "--test_enum", "oNe" };
|
||||
|
||||
parsingEngine.addArgumentSource( EnumArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
|
||||
EnumArgProvider argProvider = new EnumArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider );
|
||||
|
||||
Assert.assertEquals("Enum value is not correct", TestEnum.ONE, argProvider.testEnum);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enumDefaultTest() {
|
||||
final String[] commandLine = new String[] {};
|
||||
|
||||
parsingEngine.addArgumentSource( EnumArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
|
||||
EnumArgProvider argProvider = new EnumArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider );
|
||||
|
||||
Assert.assertEquals("Enum value is not correct", TestEnum.THREE, argProvider.testEnum);
|
||||
}
|
||||
|
||||
public enum TestEnum { ONE, TWO, THREE };
|
||||
|
||||
private class EnumArgProvider {
|
||||
@Argument(fullName="test_enum",shortName="ti",doc="test enum",required=false)
|
||||
public TestEnum testEnum = TestEnum.THREE;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void typedCollectionTest() {
|
||||
final String[] commandLine = new String[] { "-N","2","-N","4","-N","6","-N","8","-N","10" };
|
||||
|
|
|
|||
Loading…
Reference in New Issue