From a17d725c35b1440d48e37759b3767d94adb33001 Mon Sep 17 00:00:00 2001 From: asivache Date: Wed, 6 Jan 2010 18:05:00 +0000 Subject: [PATCH] Cache pileup bases and mapping quals after first call to getBases() and getMappingQuals(), respectively. Subsequent calls to these method will return cached arrays. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2525 348d0f76-0448-11de-a6fe-93d51630548a --- .../sting/utils/pileup/ReadBackedPileup.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/java/src/org/broadinstitute/sting/utils/pileup/ReadBackedPileup.java b/java/src/org/broadinstitute/sting/utils/pileup/ReadBackedPileup.java index c8b2688c1..9f293a93b 100755 --- a/java/src/org/broadinstitute/sting/utils/pileup/ReadBackedPileup.java +++ b/java/src/org/broadinstitute/sting/utils/pileup/ReadBackedPileup.java @@ -20,7 +20,9 @@ import net.sf.samtools.SAMRecord; public class ReadBackedPileup implements Iterable { private GenomeLoc loc = null; private ArrayList pileup = null; - + byte [] bases = null; // will be used to cache pileup bases after first call to getBases + byte [] mapquals = null; // will be used to cache pileup mapping quals after first call to getMappingQuals + private int size = 0; // cached value of the size of the pileup private int nDeletions = 0; // cached value of the number of deletions private int nMQ0Reads = 0; // cached value of the number of MQ0 reads @@ -395,9 +397,11 @@ public class ReadBackedPileup implements Iterable { * @return */ public byte[] getBases() { - byte[] v = new byte[size()]; - for ( ExtendedPileupElement pile : this.extendedForeachIterator() ) { v[pile.getPileupOffset()] = pile.getBase(); } - return v; + if ( bases == null ) { + bases = new byte[size()]; + for ( ExtendedPileupElement pile : this.extendedForeachIterator() ) { bases[pile.getPileupOffset()] = pile.getBase(); } + } + return bases; } /** @@ -425,9 +429,11 @@ public class ReadBackedPileup implements Iterable { * @return */ public byte[] getMappingQuals() { - byte[] v = new byte[size()]; - for ( ExtendedPileupElement pile : this.extendedForeachIterator() ) { v[pile.getPileupOffset()] = (byte)pile.getRead().getMappingQuality(); } - return v; + if ( mapquals == null ) { + mapquals = new byte[size()]; + for ( ExtendedPileupElement pile : this.extendedForeachIterator() ) { mapquals[pile.getPileupOffset()] = (byte)pile.getRead().getMappingQuality(); } + } + return mapquals; }