Okay, I caved in:

CallsetConcordance now gets possible concordance types by looking at classes that implement ConcordanceType instead of having them hard-coded in.
Thanks to Kiran this was pretty easy...


git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1939 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
ebanks 2009-10-30 00:32:26 +00:00
parent 1f0d852a48
commit 64ac956885
5 changed files with 42 additions and 45 deletions

View File

@ -26,32 +26,23 @@ public class CallsetConcordanceWalker extends RefWalker<Integer, Integer> {
private ArrayList<ConcordanceType> requestedTypes;
private HashMap<String, ConcordanceType> initializeConcordanceTypes(String prefix) {
HashMap<String, ConcordanceType> types = new HashMap<String, ConcordanceType>();
//
// Add new concordance types here!
//
types.put("SNPGenotypeConcordance", new SNPGenotypeConcordance(prefix));
types.put("SimpleVenn", new SimpleVenn(prefix));
types.put("IndelSubsets", new IndelSubsets(prefix));
return types;
}
/**
* Prepare the output file and the list of available features.
*/
public void initialize() {
HashMap<String, ConcordanceType> concordanceTypes = initializeConcordanceTypes(OUTPUT_PATH);
// get the possible concordance types
List<Class<? extends ConcordanceType>> classes = PackageUtils.getClassesImplementingInterface(ConcordanceType.class);
// print and exit if that's what was requested
if (LIST_ONLY) {
Iterator<String> types = concordanceTypes.keySet().iterator();
out.println("\nAvailable concordance types:");
while ( types.hasNext() )
out.println("\t" + types.next());
for (int i = 0; i < classes.size(); i++)
out.println("\t" + classes.get(i).getSimpleName());
out.println();
System.exit(0);
}
requestedTypes = new ArrayList<ConcordanceType>();
// initialize requested concordance types
@ -59,22 +50,37 @@ public class CallsetConcordanceWalker extends RefWalker<Integer, Integer> {
for ( String requestedTypeString : TYPES ) {
String[] requestedPieces = requestedTypeString.split(":");
String requestedType = requestedPieces[0];
ConcordanceType type = concordanceTypes.get(requestedType);
if ( type == null )
throw new StingException("The requested concordance type (" + requestedType + ") isn't a valid option");
HashMap<String,String> requestedArgs = new HashMap<String,String>();
if ( requestedPieces.length == 2 ) {
String[] argStrings = requestedPieces[1].split(",");
for (int i = 0; i < argStrings.length; i++ ) {
String[] arg = argStrings[i].split("=");
if ( arg.length == 2 )
requestedArgs.put(arg[0], arg[1]);
boolean foundClass = false;
for ( Class type : classes ) {
if (requestedType.equalsIgnoreCase(type.getSimpleName())) {
foundClass = true;
try {
ConcordanceType concordance = (ConcordanceType)type.newInstance();
HashMap<String,String> requestedArgs = new HashMap<String,String>();
if ( requestedPieces.length == 2 ) {
String[] argStrings = requestedPieces[1].split(",");
for (int i = 0; i < argStrings.length; i++ ) {
String[] arg = argStrings[i].split("=");
if ( arg.length == 2 )
requestedArgs.put(arg[0], arg[1]);
}
}
concordance.initialize(OUTPUT_PATH, requestedArgs);
requestedTypes.add(concordance);
break;
} catch (InstantiationException e) {
throw new StingException(String.format("Cannot instantiate concordance class '%s': must be concrete class", type.getSimpleName()));
} catch (IllegalAccessException e) {
throw new StingException(String.format("Cannot instantiate concordance class '%s': must have no-arg constructor", type.getSimpleName()));
}
}
}
type.initialize(requestedArgs);
requestedTypes.add(type);
if ( !foundClass )
throw new StingException("The requested concordance type (" + requestedType + ") isn't a valid concordance option");
}
}
}

View File

@ -7,7 +7,7 @@ import java.util.HashMap;
public interface ConcordanceType {
public void initialize(HashMap<String,String> args);
public void initialize(String prefix, HashMap<String,String> args);
public void computeConcordance(RefMetaDataTracker tracker, ReferenceContext ref);
public void cleanup();

View File

@ -23,13 +23,10 @@ public class IndelSubsets implements ConcordanceType {
private int sizeCutoff = 2;
private PrintWriter[][][][] writers = new PrintWriter[2][2][2][2];
private String prefix;
public IndelSubsets(String prefix) {
this.prefix = prefix;
}
public IndelSubsets() {}
public void initialize(HashMap<String,String> args) {
public void initialize(String prefix, HashMap<String,String> args) {
if ( args.get("sizeCutoff") != null )
sizeCutoff = Integer.valueOf(args.get("sizeCutoff"));
if ( args.get("homopolymerCutoff") != null )

View File

@ -28,13 +28,10 @@ public class SNPGenotypeConcordance implements ConcordanceType {
private PrintWriter comboVarWriter = null;
private PrintWriter coverageVar1Writer = null;
private PrintWriter coverageVar2Writer = null;
private String prefix;
public SNPGenotypeConcordance(String prefix) {
this.prefix = prefix;
}
public SNPGenotypeConcordance() {}
public void initialize(HashMap<String,String> args) {
public void initialize(String prefix, HashMap<String,String> args) {
try {
sameVarWriter = new PrintWriter(prefix + ".snp_concordance.sameConfidentVariant.calls");
oneVarWriter = new PrintWriter(prefix + ".snp_concordance.bothVariantOnlyOneIsConfident.calls");

View File

@ -21,13 +21,10 @@ public class SimpleVenn implements ConcordanceType {
private PrintWriter discord_writer = null;
private PrintWriter set1_writer = null;
private PrintWriter set2_writer = null;
private String prefix;
public SimpleVenn(String prefix) {
this.prefix = prefix;
}
public SimpleVenn() {}
public void initialize(HashMap<String,String> args) {
public void initialize(String prefix, HashMap<String,String> args) {
try {
union_writer = new PrintWriter(prefix + ".venn.union.calls");
intersect_writer = new PrintWriter(prefix + ".venn.intersection.calls");