From 5202d959bf53f3f8417a3c56430672b27d99e239 Mon Sep 17 00:00:00 2001 From: asivache Date: Thu, 3 Sep 2009 19:03:32 +0000 Subject: [PATCH] NM attribute changed in sam jdk (?) from Integer to Short, or maybe it is presented differently by the reader depending on whether SAM or BAM is processed; in any case, both Integer and Short are safe now git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1522 348d0f76-0448-11de-a6fe-93d51630548a --- .../playground/tools/RemapAlignments.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/java/src/org/broadinstitute/sting/playground/tools/RemapAlignments.java b/java/src/org/broadinstitute/sting/playground/tools/RemapAlignments.java index e4cbc7bff..9d20cf794 100644 --- a/java/src/org/broadinstitute/sting/playground/tools/RemapAlignments.java +++ b/java/src/org/broadinstitute/sting/playground/tools/RemapAlignments.java @@ -8,6 +8,7 @@ import java.util.Map.Entry; import org.broadinstitute.sting.playground.utils.GenomicMap; import org.broadinstitute.sting.utils.GenomeLocParser; +import org.broadinstitute.sting.utils.AlignmentUtils; import net.sf.picard.cmdline.CommandLineProgram; import net.sf.picard.cmdline.Option; @@ -126,7 +127,7 @@ public class RemapAlignments extends CommandLineProgram { badRecords++; continue; } - if ( read.getReadUnmappedFlag() ) totalUnmappedReads++; + if ( AlignmentUtils.isReadUnmapped(read) ) totalUnmappedReads++; else { // destroy mate pair mapping information, if any (we will need to reconstitute pairs after remapping both ends): read.setMateReferenceIndex(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX); @@ -218,7 +219,10 @@ public class RemapAlignments extends CommandLineProgram { if ( attr == null ) { return; // can not recompute qualities! } - int nm = (Integer)attr; + int nm; + if ( attr instanceof Short ) nm = ((Short)attr).intValue(); + else if ( attr instanceof Integer ) nm = ((Integer)attr).intValue(); + else throw new RuntimeException("NM attribute is neither Short nor Integer, don't know what to do."); if ( nm < minNM ) { minNM = nm; cnt = 1; @@ -230,12 +234,17 @@ public class RemapAlignments extends CommandLineProgram { int cnt2 = reads.size() - cnt; // count of inferior alignments - r.setAttribute("X0", new Integer(cnt)); + r.setAttribute("X0", new Integer(cnt)); r.setAttribute("X1", new Integer(cnt2)); if ( cnt2 > 255 ) cnt2 = 255; // otherwise we will be out of bounds in g_log_n - - if ( ((Integer)r.getAttribute("NM")).intValue() == minNM ) { + + int nm_attr; + Object attr = r.getAttribute("NM"); + if ( attr instanceof Short ) nm_attr = ((Short)attr).intValue(); + else if ( attr instanceof Integer ) nm_attr = ((Integer)attr).intValue(); + else throw new RuntimeException("NM attribute is neither Short nor Integer, don't know what to do."); + if ( nm_attr == minNM ) { // one of the best alignments: