From 230c1ad161c25c177b1fa9a4e08c4f0324278aac Mon Sep 17 00:00:00 2001 From: aaron Date: Fri, 27 Mar 2009 14:02:55 +0000 Subject: [PATCH] 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@211 348d0f76-0448-11de-a6fe-93d51630548a --- .../sting/utils/FastaSequenceFile2.java | 34 +-- .../sting/utils/FileProgressTracker.java | 32 ++- .../broadinstitute/sting/utils/RefHanger.java | 90 ++++--- .../org/broadinstitute/sting/utils/Utils.java | 236 +++++++++--------- 4 files changed, 220 insertions(+), 172 deletions(-) diff --git a/java/src/org/broadinstitute/sting/utils/FastaSequenceFile2.java b/java/src/org/broadinstitute/sting/utils/FastaSequenceFile2.java index 520a1ba25..7cea61732 100644 --- a/java/src/org/broadinstitute/sting/utils/FastaSequenceFile2.java +++ b/java/src/org/broadinstitute/sting/utils/FastaSequenceFile2.java @@ -14,6 +14,7 @@ import net.sf.samtools.SAMSequenceRecord; import net.sf.samtools.util.AsciiLineReader; import net.sf.samtools.util.StringUtil; import net.sf.samtools.util.RuntimeIOException; +import org.apache.log4j.Logger; /** * Implementation of ReferenceSequenceFile for reading from FASTA files. @@ -30,6 +31,11 @@ public class FastaSequenceFile2 implements ReferenceSequenceFile { private SAMSequenceDictionary sequenceDictionary = null; private String currentContigName = null; + /** + * our log, which we want to capture anything from this class + */ + private static Logger logger = Logger.getLogger(FastaSequenceFile2.class); + /** * Set to true to see lots of debugging output during operation */ @@ -129,9 +135,9 @@ public class FastaSequenceFile2 implements ReferenceSequenceFile { assert contig1Rec != null : "Contig2 record is null: " + contig2; if ( DEBUG ) - System.out.printf("Contig1=(%s, %d), contig2=(%s, %d)%n", + logger.debug(String.format("Contig1=(%s, %d), contig2=(%s, %d)%n", contig1, contig1Rec.getSequenceIndex(), - contig2, contig2Rec.getSequenceIndex()); + contig2, contig2Rec.getSequenceIndex())); int startIndex = Math.min(contig1Rec.getSequenceIndex(), contig2Rec.getSequenceIndex()); int lastIndex = Math.max(contig1Rec.getSequenceIndex(), contig2Rec.getSequenceIndex()); @@ -141,14 +147,14 @@ public class FastaSequenceFile2 implements ReferenceSequenceFile { SAMSequenceRecord rec = seqDict.getSequence(i); bytesToTraverse += rec.getSequenceLength(); if ( DEBUG ) - System.out.printf(" -> Traversing from %15s to %15s requires reading at least %10d bytes to pass contig %15s, total bytes %10d%n", - contig1, contig2, rec.getSequenceLength(), rec.getSequenceName(), bytesToTraverse); + logger.debug(String.format(" -> Traversing from %15s to %15s requires reading at least %10d bytes to pass contig %15s, total bytes %10d%n", + contig1, contig2, rec.getSequenceLength(), rec.getSequenceName(), bytesToTraverse)); } if ( contig1Rec.getSequenceIndex() > contig2Rec.getSequenceIndex() ) bytesToTraverse *= -1; // we are going backward! - if ( DEBUG ) System.out.printf(" -> total distance is %d%n", bytesToTraverse); + if ( DEBUG ) logger.debug(String.format(" -> total distance is %d%n", bytesToTraverse)); return bytesToTraverse; } @@ -180,13 +186,13 @@ public class FastaSequenceFile2 implements ReferenceSequenceFile { * @return true on success */ public boolean seekToContig(final String seekContig, boolean enableBacktracking ) { - if ( DEBUG ) System.out.printf("seekToContig( %s, %b )%n", seekContig, enableBacktracking); + if ( DEBUG ) logger.debug(String.format("seekToContig( %s, %b )%n", seekContig, enableBacktracking)); String curContig = getContigName(); String nextContig = null; if ( curContig == null ) { - System.out.printf("CurrentContig is null"); + logger.info(String.format("CurrentContig is null")); if ( this.sequenceDictionary == null ) throw new PicardException( String.format("Seeking within contigs requires FASTA dictionary, but none was available for %s", this.file )); @@ -217,7 +223,7 @@ public class FastaSequenceFile2 implements ReferenceSequenceFile { return false; // we're not going backwards just yet } else { - if ( DEBUG ) System.out.printf("Going to seek to contig %s with skip %d%n", seekContig, dist); + if ( DEBUG ) logger.debug(String.format("Going to seek to contig %s with skip %d%n", seekContig, dist)); // we're actually going to jump somewhere, so prepare the state this.nextContigName = null; // reset the contig info @@ -256,7 +262,7 @@ public class FastaSequenceFile2 implements ReferenceSequenceFile { * @return null if there are no more sequences in the fasta stream */ public ReferenceSequence nextSequence() { - if ( DEBUG ) System.out.printf("Calling nextSequence()%n"); + if ( DEBUG ) logger.debug(String.format("Calling nextSequence()%n")); // Read the header line currentContigName = getNextContigName(); @@ -309,8 +315,8 @@ public class FastaSequenceFile2 implements ReferenceSequenceFile { this.nextContigName = null; // we no longer know what the next contig name is - if ( DEBUG ) System.out.printf(" => nextSequence() is returning %s, known length = %d%n", this.currentContigName, knownLength); - if ( DEBUG ) System.out.printf(" => nextSequence() next is %s%n", this.getNextContigName()); + if ( DEBUG ) logger.debug(String.format(" => nextSequence() is returning %s, known length = %d%n", this.currentContigName, knownLength)); + if ( DEBUG ) logger.debug(String.format(" => nextSequence() next is %s%n", this.getNextContigName())); return new ReferenceSequence(currentContigName, index, bases); } @@ -326,7 +332,7 @@ public class FastaSequenceFile2 implements ReferenceSequenceFile { * @return the name of the next contig, or null if there is no next contig */ public String getNextContigName() { - if ( DEBUG ) System.out.printf("getNextContigName() => %s%n", this.nextContigName); + if ( DEBUG ) logger.debug(String.format("getNextContigName() => %s%n", this.nextContigName)); if ( this.nextContigName == null ) { // If it's not null, we've already looked up the next contig name, just return it and happily continue @@ -334,7 +340,7 @@ public class FastaSequenceFile2 implements ReferenceSequenceFile { this.nextContigName = readNextContigName(); } - if ( DEBUG ) System.out.printf("nextContigName is now %s%n", nextContigName); + if ( DEBUG ) logger.debug(String.format("nextContigName is now %s%n", nextContigName)); return this.nextContigName; } @@ -400,7 +406,7 @@ public class FastaSequenceFile2 implements ReferenceSequenceFile { if ( foundIndex == ourIndex ) { // we found our target! this.nextContigName = foundContig; // store the right answer - if ( DEBUG ) System.out.printf("seekForNextContig found %s%n", foundContig); + if ( DEBUG ) logger.debug(String.format("seekForNextContig found %s%n", foundContig)); return foundContig; } else if ( foundIndex <= ourIndex ) diff --git a/java/src/org/broadinstitute/sting/utils/FileProgressTracker.java b/java/src/org/broadinstitute/sting/utils/FileProgressTracker.java index 6b458d31b..e9291cd2a 100644 --- a/java/src/org/broadinstitute/sting/utils/FileProgressTracker.java +++ b/java/src/org/broadinstitute/sting/utils/FileProgressTracker.java @@ -1,5 +1,7 @@ package org.broadinstitute.sting.utils; +import org.apache.log4j.Logger; + import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -43,6 +45,12 @@ public class FileProgressTracker implements Iterator { this(file, it, channel, DEFAULT_HISTORY_SIZE); } + /** + * our log, which we want to capture anything from this class + */ + private static Logger logger = Logger.getLogger(FileProgressTracker.class); + + // ----------------------------------------------------------------- // // iterator support @@ -126,18 +134,18 @@ public class FileProgressTracker implements Iterator { } public void printStatus() { - System.out.printf("FileProgressTracker:%n"); - System.out.printf(" -> File size is: %d%n", getFileSize()); - System.out.printf(" -> Sampling depth: %d%n", historyI); - System.out.printf(" -> File position: %d%n", getPosition()); - System.out.printf(" -> Number of records processed: %d%n", nRecordsProcessed()); - System.out.printf(" -> Average record size is %d%n", averageRecordSize()); - System.out.printf(" -> Elapsed time in secs is %.2f%n", elapsedTimeInSecs()); - System.out.printf(" -> Processing rate (records per second) %.2f%n", processingRate()); - System.out.printf(" -> Estimated number of records in file %d%n", estRecordsInFile()); - System.out.printf(" -> Estimated percent progress through file %.2f%n", estFractionProgressThroughFile() * 100.0); - System.out.printf(" -> Estimated time for entire processing %.2f hrs / %.2f min / %.2f sec%n", estTimeTotal() / (60*60), estTimeTotal() / (60), estTimeTotal()); - System.out.printf(" -> Estimated time remaining %.2f hrs / %.2f min / %.2f sec%n", estTimeRemaining() / (60*60), estTimeRemaining() / 60, estTimeRemaining()); + logger.debug(String.format("FileProgressTracker:%n")); + logger.debug(String.format(" -> File size is: %d%n", getFileSize())); + logger.debug(String.format(" -> Sampling depth: %d%n", historyI)); + logger.debug(String.format(" -> File position: %d%n", getPosition())); + logger.debug(String.format(" -> Number of records processed: %d%n", nRecordsProcessed())); + logger.debug(String.format(" -> Average record size is %d%n", averageRecordSize())); + logger.debug(String.format(" -> Elapsed time in secs is %.2f%n", elapsedTimeInSecs())); + logger.debug(String.format(" -> Processing rate (records per second) %.2f%n", processingRate())); + logger.debug(String.format(" -> Estimated number of records in file %d%n", estRecordsInFile())); + logger.debug(String.format(" -> Estimated percent progress through file %.2f%n", estFractionProgressThroughFile() * 100.0)); + logger.debug(String.format(" -> Estimated time for entire processing %.2f hrs / %.2f min / %.2f sec%n", estTimeTotal() / (60*60), estTimeTotal() / (60), estTimeTotal())); + logger.debug(String.format(" -> Estimated time remaining %.2f hrs / %.2f min / %.2f sec%n", estTimeRemaining() / (60*60), estTimeRemaining() / 60, estTimeRemaining())); } public String progressMeter() { diff --git a/java/src/org/broadinstitute/sting/utils/RefHanger.java b/java/src/org/broadinstitute/sting/utils/RefHanger.java index f81050e1e..41c5f8439 100755 --- a/java/src/org/broadinstitute/sting/utils/RefHanger.java +++ b/java/src/org/broadinstitute/sting/utils/RefHanger.java @@ -1,6 +1,7 @@ package org.broadinstitute.sting.utils; import org.broadinstitute.sting.utils.GenomeLoc; +import org.apache.log4j.Logger; import java.util.List; import java.util.ArrayList; @@ -8,20 +9,20 @@ import java.util.Arrays; /** * Hanging data off the reference sequence - * + *

* Supports in effect the following data structure - * + *

* <-- reference bases: A T G C --> - * d d d d - * d d d d - * d d d d - * d d d - * d d - * d - * + * d d d d + * d d d d + * d d d d + * d d d + * d d + * d + *

* Where the little d's are data associated with each position in the reference. * Supports adding and removing data to either side of the data structure, as well as - * randomly accessing data anywhere within window. + * randomly accessing data anywhere within window. */ public class RefHanger { @@ -32,6 +33,11 @@ public class RefHanger { // ----------------------------------------------------------------------------------------------------------------- ArrayList hangers; + /** + * our log, which we want to capture anything from this class + */ + private static Logger logger = Logger.getLogger(RefHanger.class); + // ----------------------------------------------------------------------------------------------------------------- // // Info structure @@ -40,15 +46,23 @@ public class RefHanger { public class Hanger { public GenomeLoc loc = null; public ArrayList data = null; - + public Hanger(GenomeLoc loc, ArrayList data) { this.loc = loc; this.data = data; } - public final ArrayList getData() { return data; } - public final int size() { return this.data.size(); } - public final T get(int i) { return this.data.get(i); } + public final ArrayList getData() { + return data; + } + + public final int size() { + return this.data.size(); + } + + public final T get(int i) { + return this.data.get(i); + } } @@ -66,25 +80,37 @@ public class RefHanger { //System.out.printf("leftLoc is %s%n", getLeftLoc()); } - protected int getLeftOffset() { return 0; } - protected int getRightOffset() { return hangers.size() - 1; } + protected int getLeftOffset() { + return 0; + } + + protected int getRightOffset() { + return hangers.size() - 1; + } + protected int getOffset(GenomeLoc loc) { //System.out.printf("Loc: %s vs %s%n", loc, getLeftLoc()); return loc.minus(getLeftLoc()); } - - public GenomeLoc getLeftLoc() { return hangers.get(getLeftOffset()).loc; } - public GenomeLoc getRightLoc() { return hangers.get(getRightOffset()).loc; } + + public GenomeLoc getLeftLoc() { + return hangers.get(getLeftOffset()).loc; + } + + public GenomeLoc getRightLoc() { + return hangers.get(getRightOffset()).loc; + } public boolean hasLocation(GenomeLoc loc) { - return ! isEmpty() && loc.isBetween(getLeftLoc(), getRightLoc()); + return !isEmpty() && loc.isBetween(getLeftLoc(), getRightLoc()); } public boolean isEmpty() { return hangers.isEmpty(); } + public boolean hasHangers() { - return ! isEmpty(); + return !isEmpty(); } /** @@ -151,7 +177,7 @@ public class RefHanger { public void pushLeft(GenomeLoc pos, ArrayList data) { hangers.add(0, new Hanger(pos, data)); } - + public void pushRight(GenomeLoc pos) { pushRight(pos, new ArrayList()); } @@ -165,7 +191,7 @@ public class RefHanger { } public boolean ensurePos(GenomeLoc pos) { - if ( hasLocation(pos) ) + if (hasLocation(pos)) return true; else { pushRight(pos); @@ -178,9 +204,9 @@ public class RefHanger { } public void addData(List positions, List dataByPos) { - assert( positions.size() == dataByPos.size() ); + assert (positions.size() == dataByPos.size()); - for ( int i = 0; i < positions.size(); i++ ) { + for (int i = 0; i < positions.size(); i++) { GenomeLoc pos = positions.get(i); T datum = dataByPos.get(i); expandingPut1(pos, datum); @@ -193,15 +219,15 @@ public class RefHanger { } public void printState() { - System.out.printf("Hanger:%n"); - for ( Hanger hanger : hangers ) { - System.out.printf(" -> %s => %s:%n", hanger.loc, Utils.join("/", hanger.data) ); - } + logger.info("Hanger: "); + for (Hanger hanger : hangers) { + logger.info(String.format(" -> %s => %s:%n", hanger.loc, Utils.join("/", hanger.data))); + } } /** * Pushes locations on the right until we reach the expected position for pos. - * + *

* For example, if we have chr1:1 and 2 in the hanger, and we push 4 into the hangers * this function will add 3 -> {} to the hanger too * @@ -211,14 +237,14 @@ public class RefHanger { public void expandingPut(GenomeLoc pos, T datum) { //System.out.printf("expandingPut(%s, %s)%n", pos, datum); //printState(); - if ( isEmpty() ) + if (isEmpty()) // we have nothing, just push right pushRight(pos, datum); else { //assert pos.compareTo(getRightLoc()) == 1 : pos + " " + getRightLoc() + " => " + pos.compareTo(getRightLoc()); GenomeLoc nextRight = getRightLoc().nextLoc(); - while ( pos.compareTo(nextRight) == 1 ) { + while (pos.compareTo(nextRight) == 1) { //printState(); //System.out.printf(" *** Extending %s, heading for %s%n", nextRight, pos); ensurePos(nextRight); diff --git a/java/src/org/broadinstitute/sting/utils/Utils.java b/java/src/org/broadinstitute/sting/utils/Utils.java index 3551b6d88..40ab6a3b3 100755 --- a/java/src/org/broadinstitute/sting/utils/Utils.java +++ b/java/src/org/broadinstitute/sting/utils/Utils.java @@ -11,6 +11,8 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.BufferedReader; +import org.apache.log4j.Logger; + /** * Created by IntelliJ IDEA. * User: depristo @@ -19,28 +21,35 @@ import java.io.BufferedReader; * To change this template use File | Settings | File Templates. */ public class Utils { + /** + * our log, which we want to capture anything from this class + */ + private static Logger logger = Logger.getLogger(FileProgressTracker.class); + public static void warnUser(final String msg) { - System.out.printf("********************************************************************************%n"); - System.out.printf("* WARNING:%n"); - System.out.printf("*%n"); - System.out.printf("* %s%n", msg); - System.out.printf("********************************************************************************%n"); + logger.warn(String.format("********************************************************************************%n")); + logger.warn(String.format("* WARNING:%n")); + logger.warn(String.format("*%n")); + logger.warn(String.format("* %s%n", msg)); + logger.warn(String.format("********************************************************************************%n")); } public static void scareUser(final String msg) { - System.out.printf("********************************************************************************%n"); - System.out.printf("* ERROR:%n"); - System.out.printf("*%n"); - System.out.printf("* %s%n", msg); - System.out.printf("********************************************************************************%n"); + logger.fatal(String.format("********************************************************************************%n")); + logger.fatal(String.format("* ERROR:%n")); + logger.fatal(String.format("*%n")); + logger.fatal(String.format("* %s%n", msg)); + logger.fatal(String.format("********************************************************************************%n")); throw new RuntimeException(msg); } - /** Returns a new list built from those objects found in collection that satisfy the + /** + * Returns a new list built from those objects found in collection that satisfy the * predicate ( i.e. pred.apply() is true for the objects in th eresulting list ). - * @param pred filtering condition ( objects, for which pred.apply() is true pass the filter ) - * @param c collection to filter (will not be modified) - * @return new list built from elements of passing the filter + * + * @param pred filtering condition ( objects, for which pred.apply() is true pass the filter ) + * @param c collection to filter (will not be modified) + * @return new list built from elements of passing the filter * @see #filterInPlace(Predicate pred, Collection c) */ public static List filter(Predicate pred, Collection c) { @@ -56,7 +65,8 @@ public class Utils { return filtered; } - /** Removes from the collection all the elements that do not pass the filter (i.e. those elements, + /** + * Removes from the collection all the elements that do not pass the filter (i.e. those elements, * for which pred.apply() is false ). This is an in-place method - the argument is modified, and no new * objects are created/copied. Collection's iterator (as returned by iterator()) must implement * optional remove() interface method that allows multiple subsequent removals of elements from the @@ -67,27 +77,28 @@ public class Utils { * with other, custom lists that 1) do not inherit (are not instanceof) from ArrayList and 2) do not implement * fast (constant time) remove() operation, the performance can degrade significantly (linear traversal times, * e.g., linear removal ~ N^2). + * * @param pred filtering condition (only elements, for which pred.apply() is true will be kept in the collection) - * @param c collection to filter (will be modified - should be mutable and should implement remove() ) + * @param c collection to filter (will be modified - should be mutable and should implement remove() ) * @return reference to the same (modified) collection * @see #filter(Predicate pred, Collection c) */ public static Collection filterInPlace(Predicate pred, Collection c) { - if ( c instanceof ArrayList ) { + if (c instanceof ArrayList) { // arraylists are a special case that we know how to process efficiently // (generic implementation below removes one element at a time and is not well suited // for ArrayLists - List list = (List)c; + List list = (List) c; int j = 0; // copy-to location // perform one linear pass copying forward all elements that pass the filter, // so that the head of the list is continuous sequence of such elements: - for ( int i = 0 ; i < list.size() ; i++ ) { + for (int i = 0; i < list.size(); i++) { // if object passes, copy it forward and increment j (=copy-to location); // otherwise keep the same copy-to location and move on to the next element - if ( pred.apply(list.get(i)) ) list.set(j++,list.get(i)); + if (pred.apply(list.get(i))) list.set(j++, list.get(i)); } // j now points to first unused copy-to location; elements 0...j-1 pass the filter - list.subList(j,list.size()).clear(); // remove tail of the list + list.subList(j, list.size()).clear(); // remove tail of the list } /* // loop through all the elements in c @@ -100,8 +111,8 @@ public class Utils { } */ Iterator it = c.iterator(); - while ( it.hasNext() ) { - if ( pred.apply(it.next() )) continue; + while (it.hasNext()) { + if (pred.apply(it.next())) continue; it.remove(); } return c; @@ -110,10 +121,10 @@ public class Utils { public static ArrayList subseq(byte[] fullArray) { return subseq(fullArray, 0, fullArray.length); } - + public static ArrayList subseq(byte[] fullArray, int start, int end) { - ArrayList dest = new ArrayList(end-start+1); - for ( int i = start; i < end; i++ ) { + ArrayList dest = new ArrayList(end - start + 1); + for (int i = start; i < end; i++) { dest.add(fullArray[i]); } return dest; @@ -122,38 +133,38 @@ public class Utils { public static String baseList2string(List bases) { byte[] basesAsbytes = new byte[bases.size()]; int i = 0; - for ( Byte b : bases ) { + for (Byte b : bases) { basesAsbytes[i] = b; i++; } return new String(basesAsbytes); } - public static GenomeLoc genomicLocationOf( final SAMRecord read ) { - return new GenomeLoc( read.getReferenceName(), read.getAlignmentStart() ); + public static GenomeLoc genomicLocationOf(final SAMRecord read) { + return new GenomeLoc(read.getReferenceName(), read.getAlignmentStart()); } - private static final Map readFlagNames - = new HashMap(); + private static final Map readFlagNames + = new HashMap(); - static { - readFlagNames.put(0x1, "Paired"); - readFlagNames.put(0x2, "Proper"); - readFlagNames.put(0x4, "Unmapped"); - readFlagNames.put(0x8, "MateUnmapped"); - readFlagNames.put(0x10, "Forward"); - //readFlagNames.put(0x20, "MateForward"); - readFlagNames.put(0x4, "FirstOfPair"); - readFlagNames.put(0x8, "SecondOfPair"); - readFlagNames.put(0x100, "NotPrimary"); - readFlagNames.put(0x200, "NON-PF"); - readFlagNames.put(0x400, "Duplicate"); - } + static { + readFlagNames.put(0x1, "Paired"); + readFlagNames.put(0x2, "Proper"); + readFlagNames.put(0x4, "Unmapped"); + readFlagNames.put(0x8, "MateUnmapped"); + readFlagNames.put(0x10, "Forward"); + //readFlagNames.put(0x20, "MateForward"); + readFlagNames.put(0x4, "FirstOfPair"); + readFlagNames.put(0x8, "SecondOfPair"); + readFlagNames.put(0x100, "NotPrimary"); + readFlagNames.put(0x200, "NON-PF"); + readFlagNames.put(0x400, "Duplicate"); + } public static String readFlagsAsString(SAMRecord rec) { String flags = ""; - for ( int flag : readFlagNames.keySet() ) { - if ( ( rec.getFlags() & flag ) != 0 ) { + for (int flag : readFlagNames.keySet()) { + if ((rec.getFlags() & flag) != 0) { flags += readFlagNames.get(flag) + " "; } } @@ -178,17 +189,17 @@ public class Utils { public static String join(String separator, Collection objects) { ArrayList strs = new ArrayList(); - for ( Object x : objects ) + for (Object x : objects) strs.add(x.toString()); - return join( separator, strs.toArray(new String[0]) ); + return join(separator, strs.toArray(new String[0])); } public static double average(List vals, int maxI) { long sum = 0L; int i = 0; - for ( long x : vals ) { - if ( i > maxI ) + for (long x : vals) { + if (i > maxI) break; sum += x; i++; @@ -204,100 +215,105 @@ public class Utils { double sum = 0.0; int i = 0; - for ( double x : vals ) { - if ( i > maxI ) + for (double x : vals) { + if (i > maxI) break; sum += x; i++; } return (1.0 * sum) / i; } - - public static double average(List vals) { return average(vals, vals.size()); } - public static double averageDouble(List vals) { return averageDouble(vals, vals.size()); } + + public static double average(List vals) { + return average(vals, vals.size()); + } + + public static double averageDouble(List vals) { + return averageDouble(vals, vals.size()); + } public static boolean setupRefContigOrdering(final ReferenceSequenceFile refFile) { final SAMSequenceDictionary seqDict = refFile.getSequenceDictionary(); - if ( seqDict == null ) // we couldn't load the reference dictionary + if (seqDict == null) // we couldn't load the reference dictionary return false; - + List refContigs = seqDict.getSequences(); HashMap refContigOrdering = new HashMap(); - if ( refContigs != null ) { + if (refContigs != null) { int i = 0; - System.out.printf("Prepared reference sequence contig dictionary%n order ->"); - for ( SAMSequenceRecord contig : refContigs ) { - System.out.printf(" %s (%d bp)", contig.getSequenceName(), contig.getSequenceLength()); + logger.info(String.format("Prepared reference sequence contig dictionary%n order ->")); + for (SAMSequenceRecord contig : refContigs) { + logger.info(String.format(" %s (%d bp)", contig.getSequenceName(), contig.getSequenceLength())); refContigOrdering.put(contig.getSequenceName(), i); i++; } - System.out.printf("%n Total elements -> %d%n", refContigOrdering.size()); + logger.info(String.format("%n Total elements -> %d%n", refContigOrdering.size())); } - + GenomeLoc.setContigOrdering(refContigOrdering); return refContigs != null; } // Java Generics can't do primitive types, so I had to do this the simplistic way - - public static Integer[] SortPermutation(final int[] A) - { - class comparator implements Comparator - { - public int compare(Object a, Object b) - { - if (A[(Integer)a] < A[(Integer)b]) { return -1; } - if (A[(Integer)a] == A[(Integer)b]) { return 0; } - if (A[(Integer)a] > A[(Integer)b]) { return 1; } + + public static Integer[] SortPermutation(final int[] A) { + class comparator implements Comparator { + public int compare(Object a, Object b) { + if (A[(Integer) a] < A[(Integer) b]) { + return -1; + } + if (A[(Integer) a] == A[(Integer) b]) { + return 0; + } + if (A[(Integer) a] > A[(Integer) b]) { + return 1; + } return 0; - } + } } Integer[] permutation = new Integer[A.length]; - for (int i = 0; i < A.length; i++) - { + for (int i = 0; i < A.length; i++) { permutation[i] = i; } Arrays.sort(permutation, new comparator()); return permutation; } - public static Integer[] SortPermutation(final double[] A) - { - class comparator implements Comparator - { - public int compare(Object a, Object b) - { - if (A[(Integer)a] < A[(Integer)b]) { return -1; } - if (A[(Integer)a] == A[(Integer)b]) { return 0; } - if (A[(Integer)a] > A[(Integer)b]) { return 1; } + public static Integer[] SortPermutation(final double[] A) { + class comparator implements Comparator { + public int compare(Object a, Object b) { + if (A[(Integer) a] < A[(Integer) b]) { + return -1; + } + if (A[(Integer) a] == A[(Integer) b]) { + return 0; + } + if (A[(Integer) a] > A[(Integer) b]) { + return 1; + } return 0; - } + } } Integer[] permutation = new Integer[A.length]; - for (int i = 0; i < A.length; i++) - { + for (int i = 0; i < A.length; i++) { permutation[i] = i; } Arrays.sort(permutation, new comparator()); return permutation; } - public static Integer[] SortPermutation( List A ) - { + public static Integer[] SortPermutation(List A) { final Object[] data = A.toArray(); - class comparator implements Comparator - { - public int compare(Integer a, Integer b) - { - return ((T)data[a]).compareTo(data[b]); + class comparator implements Comparator { + public int compare(Integer a, Integer b) { + return ((T) data[a]).compareTo(data[b]); } } Integer[] permutation = new Integer[A.size()]; - for (int i = 0; i < A.size(); i++) - { + for (int i = 0; i < A.size(); i++) { permutation[i] = i; } Arrays.sort(permutation, new comparator()); @@ -305,41 +321,33 @@ public class Utils { } - public static int[] PermuteArray(int[] array, Integer[] permutation) - { + public static int[] PermuteArray(int[] array, Integer[] permutation) { int[] output = new int[array.length]; - for (int i = 0; i < output.length; i++) - { + for (int i = 0; i < output.length; i++) { output[i] = array[permutation[i]]; } return output; } - public static double[] PermuteArray(double[] array, Integer[] permutation) - { + public static double[] PermuteArray(double[] array, Integer[] permutation) { double[] output = new double[array.length]; - for (int i = 0; i < output.length; i++) - { + for (int i = 0; i < output.length; i++) { output[i] = array[permutation[i]]; } return output; } - public static Object[] PermuteArray(Object[] array, Integer[] permutation) - { + public static Object[] PermuteArray(Object[] array, Integer[] permutation) { Object[] output = new Object[array.length]; - for (int i = 0; i < output.length; i++) - { + for (int i = 0; i < output.length; i++) { output[i] = array[permutation[i]]; } return output; } - public static String[] PermuteArray(String[] array, Integer[] permutation) - { + public static String[] PermuteArray(String[] array, Integer[] permutation) { String[] output = new String[array.length]; - for (int i = 0; i < output.length; i++) - { + for (int i = 0; i < output.length; i++) { output[i] = array[permutation[i]]; } return output; @@ -379,7 +387,7 @@ public class Utils { } -*/ +*/ }