Merge pull request #75 from broadinstitute/eb_missing_rg_error_GSA-407
Added better error message for BAMs with bad read groups.
This commit is contained in:
commit
92d6a4f441
|
|
@ -28,6 +28,7 @@ package org.broadinstitute.sting.gatk.filters;
|
|||
import net.sf.samtools.SAMFileHeader;
|
||||
import net.sf.samtools.SAMRecord;
|
||||
import net.sf.samtools.SAMSequenceRecord;
|
||||
import net.sf.samtools.SAMTagUtil;
|
||||
import org.broadinstitute.sting.commandline.Argument;
|
||||
import org.broadinstitute.sting.gatk.GenomeAnalysisEngine;
|
||||
import org.broadinstitute.sting.utils.exceptions.UserException;
|
||||
|
|
@ -59,9 +60,14 @@ public class MalformedReadFilter extends ReadFilter {
|
|||
!checkCigarDisagreesWithAlignment(read);
|
||||
}
|
||||
|
||||
private static boolean checkHasReadGroup(SAMRecord read) {
|
||||
if ( read.getReadGroup() == null )
|
||||
throw new UserException.ReadMissingReadGroup(read);
|
||||
private static boolean checkHasReadGroup(final SAMRecord read) {
|
||||
if ( read.getReadGroup() == null ) {
|
||||
// there are 2 possibilities: either the RG tag is missing or it is not defined in the header
|
||||
final String rgID = (String)read.getAttribute(SAMTagUtil.getSingleton().RG);
|
||||
if ( rgID == null )
|
||||
throw new UserException.ReadMissingReadGroup(read);
|
||||
throw new UserException.ReadHasUndefinedReadGroup(read, rgID);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -276,8 +276,14 @@ public class UserException extends ReviewedStingException {
|
|||
}
|
||||
|
||||
public static class ReadMissingReadGroup extends MalformedBAM {
|
||||
public ReadMissingReadGroup(SAMRecord read) {
|
||||
super(read, String.format("Read %s is either missing the read group or its read group is not defined in the BAM header, both of which are required by the GATK. Please use " + HelpConstants.forumPost("discussion/59/companion-utilities-replacereadgroups to fix this problem"), read.getReadName()));
|
||||
public ReadMissingReadGroup(final SAMRecord read) {
|
||||
super(read, String.format("Read %s is missing the read group (RG) tag, which is required by the GATK. Please use " + HelpConstants.forumPost("discussion/59/companion-utilities-replacereadgroups to fix this problem"), read.getReadName()));
|
||||
}
|
||||
}
|
||||
|
||||
public static class ReadHasUndefinedReadGroup extends MalformedBAM {
|
||||
public ReadHasUndefinedReadGroup(final SAMRecord read, final String rgID) {
|
||||
super(read, String.format("Read %s uses a read group (%s) that is not defined in the BAM header, which is not valid. Please use " + HelpConstants.forumPost("discussion/59/companion-utilities-replacereadgroups to fix this problem"), read.getReadName(), rgID));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2012 The Broad Institute
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.broadinstitute.sting.gatk.filters;
|
||||
|
||||
import org.broadinstitute.sting.WalkerTest;
|
||||
import org.broadinstitute.sting.utils.exceptions.UserException;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
||||
public class BadReadGroupsIntegrationTest extends WalkerTest {
|
||||
|
||||
@Test
|
||||
public void testMissingReadGroup() {
|
||||
WalkerTest.WalkerTestSpec spec = new WalkerTest.WalkerTestSpec(
|
||||
"-T PrintReads -R " + b36KGReference + " -I " + privateTestDir + "missingReadGroup.bam -o /dev/null",
|
||||
0,
|
||||
UserException.ReadMissingReadGroup.class);
|
||||
executeTest("test Missing Read Group", spec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUndefinedReadGroup() {
|
||||
WalkerTest.WalkerTestSpec spec = new WalkerTest.WalkerTestSpec(
|
||||
"-T PrintReads -R " + b36KGReference + " -I " + privateTestDir + "undefinedReadGroup.bam -o /dev/null",
|
||||
0,
|
||||
UserException.ReadHasUndefinedReadGroup.class);
|
||||
executeTest("test Undefined Read Group", spec);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue