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:
hanna 2009-07-08 20:26:16 +00:00
parent aacec3aeb0
commit da4d26b1ea
6 changed files with 60 additions and 24 deletions

View File

@ -157,7 +157,7 @@ public class CommandLineGATK extends CommandLineProgram {
public Object createArgument( Class type, String repr ) { public Object createArgument( Class type, String repr ) {
if (type == SAMFileReader.class) { if (type == SAMFileReader.class) {
SAMFileReader samFileReader = new SAMFileReader(new File(repr),true); SAMFileReader samFileReader = new SAMFileReader(new File(repr),true);
samFileReader.setValidationStringency(GenomeAnalysisEngine.getValidationStringency(argCollection)); samFileReader.setValidationStringency(argCollection.strictnessLevel);
return samFileReader; return samFileReader;
} }
return null; return null;

View File

@ -14,6 +14,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.sf.samtools.SAMFileReader;
/** /**
* *
* User: aaron * User: aaron
@ -118,7 +120,7 @@ public class GATKArgumentCollection {
@Element(required = false) @Element(required = false)
@Argument(fullName = "validation_strictness", shortName = "S", doc = "How strict should we be with validation (LENIENT|SILENT|STRICT)", 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) @Element(required = false)
@Argument(fullName = "unsafe", shortName = "U", doc = "If set, enables unsafe operations, nothing will be checked at runtime.", required = false) @Argument(fullName = "unsafe", shortName = "U", doc = "If set, enables unsafe operations, nothing will be checked at runtime.", required = false)

View File

@ -124,10 +124,7 @@ public class GenomeAnalysisEngine {
GenomeLocParser.setupRefContigOrdering(refFile); GenomeLocParser.setupRefContigOrdering(refFile);
} }
// Determine the validation stringency. Default to ValidationStringency.STRICT. logger.info("Strictness is " + argCollection.strictnessLevel);
ValidationStringency strictness = getValidationStringency(argCollection);
logger.info("Strictness is " + strictness);
// perform validation steps that are common to all the engines // perform validation steps that are common to all the engines
genericEngineSetup(); genericEngineSetup();
@ -219,7 +216,7 @@ public class GenomeAnalysisEngine {
*/ */
private Reads extractSourceInfoFromArguments( GATKArgumentCollection argCollection ) { private Reads extractSourceInfoFromArguments( GATKArgumentCollection argCollection ) {
return new Reads( argCollection.samFiles, return new Reads( argCollection.samFiles,
getValidationStringency(argCollection), argCollection.strictnessLevel,
argCollection.downsampleFraction, argCollection.downsampleFraction,
argCollection.downsampleCoverage, argCollection.downsampleCoverage,
!argCollection.unsafe, !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) * Default to 5 (based on research by Alec Wysoker)
* *

View File

@ -468,6 +468,8 @@ public class ParsingEngine {
throw new StingException("Unable to parse argument '" + str + "' into a character."); throw new StingException("Unable to parse argument '" + str + "' into a character.");
Character c = str.trim().charAt(0); Character c = str.trim().charAt(0);
return c; return c;
} else if (type.isEnum()) {
return Enum.valueOf(type,str.toUpperCase().trim());
} else { } else {
Constructor ctor = null; Constructor ctor = null;
try { try {

View File

@ -10,6 +10,8 @@ import org.junit.Test;
import java.io.File; import java.io.File;
import java.util.*; import java.util.*;
import net.sf.samtools.SAMFileReader;
/* /*
* Copyright (c) 2009 The Broad Institute * Copyright (c) 2009 The Broad Institute
* *
@ -79,7 +81,7 @@ public class GATKArgumentCollectionTest extends BaseTest {
input.add(new File("test.file")); input.add(new File("test.file"));
collect.samFiles = input; collect.samFiles = input;
collect.maximumEngineIterations = -1; collect.maximumEngineIterations = -1;
collect.strictnessLevel = "strict"; collect.strictnessLevel = SAMFileReader.ValidationStringency.STRICT;
collect.referenceFile = new File("referenceFile".toLowerCase()); collect.referenceFile = new File("referenceFile".toLowerCase());
collect.analysisName = "analysisName".toLowerCase(); collect.analysisName = "analysisName".toLowerCase();
collect.DBSNPFile = "DBSNPFile".toLowerCase(); collect.DBSNPFile = "DBSNPFile".toLowerCase();

View File

@ -140,6 +140,55 @@ public class ParsingEngineTest extends BaseTest {
public String[] inputFile; 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 @Test
public void typedCollectionTest() { public void typedCollectionTest() {
final String[] commandLine = new String[] { "-N","2","-N","4","-N","6","-N","8","-N","10" }; final String[] commandLine = new String[] { "-N","2","-N","4","-N","6","-N","8","-N","10" };