Move the cleaned read injector test from playground to core. Remove CovariateCounterTest's dependency on the CleanedReadInjector. Start doing a bit of cleanup on the CLP's FieldParsers.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1312 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
e2ec703a32
commit
2db86b7829
|
|
@ -270,15 +270,21 @@ class ArgumentDefinition {
|
||||||
* Creates a new argument definition.
|
* Creates a new argument definition.
|
||||||
* @param source Source information for defining the argument.
|
* @param source Source information for defining the argument.
|
||||||
*/
|
*/
|
||||||
public ArgumentDefinition( ArgumentSource source ) {
|
public ArgumentDefinition( ArgumentSource source,
|
||||||
|
String fullName,
|
||||||
|
String shortName,
|
||||||
|
String doc,
|
||||||
|
boolean required,
|
||||||
|
String exclusiveOf,
|
||||||
|
String validation ) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
|
|
||||||
fullName = source.getFullName();
|
this.fullName = fullName;
|
||||||
shortName = source.getShortName();
|
this.shortName = shortName;
|
||||||
doc = source.getDoc();
|
this.doc = doc;
|
||||||
required = source.isRequired();
|
this.required = required;
|
||||||
exclusiveOf = source.getExclusiveOf();
|
this.exclusiveOf = exclusiveOf;
|
||||||
validation = source.getValidationRegex();
|
this.validation = validation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ import org.broadinstitute.sting.utils.StingException;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes the source field which defines a command-line argument.
|
* Describes the source field which defines a command-line argument.
|
||||||
|
|
@ -94,53 +96,26 @@ public class ArgumentSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the full name of the argument, specifiable with the '--' prefix. The full name can be
|
* Generate a list of all argument definitions to which this argument source maps.
|
||||||
* either specified explicitly with the fullName annotation parameter or implied by the field name.
|
* @return A non-null, non-empty list of argument definitions.
|
||||||
* @return full name of the argument. Never null.
|
|
||||||
*/
|
*/
|
||||||
public String getFullName() {
|
public List<ArgumentDefinition> createArgumentDefinitions() {
|
||||||
return descriptor.fullName().trim().length() > 0 ? descriptor.fullName().trim() : field.getName().toLowerCase();
|
String fullName = descriptor.fullName().trim().length() > 0 ? descriptor.fullName().trim() : field.getName().toLowerCase();
|
||||||
}
|
String shortName = descriptor.shortName().trim().length() > 0 ? descriptor.shortName().trim() : null;
|
||||||
|
String doc = descriptor.doc();
|
||||||
|
boolean required = descriptor.required() && !isFlag();
|
||||||
|
String exclusiveOf = descriptor.exclusiveOf().trim().length() > 0 ? descriptor.exclusiveOf().trim() : null;
|
||||||
|
String validation = descriptor.validation().trim().length() > 0 ? descriptor.validation().trim() : null;
|
||||||
|
|
||||||
/**
|
ArgumentDefinition argumentDefinition = new ArgumentDefinition( this,
|
||||||
* Retrieves the short name of the argument, specifiable with the '-' prefix. The short name can
|
fullName,
|
||||||
* be specified or not; if left unspecified, no short name will be present.
|
shortName,
|
||||||
* @return short name of the argument. Null if no short name exists.
|
doc,
|
||||||
*/
|
required,
|
||||||
public String getShortName() {
|
exclusiveOf,
|
||||||
return descriptor.shortName().trim().length() > 0 ? descriptor.shortName().trim() : null;
|
validation );
|
||||||
}
|
|
||||||
|
return Collections.singletonList(argumentDefinition);
|
||||||
/**
|
|
||||||
* Documentation for this argument. Mandatory field.
|
|
||||||
* @return Documentation for this argument.
|
|
||||||
*/
|
|
||||||
public String getDoc() {
|
|
||||||
return descriptor.doc();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether this field is required. Note that flag fields are always forced to 'not required'.
|
|
||||||
* @return True if the field is mandatory and not a boolean flag. False otherwise.
|
|
||||||
*/
|
|
||||||
public boolean isRequired() {
|
|
||||||
return descriptor.required() && !isFlag();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Specifies other arguments which cannot be used in conjunction with tihs argument. Comma-separated list.
|
|
||||||
* @return A comma-separated list of exclusive arguments, or null if none are present.
|
|
||||||
*/
|
|
||||||
public String getExclusiveOf() {
|
|
||||||
return descriptor.exclusiveOf().trim().length() > 0 ? descriptor.exclusiveOf().trim() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A regular expression which can be used for validation.
|
|
||||||
* @return a JVM regex-compatible regular expression, or null to permit any possible value.
|
|
||||||
*/
|
|
||||||
public String getValidationRegex() {
|
|
||||||
return descriptor.validation().trim().length() > 0 ? descriptor.validation().trim() : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -38,54 +38,54 @@ import java.util.*;
|
||||||
* @author mhanna
|
* @author mhanna
|
||||||
* @version 0.1
|
* @version 0.1
|
||||||
*/
|
*/
|
||||||
public abstract class FieldParser {
|
public abstract class ArgumentTypeDescriptor {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* our log, which we want to capture anything from org.broadinstitute.sting
|
* our log, which we want to capture anything from org.broadinstitute.sting
|
||||||
*/
|
*/
|
||||||
protected static Logger logger = Logger.getLogger(FieldParser.class);
|
protected static Logger logger = Logger.getLogger(ArgumentTypeDescriptor.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of the field which should be parsed by this argument.
|
* Name of the field which should be parsed by this argument.
|
||||||
*/
|
*/
|
||||||
protected final String fieldName;
|
protected final String fieldName;
|
||||||
|
|
||||||
public static FieldParser create( Field field ) {
|
public static ArgumentTypeDescriptor create( Field field ) {
|
||||||
Class type = field.getType();
|
Class type = field.getType();
|
||||||
|
|
||||||
if( Collection.class.isAssignableFrom(type) || type.isArray() )
|
if( Collection.class.isAssignableFrom(type) || type.isArray() )
|
||||||
return new JRECompoundFieldParser( field );
|
return new CompoundArgumentTypeDescriptor( field );
|
||||||
else
|
else
|
||||||
return new JRESimpleFieldParser( field );
|
return new SimpleArgumentTypeDescriptor( field );
|
||||||
}
|
}
|
||||||
|
|
||||||
static FieldParser create( String fieldName, Class type ) {
|
static ArgumentTypeDescriptor create( String fieldName, Class type ) {
|
||||||
if( Collection.class.isAssignableFrom(type) || type.isArray() )
|
if( Collection.class.isAssignableFrom(type) || type.isArray() )
|
||||||
return new JRECompoundFieldParser( fieldName, type );
|
return new CompoundArgumentTypeDescriptor( fieldName, type );
|
||||||
else
|
else
|
||||||
return new JRESimpleFieldParser( fieldName, type );
|
return new SimpleArgumentTypeDescriptor( fieldName, type );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected FieldParser( Field field ) {
|
protected ArgumentTypeDescriptor( Field field ) {
|
||||||
fieldName = field.toString();
|
fieldName = field.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected FieldParser( String fieldName ) {
|
protected ArgumentTypeDescriptor( String fieldName ) {
|
||||||
this.fieldName = fieldName;
|
this.fieldName = fieldName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract Object parse( String... values );
|
public abstract Object parse( String... values );
|
||||||
}
|
}
|
||||||
|
|
||||||
class JRESimpleFieldParser extends FieldParser {
|
class SimpleArgumentTypeDescriptor extends ArgumentTypeDescriptor {
|
||||||
private final Class type;
|
private final Class type;
|
||||||
|
|
||||||
public JRESimpleFieldParser( Field field ) {
|
public SimpleArgumentTypeDescriptor( Field field ) {
|
||||||
super( field );
|
super( field );
|
||||||
this.type = field.getType();
|
this.type = field.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JRESimpleFieldParser( String fieldName, Class type ) {
|
public SimpleArgumentTypeDescriptor( String fieldName, Class type ) {
|
||||||
super( fieldName );
|
super( fieldName );
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
@ -142,12 +142,12 @@ class JRESimpleFieldParser extends FieldParser {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
class JRECompoundFieldParser extends FieldParser {
|
class CompoundArgumentTypeDescriptor extends ArgumentTypeDescriptor {
|
||||||
private final Class type;
|
private final Class type;
|
||||||
private final Class componentType;
|
private final Class componentType;
|
||||||
private final FieldParser componentArgumentParser;
|
private final ArgumentTypeDescriptor componentArgumentParser;
|
||||||
|
|
||||||
public JRECompoundFieldParser( Field field ) {
|
public CompoundArgumentTypeDescriptor( Field field ) {
|
||||||
super( field );
|
super( field );
|
||||||
Class candidateType = field.getType();
|
Class candidateType = field.getType();
|
||||||
|
|
||||||
|
|
@ -181,10 +181,10 @@ class JRECompoundFieldParser extends FieldParser {
|
||||||
else
|
else
|
||||||
throw new StingException("Unsupported compound argument type: " + candidateType);
|
throw new StingException("Unsupported compound argument type: " + candidateType);
|
||||||
|
|
||||||
componentArgumentParser = FieldParser.create( fieldName, componentType );
|
componentArgumentParser = ArgumentTypeDescriptor.create( fieldName, componentType );
|
||||||
}
|
}
|
||||||
|
|
||||||
public JRECompoundFieldParser( String fieldName, Class type ) {
|
public CompoundArgumentTypeDescriptor( String fieldName, Class type ) {
|
||||||
super(fieldName);
|
super(fieldName);
|
||||||
|
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|
@ -198,7 +198,7 @@ class JRECompoundFieldParser extends FieldParser {
|
||||||
else
|
else
|
||||||
throw new StingException("Unsupported compound argument type: " + type);
|
throw new StingException("Unsupported compound argument type: " + type);
|
||||||
|
|
||||||
componentArgumentParser = FieldParser.create( fieldName, componentType );
|
componentArgumentParser = ArgumentTypeDescriptor.create( fieldName, componentType );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -85,7 +85,7 @@ public class ParsingEngine {
|
||||||
public void addArgumentSource( String sourceName, Class sourceClass ) {
|
public void addArgumentSource( String sourceName, Class sourceClass ) {
|
||||||
List<ArgumentDefinition> argumentsFromSource = new ArrayList<ArgumentDefinition>();
|
List<ArgumentDefinition> argumentsFromSource = new ArrayList<ArgumentDefinition>();
|
||||||
for( ArgumentSource argumentSource: extractArgumentSources(sourceClass,true) )
|
for( ArgumentSource argumentSource: extractArgumentSources(sourceClass,true) )
|
||||||
argumentsFromSource.add( new ArgumentDefinition(argumentSource) );
|
argumentsFromSource.addAll( argumentSource.createArgumentDefinitions() );
|
||||||
argumentDefinitions.add( new ArgumentDefinitionGroup(sourceName, argumentsFromSource) );
|
argumentDefinitions.add( new ArgumentDefinitionGroup(sourceName, argumentsFromSource) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -280,7 +280,7 @@ public class ParsingEngine {
|
||||||
|
|
||||||
if( !definition.source.isFlag() ) {
|
if( !definition.source.isFlag() ) {
|
||||||
String[] tokens = match.values().toArray(new String[0]);
|
String[] tokens = match.values().toArray(new String[0]);
|
||||||
FieldParser fieldParser = FieldParser.create(definition.source.field);
|
ArgumentTypeDescriptor fieldParser = ArgumentTypeDescriptor.create(definition.source.field);
|
||||||
definition.source.setValue( object, fieldParser.parse(tokens) );
|
definition.source.setValue( object, fieldParser.parse(tokens) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -355,7 +355,7 @@ public class ParsingEngine {
|
||||||
* @return Parsed object of the inferred type.
|
* @return Parsed object of the inferred type.
|
||||||
*/
|
*/
|
||||||
private Object constructFromString(Field f, List<String> strs) {
|
private Object constructFromString(Field f, List<String> strs) {
|
||||||
FieldParser fieldParser = FieldParser.create(f);
|
ArgumentTypeDescriptor fieldParser = ArgumentTypeDescriptor.create(f);
|
||||||
return fieldParser.parse( strs.toArray(new String[0]) );
|
return fieldParser.parse( strs.toArray(new String[0]) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.broadinstitute.sting.playground.gatk.walkers.indels;
|
package org.broadinstitute.sting.gatk.walkers.indels;
|
||||||
|
|
||||||
import org.broadinstitute.sting.BaseTest;
|
import org.broadinstitute.sting.BaseTest;
|
||||||
import org.broadinstitute.sting.gatk.OutputTracker;
|
import org.broadinstitute.sting.gatk.OutputTracker;
|
||||||
|
|
@ -11,7 +11,6 @@ import org.junit.Test;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.broadinstitute.sting.BaseTest;
|
import org.broadinstitute.sting.BaseTest;
|
||||||
import org.broadinstitute.sting.playground.gatk.walkers.indels.CleanedReadInjector;
|
|
||||||
import org.broadinstitute.sting.utils.QualityUtils;
|
import org.broadinstitute.sting.utils.QualityUtils;
|
||||||
import org.broadinstitute.sting.utils.BaseUtils;
|
import org.broadinstitute.sting.utils.BaseUtils;
|
||||||
import org.broadinstitute.sting.utils.GenomeLocParser;
|
import org.broadinstitute.sting.utils.GenomeLocParser;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue