moved a bunch of files over to the logging system. In some cases I ballparked the severity level of an error, so if you see something wrong feel free to make changes.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@209 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
aaron 2009-03-27 13:27:04 +00:00
parent 935a4d81c9
commit d115209e86
5 changed files with 145 additions and 103 deletions

View File

@ -230,17 +230,17 @@ public class GenomeAnalysisTK extends CommandLineProgram {
final String startContigName = startContig.getSequenceName(); final String startContigName = startContig.getSequenceName();
for ( SAMSequenceRecord targetContig : refFile.getSequenceDictionary().getSequences() ) { for ( SAMSequenceRecord targetContig : refFile.getSequenceDictionary().getSequences() ) {
refFile.seekToContig(startContigName, true); refFile.seekToContig(startContigName, true);
System.out.printf("Seeking: current=%s, target=%s%n", startContigName, targetContig.getSequenceName()); logger.info(String.format("Seeking: current=%s, target=%s%n", startContigName, targetContig.getSequenceName()));
long lastTime = System.currentTimeMillis(); long lastTime = System.currentTimeMillis();
final boolean success = refFile.seekToContig(targetContig.getSequenceName(), true); final boolean success = refFile.seekToContig(targetContig.getSequenceName(), true);
long curTime = System.currentTimeMillis(); long curTime = System.currentTimeMillis();
final double elapsed = (curTime - lastTime) / 1000.0; final double elapsed = (curTime - lastTime) / 1000.0;
timings.add(elapsed); timings.add(elapsed);
System.out.printf(" -> Elapsed time %.2f, averaging %.2f sec / seek for %d seeks%n", logger.info(String.format(" -> Elapsed time %.2f, averaging %.2f sec / seek for %d seeks%n",
elapsed, Utils.averageDouble(timings), timings.size()); elapsed, Utils.averageDouble(timings), timings.size()));
if ( ! success ) { if ( ! success ) {
System.out.printf("Failured to seek to %s from %s%n", targetContig.getSequenceName(), lastContig ); logger.error(String.format("Failured to seek to %s from %s%n", targetContig.getSequenceName(), lastContig ));
} }
//System.exit(1); //System.exit(1);
} }
@ -297,14 +297,14 @@ public class GenomeAnalysisTK extends CommandLineProgram {
int i = 0; int i = 0;
String prevNextContigName = null; String prevNextContigName = null;
System.out.printf("Walking reference sequence:%n"); logger.info(String.format("Walking reference sequence:%n"));
for ( SAMSequenceRecord refContig: refContigs ) { for ( SAMSequenceRecord refContig: refContigs ) {
long curTime = System.currentTimeMillis(); long curTime = System.currentTimeMillis();
ReferenceSequence contig = refFile.nextSequence(); ReferenceSequence contig = refFile.nextSequence();
final double elapsed = (curTime - lastTime) / 1000.0; final double elapsed = (curTime - lastTime) / 1000.0;
timings.add(elapsed); timings.add(elapsed);
System.out.printf("%2d : expected %s contig, found %s with next of %s after %.2f seconds, average is %.2f%n", i, logger.info(String.format("%2d : expected %s contig, found %s with next of %s after %.2f seconds, average is %.2f%n", i,
refContig.getSequenceName(), contig.getName(), refFile.getNextContigName(), elapsed, Utils.averageDouble(timings)); refContig.getSequenceName(), contig.getName(), refFile.getNextContigName(), elapsed, Utils.averageDouble(timings)));
if ( prevNextContigName != null && contig.getName() != null && ! prevNextContigName.equals(contig.getName()) ) if ( prevNextContigName != null && contig.getName() != null && ! prevNextContigName.equals(contig.getName()) )
throw new RuntimeIOException(String.format("Unexpected contig ordering %s was expected next, but I found %s?", throw new RuntimeIOException(String.format("Unexpected contig ordering %s was expected next, but I found %s?",
prevNextContigName, contig.getName())); prevNextContigName, contig.getName()));
@ -313,8 +313,8 @@ public class GenomeAnalysisTK extends CommandLineProgram {
lastTime = curTime; lastTime = curTime;
i++; i++;
System.out.printf(" Traversing from chr1 to %s would require jumping %d bytes%n", logger.info(String.format(" Traversing from chr1 to %s would require jumping %d bytes%n",
contig.getName(), refFile.getDistanceBetweenContigs("chr1", contig.getName())); contig.getName(), refFile.getDistanceBetweenContigs("chr1", contig.getName())));
} }
} }
} }

View File

@ -332,7 +332,7 @@ public class TraversalEngine {
*/ */
protected <T> void printOnTraversalDone(final String type, T sum) { protected <T> void printOnTraversalDone(final String type, T sum) {
printProgress(true, type, null); printProgress(true, type, null);
System.out.println("Traversal reduce result is " + sum); // TODO: fixme -- how do we use this logger? logger.info("Traversal reduce result is " + sum);
final long curTime = System.currentTimeMillis(); final long curTime = System.currentTimeMillis();
final double elapsed = (curTime - startTime) / 1000.0; final double elapsed = (curTime - startTime) / 1000.0;
logger.info(String.format("Total runtime %.2f secs, %.2f min, %.2f hours%n", elapsed, elapsed / 60, elapsed / 3600)); logger.info(String.format("Total runtime %.2f secs, %.2f min, %.2f hours%n", elapsed, elapsed / 60, elapsed / 3600));

View File

@ -23,6 +23,7 @@ import java.util.jar.JarInputStream;
import org.broadinstitute.sting.gatk.walkers.Walker; import org.broadinstitute.sting.gatk.walkers.Walker;
import org.broadinstitute.sting.gatk.walkers.WalkerName; import org.broadinstitute.sting.gatk.walkers.WalkerName;
import org.broadinstitute.sting.utils.cmdLine.Argument; import org.broadinstitute.sting.utils.cmdLine.Argument;
import org.apache.log4j.Logger;
/** /**
* Created by IntelliJ IDEA. * Created by IntelliJ IDEA.
@ -33,6 +34,11 @@ import org.broadinstitute.sting.utils.cmdLine.Argument;
*/ */
public class WalkerManager { public class WalkerManager {
/**
* our log, which we want to capture anything from this class
*/
private static Logger logger = Logger.getLogger(WalkerManager.class);
private Map<String, Class> walkers; private Map<String, Class> walkers;
public WalkerManager(String pluginDirectory) { public WalkerManager(String pluginDirectory) {
@ -46,7 +52,7 @@ public class WalkerManager {
// Load all classes that live in the extension path. // Load all classes that live in the extension path.
if (pluginDirectory == null) if (pluginDirectory == null)
pluginDirectory = location.getParent() + File.separator + "walkers"; pluginDirectory = location.getParent() + File.separator + "walkers";
System.out.println("plugin directory: " + pluginDirectory); logger.info("plugin directory: " + pluginDirectory);
File extensionPath = new File(pluginDirectory); File extensionPath = new File(pluginDirectory);
if (extensionPath.exists()) { if (extensionPath.exists()) {
@ -70,6 +76,7 @@ public class WalkerManager {
/** /**
* Does a walker with the given name exist? * Does a walker with the given name exist?
*
* @param walkerName Name of the walker for which to search. * @param walkerName Name of the walker for which to search.
* @return True if the walker exists, false otherwise. * @return True if the walker exists, false otherwise.
*/ */
@ -79,6 +86,7 @@ public class WalkerManager {
/** /**
* Gets a walker with the given name, or null if no walker exists. * Gets a walker with the given name, or null if no walker exists.
*
* @param walkerName Name of the walker to retrieve. * @param walkerName Name of the walker to retrieve.
* @return The walker object if found; null otherwise. * @return The walker object if found; null otherwise.
*/ */
@ -94,6 +102,7 @@ public class WalkerManager {
/** /**
* Determines which jar file contains the WalkerManager class. * Determines which jar file contains the WalkerManager class.
*
* @return Jar file containing the WalkerManager class. * @return Jar file containing the WalkerManager class.
*/ */
private File getThisLocation() throws IOException { private File getThisLocation() throws IOException {
@ -109,6 +118,7 @@ public class WalkerManager {
/** /**
* Load classes internal to the classpath from an arbitrary location. * Load classes internal to the classpath from an arbitrary location.
*
* @param location Location from which to load classes. * @param location Location from which to load classes.
* @return List of classes. * @return List of classes.
* @throws IOException Problem occurred reading classes. * @throws IOException Problem occurred reading classes.
@ -126,6 +136,7 @@ public class WalkerManager {
/** /**
* Loads concrete classes from a jar which are both in the same package or 'sub-package' of baseClass, * Loads concrete classes from a jar which are both in the same package or 'sub-package' of baseClass,
* and which extend from baseClass. * and which extend from baseClass.
*
* @param jarFile The jar file to search. * @param jarFile The jar file to search.
* @return A list of classes derived from baseClass. * @return A list of classes derived from baseClass.
*/ */
@ -140,8 +151,7 @@ public class WalkerManager {
while (jarEntry != null) { while (jarEntry != null) {
String jarEntryName = jarEntry.getName(); String jarEntryName = jarEntry.getName();
if(jarEntryName.endsWith(".class")) if (jarEntryName.endsWith(".class")) {
{
String className = fileNameToClassName(jarEntryName); String className = fileNameToClassName(jarEntryName);
subclasses.add(Class.forName(className)); subclasses.add(Class.forName(className));
} }
@ -161,6 +171,7 @@ public class WalkerManager {
/** /**
* Loads a list of classes currently on the classpath. * Loads a list of classes currently on the classpath.
*
* @param classFileNames List of files representing classes. * @param classFileNames List of files representing classes.
* @return class objects. * @return class objects.
* @throws IOException Unable to open any of the found classes. * @throws IOException Unable to open any of the found classes.
@ -185,6 +196,7 @@ public class WalkerManager {
/** /**
* Load loose classes, external to the classloader, from the specified directory. * Load loose classes, external to the classloader, from the specified directory.
*
* @param path source path from which to load classes. * @param path source path from which to load classes.
* @return A list of all loose classes contained in the path directory. * @return A list of all loose classes contained in the path directory.
*/ */
@ -213,6 +225,7 @@ public class WalkerManager {
/** /**
* Find the files in the given directory matching the given extension. * Find the files in the given directory matching the given extension.
*
* @param basePath Path to search. * @param basePath Path to search.
* @param relativePrefix What directory should the given files be presented relative to? * @param relativePrefix What directory should the given files be presented relative to?
* @param extension Extension for which to search. * @param extension Extension for which to search.
@ -241,6 +254,7 @@ public class WalkerManager {
/** /**
* Convert a filename of the form a/b/c.class to a.b.c. Makes no assurances about whether the * Convert a filename of the form a/b/c.class to a.b.c. Makes no assurances about whether the
* class is valid on any classloader. * class is valid on any classloader.
*
* @param fileName Filename to convert. * @param fileName Filename to convert.
* @return classname represented by that file. * @return classname represented by that file.
* TODO: Move to a utils class. * TODO: Move to a utils class.
@ -255,22 +269,38 @@ public class WalkerManager {
*/ */
private class ExtensionFilter implements FilenameFilter { private class ExtensionFilter implements FilenameFilter {
private String extensionName = null; private String extensionName = null;
public ExtensionFilter( String extensionName ) { this.extensionName = extensionName; }
public boolean accept( File f, String s ) { return s.endsWith("." + extensionName); } public ExtensionFilter(String extensionName) {
this.extensionName = extensionName;
}
public boolean accept(File f, String s) {
return s.endsWith("." + extensionName);
}
} }
private class DirectoryFilter implements FilenameFilter { private class DirectoryFilter implements FilenameFilter {
public boolean accept( File f, String s ) { return new File( f, s ).isDirectory(); } public boolean accept(File f, String s) {
return new File(f, s).isDirectory();
}
} }
private class OrFilenameFilter implements FilenameFilter { private class OrFilenameFilter implements FilenameFilter {
private FilenameFilter lhs = null, rhs = null; private FilenameFilter lhs = null, rhs = null;
public OrFilenameFilter( FilenameFilter lhs, FilenameFilter rhs ) { this.lhs = lhs; this.rhs = rhs; }
public boolean accept( File f, String s ) { return lhs.accept( f, s ) || rhs.accept( f, s ); } public OrFilenameFilter(FilenameFilter lhs, FilenameFilter rhs) {
this.lhs = lhs;
this.rhs = rhs;
}
public boolean accept(File f, String s) {
return lhs.accept(f, s) || rhs.accept(f, s);
}
} }
/** /**
* Given a list of classes, return a list of those classes which extend from the Walker base interface. * Given a list of classes, return a list of those classes which extend from the Walker base interface.
*
* @param classes Arbitrary list of classes. * @param classes Arbitrary list of classes.
* @return List of classes extending from Walker. * @return List of classes extending from Walker.
*/ */
@ -299,6 +329,7 @@ public class WalkerManager {
/** /**
* Instantiate the list of walker classes. Add them to the walker hashmap. * Instantiate the list of walker classes. Add them to the walker hashmap.
*
* @param walkerClasses Classes to instantiate. * @param walkerClasses Classes to instantiate.
* @return map of walker name to walker. * @return map of walker name to walker.
*/ */
@ -307,7 +338,7 @@ public class WalkerManager {
for (Class<Walker> walkerClass : walkerClasses) { for (Class<Walker> walkerClass : walkerClasses) {
String walkerName = getWalkerName(walkerClass); String walkerName = getWalkerName(walkerClass);
System.out.printf("* Adding module %s%n", walkerName); logger.info(String.format("* Adding module %s%n", walkerName));
walkers.put(walkerName, walkerClass); walkers.put(walkerName, walkerClass);
} }
@ -316,6 +347,7 @@ public class WalkerManager {
/** /**
* Create a name for this type of walker. * Create a name for this type of walker.
*
* @param walkerType The type of walker. * @param walkerType The type of walker.
* @return A name for this type of walker. * @return A name for this type of walker.
*/ */

View File

@ -13,12 +13,18 @@ import org.broadinstitute.sting.utils.RefHanger;
import org.broadinstitute.sting.gatk.iterators.PushbackIterator; import org.broadinstitute.sting.gatk.iterators.PushbackIterator;
import org.broadinstitute.sting.gatk.iterators.LocusIterator; import org.broadinstitute.sting.gatk.iterators.LocusIterator;
import org.broadinstitute.sting.gatk.LocusContext; import org.broadinstitute.sting.gatk.LocusContext;
import org.apache.log4j.Logger;
/** /**
* Iterator that traverses a SAM File, accumulating information on a per-locus basis * Iterator that traverses a SAM File, accumulating information on a per-locus basis
*/ */
public class LocusIteratorByHanger extends LocusIterator { public class LocusIteratorByHanger extends LocusIterator {
/**
* our log, which we want to capture anything from this class
*/
private static Logger logger = Logger.getLogger(LocusIteratorByHanger.class);
// ----------------------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------------------
// //
// member fields // member fields
@ -58,19 +64,19 @@ public class LocusIteratorByHanger extends LocusIterator {
RefHanger.Hanger rhanger = readHanger.getHanger(i); RefHanger.Hanger rhanger = readHanger.getHanger(i);
RefHanger.Hanger ohanger = offsetHanger.getHanger(i); RefHanger.Hanger ohanger = offsetHanger.getHanger(i);
System.out.printf(" -> %s:", rhanger.loc); logger.debug(String.format(" -> %s:", rhanger.loc));
for ( int j = 0; j < rhanger.size(); j++ ) { for ( int j = 0; j < rhanger.size(); j++ ) {
SAMRecord read = (SAMRecord)rhanger.get(j); SAMRecord read = (SAMRecord)rhanger.get(j);
int offset = (Integer)ohanger.get(j); int offset = (Integer)ohanger.get(j);
System.out.printf(" %s(%d)=%s", read.getReadName(), offset, read.getReadString().charAt(offset) ); logger.debug(String.format(" %s(%d)=%s", read.getReadName(), offset, read.getReadString().charAt(offset) ));
} }
System.out.printf("%n"); logger.debug(String.format("%n"));
} }
} }
public void clear() { public void clear() {
System.out.printf("clear() called%n"); logger.debug(String.format(("clear() called%n")));
readHanger.clear(); readHanger.clear();
offsetHanger.clear(); offsetHanger.clear();
} }
@ -96,7 +102,7 @@ public class LocusIteratorByHanger extends LocusIterator {
expandWindow(INCREMENT_SIZE); expandWindow(INCREMENT_SIZE);
if ( DEBUG ) { if ( DEBUG ) {
System.out.printf("in Next:%n"); logger.debug(String.format(("in Next:%n")));
printState(); printState();
} }
@ -120,13 +126,13 @@ public class LocusIteratorByHanger extends LocusIterator {
for ( AlignmentBlock block : read.getAlignmentBlocks() ) { for ( AlignmentBlock block : read.getAlignmentBlocks() ) {
if ( DEBUG ) if ( DEBUG )
System.out.printf("Processing block %s len=%d%n", block, block.getLength()); logger.debug(String.format("Processing block %s len=%d%n", block, block.getLength()));
for ( int i = 0; i < block.getLength(); i++ ) { for ( int i = 0; i < block.getLength(); i++ ) {
GenomeLoc offset = new GenomeLoc(readLoc.getContig(), block.getReferenceStart() + i); GenomeLoc offset = new GenomeLoc(readLoc.getContig(), block.getReferenceStart() + i);
readHanger.expandingPut(offset, read); readHanger.expandingPut(offset, read);
offsetHanger.expandingPut(offset, block.getReadStart() + i - 1); offsetHanger.expandingPut(offset, block.getReadStart() + i - 1);
if ( DEBUG ) if ( DEBUG )
System.out.printf(" # Added %s%n", offset); logger.debug(String.format(" # Added %s%n", offset));
} }
} }
} }
@ -158,13 +164,13 @@ public class LocusIteratorByHanger extends LocusIterator {
private final void expandWindow(final int incrementSize) { private final void expandWindow(final int incrementSize) {
if ( DEBUG ) { if ( DEBUG ) {
System.out.printf("entering expandWindow..., hasNext=%b%n", it.hasNext()); logger.debug(String.format("entering expandWindow..., hasNext=%b%n", it.hasNext()));
printState(); printState();
} }
while ( it.hasNext() ) { while ( it.hasNext() ) {
if ( DEBUG ) { if ( DEBUG ) {
System.out.printf("Expanding window%n"); logger.debug(String.format("Expanding window%n"));
printState(); printState();
} }
@ -173,12 +179,12 @@ public class LocusIteratorByHanger extends LocusIterator {
GenomeLoc readLoc = Utils.genomicLocationOf(read); GenomeLoc readLoc = Utils.genomicLocationOf(read);
if ( DEBUG ) { if ( DEBUG ) {
System.out.printf(" Expanding window sizes %d with %d : left=%s, right=%s, readLoc = %s, cmp=%d%n", logger.debug(String.format(" Expanding window sizes %d with %d : left=%s, right=%s, readLoc = %s, cmp=%d%n",
readHanger.size(), incrementSize, readHanger.size(), incrementSize,
readHanger.hasHangers() ? readHanger.getLeftLoc() : "NA", readHanger.hasHangers() ? readHanger.getLeftLoc() : "NA",
readHanger.hasHangers() ? readHanger.getRightLoc() : "NA", readHanger.hasHangers() ? readHanger.getRightLoc() : "NA",
readLoc, readLoc,
readHanger.hasHangers() ? readLoc.compareTo(readHanger.getLeftLoc()) : -100); readHanger.hasHangers() ? readLoc.compareTo(readHanger.getLeftLoc()) : -100));
} }
//if ( readHanger.size() >= incrementSize ) { //if ( readHanger.size() >= incrementSize ) {
//if ( readHanger.hasHangers() && readLoc.compareTo(readHanger.getLeftLoc()) == 1) { //if ( readHanger.hasHangers() && readLoc.compareTo(readHanger.getLeftLoc()) == 1) {

View File

@ -11,6 +11,7 @@ import java.io.IOException;
import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.GenomeLoc;
import org.broadinstitute.sting.utils.FastaSequenceFile2; import org.broadinstitute.sting.utils.FastaSequenceFile2;
import org.apache.log4j.Logger;
/** /**
* Created by IntelliJ IDEA. * Created by IntelliJ IDEA.
@ -34,7 +35,10 @@ public class ReferenceIterator implements Iterator<ReferenceIterator> {
public ReferenceIterator( FastaSequenceFile2 refFile ) { public ReferenceIterator( FastaSequenceFile2 refFile ) {
this.refFile = refFile; this.refFile = refFile;
} }
/**
* our log, which we want to capture anything from this class
*/
private static Logger logger = Logger.getLogger(ReferenceIterator.class);
// -------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------
// //
// Accessing data // Accessing data
@ -68,7 +72,7 @@ public class ReferenceIterator implements Iterator<ReferenceIterator> {
public ReferenceIterator next() { public ReferenceIterator next() {
if ( currentContig != null ) { if ( currentContig != null ) {
if ( DEBUG ) System.out.printf(" -> %s:%d %d%n", currentContig.getName(), offset, currentContig.length()); if ( DEBUG ) logger.debug(String.format(" -> %s:%d %d%n", currentContig.getName(), offset, currentContig.length()));
} }
offset++; // move on to the next position offset++; // move on to the next position
@ -139,7 +143,7 @@ public class ReferenceIterator implements Iterator<ReferenceIterator> {
if ( currentContig == null ) if ( currentContig == null )
next(); next();
if ( DEBUG ) System.out.printf(" -> Seeking to %s %d from %s %d%n", seekContigName, seekOffset, currentContig.getName(), offset); if ( DEBUG ) logger.debug(String.format(" -> Seeking to %s %d from %s %d%n", seekContigName, seekOffset, currentContig.getName(), offset));
int cmpContigs = GenomeLoc.compareContigs(seekContigName, currentContig.getName()); int cmpContigs = GenomeLoc.compareContigs(seekContigName, currentContig.getName());
@ -150,7 +154,7 @@ public class ReferenceIterator implements Iterator<ReferenceIterator> {
} }
else if ( cmpContigs == 1 ) { else if ( cmpContigs == 1 ) {
// we need to jump forward // we need to jump forward
if ( DEBUG ) System.out.printf(" -> Seeking in the fasta file to %s from %s%n", seekContigName, currentContig.getName()); if ( DEBUG ) logger.debug(String.format(" -> Seeking in the fasta file to %s from %s%n", seekContigName, currentContig.getName()));
if ( ! refFile.seekToContig(seekContigName) ) { // ok, do the seek if ( ! refFile.seekToContig(seekContigName) ) { // ok, do the seek
// a false result indicates a failure, throw a somewhat cryptic call // a false result indicates a failure, throw a somewhat cryptic call