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();
for ( SAMSequenceRecord targetContig : refFile.getSequenceDictionary().getSequences() ) {
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();
final boolean success = refFile.seekToContig(targetContig.getSequenceName(), true);
long curTime = System.currentTimeMillis();
final double elapsed = (curTime - lastTime) / 1000.0;
timings.add(elapsed);
System.out.printf(" -> Elapsed time %.2f, averaging %.2f sec / seek for %d seeks%n",
elapsed, Utils.averageDouble(timings), timings.size());
logger.info(String.format(" -> Elapsed time %.2f, averaging %.2f sec / seek for %d seeks%n",
elapsed, Utils.averageDouble(timings), timings.size()));
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);
}
@ -297,14 +297,14 @@ public class GenomeAnalysisTK extends CommandLineProgram {
int i = 0;
String prevNextContigName = null;
System.out.printf("Walking reference sequence:%n");
logger.info(String.format("Walking reference sequence:%n"));
for ( SAMSequenceRecord refContig: refContigs ) {
long curTime = System.currentTimeMillis();
ReferenceSequence contig = refFile.nextSequence();
final double elapsed = (curTime - lastTime) / 1000.0;
timings.add(elapsed);
System.out.printf("%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));
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)));
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?",
prevNextContigName, contig.getName()));
@ -313,8 +313,8 @@ public class GenomeAnalysisTK extends CommandLineProgram {
lastTime = curTime;
i++;
System.out.printf(" Traversing from chr1 to %s would require jumping %d bytes%n",
contig.getName(), refFile.getDistanceBetweenContigs("chr1", contig.getName()));
logger.info(String.format(" Traversing from chr1 to %s would require jumping %d bytes%n",
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) {
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 double elapsed = (curTime - startTime) / 1000.0;
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.WalkerName;
import org.broadinstitute.sting.utils.cmdLine.Argument;
import org.apache.log4j.Logger;
/**
* Created by IntelliJ IDEA.
@ -33,6 +34,11 @@ import org.broadinstitute.sting.utils.cmdLine.Argument;
*/
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;
public WalkerManager(String pluginDirectory) {
@ -46,7 +52,7 @@ public class WalkerManager {
// Load all classes that live in the extension path.
if (pluginDirectory == null)
pluginDirectory = location.getParent() + File.separator + "walkers";
System.out.println("plugin directory: " + pluginDirectory);
logger.info("plugin directory: " + pluginDirectory);
File extensionPath = new File(pluginDirectory);
if (extensionPath.exists()) {
@ -70,6 +76,7 @@ public class WalkerManager {
/**
* Does a walker with the given name exist?
*
* @param walkerName Name of the walker for which to search.
* @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.
*
* @param walkerName Name of the walker to retrieve.
* @return The walker object if found; null otherwise.
*/
@ -94,6 +102,7 @@ public class WalkerManager {
/**
* Determines which jar file contains the WalkerManager class.
*
* @return Jar file containing the WalkerManager class.
*/
private File getThisLocation() throws IOException {
@ -109,6 +118,7 @@ public class WalkerManager {
/**
* Load classes internal to the classpath from an arbitrary location.
*
* @param location Location from which to load classes.
* @return List of 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,
* and which extend from baseClass.
*
* @param jarFile The jar file to search.
* @return A list of classes derived from baseClass.
*/
@ -140,8 +151,7 @@ public class WalkerManager {
while (jarEntry != null) {
String jarEntryName = jarEntry.getName();
if(jarEntryName.endsWith(".class"))
{
if (jarEntryName.endsWith(".class")) {
String className = fileNameToClassName(jarEntryName);
subclasses.add(Class.forName(className));
}
@ -161,6 +171,7 @@ public class WalkerManager {
/**
* Loads a list of classes currently on the classpath.
*
* @param classFileNames List of files representing classes.
* @return class objects.
* @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.
*
* @param path source path from which to load classes.
* @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.
*
* @param basePath Path to search.
* @param relativePrefix What directory should the given files be presented relative to?
* @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
* class is valid on any classloader.
*
* @param fileName Filename to convert.
* @return classname represented by that file.
* TODO: Move to a utils class.
@ -255,22 +269,38 @@ public class WalkerManager {
*/
private class ExtensionFilter implements FilenameFilter {
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 {
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 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.
*
* @param classes Arbitrary list of classes.
* @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.
*
* @param walkerClasses Classes to instantiate.
* @return map of walker name to walker.
*/
@ -307,7 +338,7 @@ public class WalkerManager {
for (Class<Walker> walkerClass : walkerClasses) {
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);
}
@ -316,6 +347,7 @@ public class WalkerManager {
/**
* Create a name for this type of walker.
*
* @param walkerType The 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.LocusIterator;
import org.broadinstitute.sting.gatk.LocusContext;
import org.apache.log4j.Logger;
/**
* Iterator that traverses a SAM File, accumulating information on a per-locus basis
*/
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
@ -58,19 +64,19 @@ public class LocusIteratorByHanger extends LocusIterator {
RefHanger.Hanger rhanger = readHanger.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++ ) {
SAMRecord read = (SAMRecord)rhanger.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() {
System.out.printf("clear() called%n");
logger.debug(String.format(("clear() called%n")));
readHanger.clear();
offsetHanger.clear();
}
@ -96,7 +102,7 @@ public class LocusIteratorByHanger extends LocusIterator {
expandWindow(INCREMENT_SIZE);
if ( DEBUG ) {
System.out.printf("in Next:%n");
logger.debug(String.format(("in Next:%n")));
printState();
}
@ -120,13 +126,13 @@ public class LocusIteratorByHanger extends LocusIterator {
for ( AlignmentBlock block : read.getAlignmentBlocks() ) {
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++ ) {
GenomeLoc offset = new GenomeLoc(readLoc.getContig(), block.getReferenceStart() + i);
readHanger.expandingPut(offset, read);
offsetHanger.expandingPut(offset, block.getReadStart() + i - 1);
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) {
if ( DEBUG ) {
System.out.printf("entering expandWindow..., hasNext=%b%n", it.hasNext());
logger.debug(String.format("entering expandWindow..., hasNext=%b%n", it.hasNext()));
printState();
}
while ( it.hasNext() ) {
if ( DEBUG ) {
System.out.printf("Expanding window%n");
logger.debug(String.format("Expanding window%n"));
printState();
}
@ -173,12 +179,12 @@ public class LocusIteratorByHanger extends LocusIterator {
GenomeLoc readLoc = Utils.genomicLocationOf(read);
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.hasHangers() ? readHanger.getLeftLoc() : "NA",
readHanger.hasHangers() ? readHanger.getRightLoc() : "NA",
readLoc,
readHanger.hasHangers() ? readLoc.compareTo(readHanger.getLeftLoc()) : -100);
readHanger.hasHangers() ? readLoc.compareTo(readHanger.getLeftLoc()) : -100));
}
//if ( readHanger.size() >= incrementSize ) {
//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.FastaSequenceFile2;
import org.apache.log4j.Logger;
/**
* Created by IntelliJ IDEA.
@ -34,7 +35,10 @@ public class ReferenceIterator implements Iterator<ReferenceIterator> {
public ReferenceIterator( FastaSequenceFile2 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
@ -68,7 +72,7 @@ public class ReferenceIterator implements Iterator<ReferenceIterator> {
public ReferenceIterator next() {
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
@ -139,7 +143,7 @@ public class ReferenceIterator implements Iterator<ReferenceIterator> {
if ( currentContig == null )
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());
@ -150,7 +154,7 @@ public class ReferenceIterator implements Iterator<ReferenceIterator> {
}
else if ( cmpContigs == 1 ) {
// 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
// a false result indicates a failure, throw a somewhat cryptic call