Fixes for GSA-201, where enumerated types in command line arguments had to be defined as all uppercase for the system to work.
Also a little playground walker that changes the sort order flag of a BAM file. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1805 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
32d55eb2ff
commit
62c484b57a
|
|
@ -0,0 +1,49 @@
|
||||||
|
package org.broadinstitute.sting.playground.gatk.walkers;
|
||||||
|
|
||||||
|
import org.broadinstitute.sting.gatk.walkers.ReadWalker;
|
||||||
|
import org.broadinstitute.sting.gatk.GenomeAnalysisEngine;
|
||||||
|
import org.broadinstitute.sting.utils.cmdLine.Argument;
|
||||||
|
import net.sf.samtools.SAMFileWriter;
|
||||||
|
import net.sf.samtools.SAMRecord;
|
||||||
|
import net.sf.samtools.SAMFileHeader;
|
||||||
|
import net.sf.samtools.SAMFileWriterFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by IntelliJ IDEA.
|
||||||
|
* User: aaron
|
||||||
|
* Date: Oct 9, 2009
|
||||||
|
* Time: 2:21:08 PM
|
||||||
|
*/
|
||||||
|
public class UpdateSAMSortOrderWalker extends ReadWalker<SAMRecord, SAMFileWriter> {
|
||||||
|
|
||||||
|
@Argument(required=true, shortName="out_bam", doc="The samfile to output to")
|
||||||
|
public File SAM_FILE_OUTPUT_LOCATION;
|
||||||
|
|
||||||
|
@Argument(required=false, shortName="sortorder", doc="the sort order to emit in")
|
||||||
|
public SAMFileHeader.SortOrder SORT_ORDER=SAMFileHeader.SortOrder.coordinate;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SAMRecord map(char[] ref, SAMRecord read) {
|
||||||
|
return read;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SAMFileWriter reduceInit() {
|
||||||
|
SAMFileHeader header = GenomeAnalysisEngine.instance.getSAMFileHeader();
|
||||||
|
header.setSortOrder(SORT_ORDER);
|
||||||
|
SAMFileWriterFactory factory = new SAMFileWriterFactory();
|
||||||
|
return factory.makeBAMWriter(header,false,SAM_FILE_OUTPUT_LOCATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SAMFileWriter reduce(SAMRecord value, SAMFileWriter sum) {
|
||||||
|
sum.addAlignment(value);
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onTraversalDone(SAMFileWriter result) {
|
||||||
|
result.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -241,7 +241,10 @@ class SimpleArgumentTypeDescriptor extends ArgumentTypeDescriptor {
|
||||||
Method valueOf = primitiveToWrapperMap.get(type).getMethod("valueOf",String.class);
|
Method valueOf = primitiveToWrapperMap.get(type).getMethod("valueOf",String.class);
|
||||||
return valueOf.invoke(null,value.trim());
|
return valueOf.invoke(null,value.trim());
|
||||||
} else if (type.isEnum()) {
|
} else if (type.isEnum()) {
|
||||||
return Enum.valueOf(type,value.toUpperCase().trim());
|
Object[] vals = type.getEnumConstants();
|
||||||
|
for (Object val : vals)
|
||||||
|
if (String.valueOf(val).equalsIgnoreCase(value)) return val;
|
||||||
|
throw new UnknownEnumeratedValueException(value, type.getName());
|
||||||
} else {
|
} else {
|
||||||
Constructor ctor = type.getConstructor(String.class);
|
Constructor ctor = type.getConstructor(String.class);
|
||||||
return ctor.newInstance(value);
|
return ctor.newInstance(value);
|
||||||
|
|
|
||||||
|
|
@ -485,4 +485,18 @@ class ArgumentsAreMutuallyExclusiveException extends ArgumentException {
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An exception for when an argument doesn't match an of the enumerated options for that var type
|
||||||
|
*/
|
||||||
|
class UnknownEnumeratedValueException extends ArgumentException {
|
||||||
|
public UnknownEnumeratedValueException(String argumentPassed, String typeName ) {
|
||||||
|
super( formatArguments(argumentPassed, typeName) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String formatArguments(String argumentPassed, String typeName ) {
|
||||||
|
return new String("Enumerated constant " + argumentPassed + " Not found in type " + typeName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue