IntelliJ no longer complains that my methods are too complex to analyze.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2708 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
rpoplin 2010-01-27 20:12:13 +00:00
parent fc4285f9fd
commit 3999a8d2c8
3 changed files with 20 additions and 22 deletions

View File

@ -8,8 +8,6 @@ import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.AlignmentContext;
import org.broadinstitute.sting.utils.cmdLine.Argument; import org.broadinstitute.sting.utils.cmdLine.Argument;
import java.io.IOException;
/* /*
* Copyright (c) 2010 The Broad Institute * Copyright (c) 2010 The Broad Institute
* *

View File

@ -5,6 +5,7 @@ import org.broadinstitute.sting.utils.BaseUtils;
import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.StingException;
import java.util.*; import java.util.*;
import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -47,7 +48,7 @@ public class AnnotationDataManager {
data = new HashMap<String, TreeSet<AnnotationDatum>>(); data = new HashMap<String, TreeSet<AnnotationDatum>>();
} }
public void addAnnotations( RodVCF variant, String sampleName ) { public void addAnnotations( final RodVCF variant, final String sampleName ) {
if( sampleName != null ) { // Only process variants that are found in the sample with this sampleName if( sampleName != null ) { // Only process variants that are found in the sample with this sampleName
if( variant.getGenotype(sampleName).isNoCall() ) { // This variant isn't found in this sample so break out if( variant.getGenotype(sampleName).isNoCall() ) { // This variant isn't found in this sample so break out
@ -60,14 +61,10 @@ public class AnnotationDataManager {
for( String annotationKey : infoField.keySet() ) { for( String annotationKey : infoField.keySet() ) {
float value = 0.0f; float value = 0.0f;
boolean skipThisAnnotation = false;
try { try {
value = Float.parseFloat( infoField.get( annotationKey ) ); value = Float.parseFloat( infoField.get( annotationKey ) );
} catch( NumberFormatException e ) { } catch( NumberFormatException e ) {
skipThisAnnotation = true; // Skip over annotations that aren't floats, like older versions of "AC" and "DB" continue; // Skip over annotations that aren't floats, like "DB"
}
if( skipThisAnnotation ) {
continue; // Skip over annotations that aren't floats, like older versions of "AC" and "DB"
} }
TreeSet<AnnotationDatum> treeSet = data.get( annotationKey ); TreeSet<AnnotationDatum> treeSet = data.get( annotationKey );
@ -76,17 +73,17 @@ public class AnnotationDataManager {
data.put( annotationKey, treeSet ); data.put( annotationKey, treeSet );
} }
AnnotationDatum datum = new AnnotationDatum( value ); AnnotationDatum datum = new AnnotationDatum( value );
if( treeSet.contains(datum) ) { if( treeSet.contains(datum) ) { // contains uses AnnotationDatum's equals function, so it only checks if the value field is already present
datum = treeSet.tailSet(datum).first(); datum = treeSet.tailSet(datum).first();
} else { } else {
treeSet.add(datum); treeSet.add(datum);
} }
final boolean isNovelVariant = variant.getID().equals("."); final boolean isNovelVariant = variant.getID().equals(".");
final boolean isTrueVariant = false; final boolean isTrueVariant = false; //BUGBUG: Check truth input file to see if this variant is in the truth set
// Decide if it was a Ti or a Tv // Decide if the variant is a transition or transversion
if( BaseUtils.isTransition(variant.getReferenceForSNP(), variant.getAlternativeBaseForSNP()) ) { if( BaseUtils.isTransition( variant.getReferenceForSNP(), variant.getAlternativeBaseForSNP()) ) {
datum.incrementTi( isNovelVariant, isTrueVariant ); datum.incrementTi( isNovelVariant, isTrueVariant );
} else { } else {
datum.incrementTv( isNovelVariant, isTrueVariant ); datum.incrementTv( isNovelVariant, isTrueVariant );
@ -97,6 +94,7 @@ public class AnnotationDataManager {
public void plotCumulativeTables( final String PATH_TO_RSCRIPT, final String PATH_TO_RESOURCES, final String OUTPUT_PREFIX, public void plotCumulativeTables( final String PATH_TO_RSCRIPT, final String PATH_TO_RESOURCES, final String OUTPUT_PREFIX,
final int MIN_VARIANTS_PER_BIN, final int MAX_VARIANTS_PER_BIN ) { final int MIN_VARIANTS_PER_BIN, final int MAX_VARIANTS_PER_BIN ) {
final AnnotationDatum thisAnnotationBin = new AnnotationDatum();
System.out.println( "\nExecuting RScript commands:" ); System.out.println( "\nExecuting RScript commands:" );
// For each annotation we've seen // For each annotation we've seen
@ -113,8 +111,8 @@ public class AnnotationDataManager {
// Output a header line // Output a header line
output.println("value\ttitv\tnumVariants\tcategory"); output.println("value\ttitv\tnumVariants\tcategory");
// Bin SNPs and calculate truth metrics for each bin, right now this is just TiTv // Bin SNPs and calculate truth metrics for each bin
AnnotationDatum thisAnnotationBin = new AnnotationDatum(); thisAnnotationBin.clearBin();
for( AnnotationDatum datum : data.get( annotationKey ) ) { for( AnnotationDatum datum : data.get( annotationKey ) ) {
thisAnnotationBin.combine( datum ); thisAnnotationBin.combine( datum );
if( thisAnnotationBin.numVariants( AnnotationDatum.FULL_SET ) >= MAX_VARIANTS_PER_BIN ) { // This annotation bin is full if( thisAnnotationBin.numVariants( AnnotationDatum.FULL_SET ) >= MAX_VARIANTS_PER_BIN ) { // This annotation bin is full
@ -126,24 +124,26 @@ public class AnnotationDataManager {
// else, continue accumulating variants because this bin isn't full yet // else, continue accumulating variants because this bin isn't full yet
} }
if( thisAnnotationBin.numVariants( AnnotationDatum.FULL_SET ) != 0 ) { // one final bin that may not have been dumped out if( thisAnnotationBin.numVariants( AnnotationDatum.FULL_SET ) != 0 ) { // One final bin that may not have been dumped out
output.println( thisAnnotationBin.value + "\t" + thisAnnotationBin.calcTiTv( AnnotationDatum.FULL_SET ) + "\t" + thisAnnotationBin.numVariants( AnnotationDatum.FULL_SET ) + "\tall"); output.println( thisAnnotationBin.value + "\t" + thisAnnotationBin.calcTiTv( AnnotationDatum.FULL_SET ) + "\t" + thisAnnotationBin.numVariants( AnnotationDatum.FULL_SET ) + "\tall");
output.println( thisAnnotationBin.value + "\t" + thisAnnotationBin.calcTiTv( AnnotationDatum.NOVEL_SET ) + "\t" + thisAnnotationBin.numVariants( AnnotationDatum.NOVEL_SET ) + "\tnovel"); output.println( thisAnnotationBin.value + "\t" + thisAnnotationBin.calcTiTv( AnnotationDatum.NOVEL_SET ) + "\t" + thisAnnotationBin.numVariants( AnnotationDatum.NOVEL_SET ) + "\tnovel");
output.println( thisAnnotationBin.value + "\t" + thisAnnotationBin.calcTiTv( AnnotationDatum.DBSNP_SET ) + "\t" + thisAnnotationBin.numVariants( AnnotationDatum.DBSNP_SET ) + "\tdbsnp"); output.println( thisAnnotationBin.value + "\t" + thisAnnotationBin.calcTiTv( AnnotationDatum.DBSNP_SET ) + "\t" + thisAnnotationBin.numVariants( AnnotationDatum.DBSNP_SET ) + "\tdbsnp");
} }
// Close the PrintStream
output.close(); output.close();
System.out.println(PATH_TO_RSCRIPT + " " + PATH_TO_RESOURCES + "plot_Annotations_BinnedTiTv.R" + " " + // Print out the command line to make it clear to the user what is being executed and how one might modify it
OUTPUT_PREFIX + annotationKey + ".dat" + " " + annotationKey + " " + MIN_VARIANTS_PER_BIN); final String rScriptCommandLine = PATH_TO_RSCRIPT + " " + PATH_TO_RESOURCES + "plot_Annotations_BinnedTiTv.R" + " " +
OUTPUT_PREFIX + annotationKey + ".dat" + " " + annotationKey + " " + MIN_VARIANTS_PER_BIN;
System.out.println( rScriptCommandLine );
// Execute the RScript command to plot the table of TiTv values // Execute the RScript command to plot the table of TiTv values
try { try {
final Process p = Runtime.getRuntime().exec(PATH_TO_RSCRIPT + " " + PATH_TO_RESOURCES + "plot_Annotations_BinnedTiTv.R" + " " + Runtime.getRuntime().exec( rScriptCommandLine );
OUTPUT_PREFIX + annotationKey + ".dat" + " " + annotationKey + " " + MIN_VARIANTS_PER_BIN); } catch ( IOException e ) {
} catch ( Exception e ) { throw new StingException( "Unable to execute RScript command: " + rScriptCommandLine );
throw new StingException( "Unable to execute RScript command" );
} }
} }
} }

View File

@ -98,7 +98,7 @@ public class AnnotationDatum implements Comparator<AnnotationDatum> {
this.ti[iii] += that.ti[iii]; this.ti[iii] += that.ti[iii];
this.tv[iii] += that.tv[iii]; this.tv[iii] += that.tv[iii];
} }
this.value = that.value; // overwrite this bin's value this.value = that.value; // Overwrite this bin's value
} }
final public float calcTiTv( final int INDEX ) { final public float calcTiTv( final int INDEX ) {