From 58debd7e566fe43606b6a21399ad347ce997bc40 Mon Sep 17 00:00:00 2001 From: asivache Date: Wed, 2 Sep 2009 17:00:39 +0000 Subject: [PATCH] A convenience shortcut isReadUnmapped() added: thanks to SAM format specification, 'read unmapped' flag is not always required to be set for an unmapped read; this method checks both the flag and the alignment reference index/start (if those are set to '*' the flag is not required according to the spec!) git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1506 348d0f76-0448-11de-a6fe-93d51630548a --- .../broadinstitute/sting/utils/AlignmentUtils.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/java/src/org/broadinstitute/sting/utils/AlignmentUtils.java b/java/src/org/broadinstitute/sting/utils/AlignmentUtils.java index dd4edf521..a9c3f289d 100644 --- a/java/src/org/broadinstitute/sting/utils/AlignmentUtils.java +++ b/java/src/org/broadinstitute/sting/utils/AlignmentUtils.java @@ -258,4 +258,18 @@ public class AlignmentUtils { refLine.append('\n'); return refLine.toString(); } + + /** + * Due to (unfortunate) multiple ways to indicate that read is unmapped allowed by SAM format + * specification, one may need this convenience shortcut. Checks both 'read unmapped' flag and + * alignment reference index/start. + * @param r + * @return + */ + public static boolean isReadUnmapped(final SAMRecord r) { + if ( r.getReadUnmappedFlag() ) return true; + if ( r.getReferenceIndex() == SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX || + r.getAlignmentStart() == SAMRecord.NO_ALIGNMENT_START ) return true; + return false; + } }