Java Code Examples for htsjdk.samtools.ValidationStringency#STRICT

The following examples show how to use htsjdk.samtools.ValidationStringency#STRICT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GTFParser.java    From Drop-seq with MIT License 6 votes vote down vote up
@Override
public GTFRecord next() {
    final TabbedTextFileWithHeaderParser.Row row = it.next();
    if (row.getFields().length != GTFColumnLabels.length) {
        throw new AnnotationException("Wrong number of fields in GTF file " + gtfFile + " at line " +
                row.getCurrentLine());
    }
    final GTFRecord ret = parseLine(row);
    if (validationStringency != ValidationStringency.SILENT) {
        final List<String> errors = ret.validate();
        if (errors != null && !errors.isEmpty()) {
            final String message = String.format(
                    "Invalid GTF line: \n%s\nProblems:\n%s",
                    row.getCurrentLine(),
                    CollectionUtil.join(errors, "\n"));
            if (validationStringency == ValidationStringency.STRICT) {
                throw new AnnotationException(message);
            } else {
                LOG.warn(message);
            }
        }
    }
    progressLogger.record(ret.getChromosome(), ret.getStart());
    return ret;
}
 
Example 2
Source File: PolyATrimmerTest.java    From Drop-seq with MIT License 6 votes vote down vote up
@Test(dataProvider = "testClpDataProvider")
public void testClp(final boolean newTrimmer) throws IOException {
    final File tempDir = Files.createTempDirectory("PolyATrimmerTest.").toFile();
    final Log.LogLevel saveLogLevel = Log.getGlobalLogLevel();
    Log.setGlobalLogLevel(Log.LogLevel.DEBUG);
    try {
        final PolyATrimmer clp = new PolyATrimmer();
        clp.INPUT = INPUT;
        clp.OUTPUT = File.createTempFile("PolyATrimmerTest.", ".sam");
        clp.OUTPUT.deleteOnExit();
        clp.OUTPUT_SUMMARY = File.createTempFile("PolyATrimmerTest.", ".summary");
        clp.OUTPUT_SUMMARY.deleteOnExit();
        clp.TMP_DIR = Arrays.asList(tempDir);
        tempDir.deleteOnExit();
        clp.MISMATCHES = 0;
        clp.NUM_BASES = 6;
        clp.VALIDATION_STRINGENCY = ValidationStringency.STRICT;
        clp.USE_NEW_TRIMMER = newTrimmer;
        Assert.assertEquals(clp.doWork(), 0);
        final File expectedResult = new File(TESTDATA_DIR, String.format("N701.%s_trimmer.sam", newTrimmer? "new": "old"));
        TestUtils.assertSamFilesSame(clp.OUTPUT, expectedResult);
    } finally {
        Log.setGlobalLogLevel(saveLogLevel);
        IOUtil.recursiveDelete(tempDir.toPath());
    }
}
 
Example 3
Source File: FingerprintChecker.java    From picard with MIT License 6 votes vote down vote up
private FingerprintIdDetails createUnknownFP(final Path samFile, final SAMRecord rec) {
    final PicardException e = new PicardException("Found read with no readgroup: " + rec.getReadName() + " in file: " + samFile);
    if (validationStringency != ValidationStringency.STRICT) {
        final SAMReadGroupRecord readGroupRecord = new SAMReadGroupRecord("<UNKNOWN>:::" + samFile.toUri().toString());
        readGroupRecord.setLibrary("<UNKNOWN>");
        readGroupRecord.setSample(defaultSampleID);
        readGroupRecord.setPlatformUnit("<UNKNOWN>.0.ZZZ");

        if (validationStringency != ValidationStringency.SILENT && missingRGFiles.add(samFile)) {
            log.warn(e.getMessage());
            log.warn("further messages from this file will be suppressed");
        }

        return new FingerprintIdDetails(readGroupRecord, samFile.toUri().toString());
    } else {
        log.error(e.getMessage());
        throw e;
    }
}
 
Example 4
Source File: IlluminaLaneMetricsCollectorTest.java    From picard with MIT License 6 votes vote down vote up
/** Ensures that an exception is thrown when we encounter a tile without phasing/pre-phasing metrics. */
@Test(expectedExceptions = PicardException.class)
public void testMissingPhasingValuesStrict() {
    final ReadStructure readStructure = new ReadStructure("151T8B8B151T");
    for (final boolean useReadStructure : Arrays.asList(true, false)) {
        final File runDirectory = TEST_MISSING_PHASING_DIRECTORY;
        final CollectIlluminaLaneMetrics clp = new CollectIlluminaLaneMetrics();
        clp.OUTPUT_DIRECTORY = IOUtil.createTempDir("illuminaLaneMetricsCollectorTest", null);
        clp.RUN_DIRECTORY = runDirectory;
        clp.OUTPUT_PREFIX = "test";
        clp.VALIDATION_STRINGENCY = ValidationStringency.STRICT;
        if (useReadStructure) clp.READ_STRUCTURE = readStructure;
        clp.doWork();

        final File phasingMetricsFile = buildOutputFile(clp.OUTPUT_DIRECTORY, clp.OUTPUT_PREFIX, IlluminaPhasingMetrics.getExtension());
        final File canonicalPhasingFile = buildOutputFile(runDirectory, runDirectory.getName(), IlluminaPhasingMetrics.getExtension());
        IOUtil.assertFilesEqual(canonicalPhasingFile, phasingMetricsFile);

        final File laneMetricsFile = buildOutputFile(clp.OUTPUT_DIRECTORY, clp.OUTPUT_PREFIX, IlluminaLaneMetrics.getExtension());
        final File canonicalLaneFile = buildOutputFile(runDirectory, runDirectory.getName(), IlluminaLaneMetrics.getExtension());
        IOUtil.assertFilesEqual(canonicalLaneFile, laneMetricsFile);
        IOUtil.deleteDirectoryTree(clp.OUTPUT_DIRECTORY);
    }
}
 
Example 5
Source File: EnhanceGTFRecordsTest.java    From Drop-seq with MIT License 5 votes vote down vote up
@Test(enabled=true, groups={"dropseq", "transcriptome"})
public void test1Enhanced() {
	EnhanceGTFRecords e = new EnhanceGTFRecords();
	GTFParser parser = new GTFParser(GTF_FILE1, ValidationStringency.STRICT);
       List<GTFRecord> records;
       try {
           records = e.enhanceGTFRecords(parser);
       } finally {
           CloserUtil.close(parser);
       }
       Assert.assertNotNull(records);
	
}
 
Example 6
Source File: EnhanceGTFRecordsTest.java    From Drop-seq with MIT License 5 votes vote down vote up
@Test(enabled=true, expectedExceptions=java.lang.IllegalStateException.class)
public void testGeneNoExon () {
	EnhanceGTFRecords e = new EnhanceGTFRecords();
	GTFParser parser = new GTFParser(GTF_FILE3, ValidationStringency.STRICT);
       List<GTFRecord> records;
       try {
           records = e.enhanceGTFRecords(parser);
       } finally {
           CloserUtil.close(parser);
       }
       Assert.assertNotNull(records);		
}
 
Example 7
Source File: BayesianHetPulldownCalculatorUnitTest.java    From gatk-protected with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@BeforeClass
public void initHetPulldownCalculator() {
    calculator = new BayesianHetPulldownCalculator(REF_FILE, IntervalList.fromFile(SNP_FILE),
            MINIMUM_MAPPING_QUALITY, MINIMUM_BASE_QUALITY, READ_DEPTH_THRESHOLD,
            ValidationStringency.STRICT, ERROR_PROBABILITY_ADJUSTMENT_FACTOR,
            new HeterogeneousHeterozygousPileupPriorModel(MIN_ABNORMAL_FRACTION, MAX_ABNORMAL_FRACTION,
                    MAX_COPY_NUMBER, QUADRATURE_ORDER));
}
 
Example 8
Source File: CleanSam.java    From picard with MIT License 5 votes vote down vote up
/**
 * Do the work after command line has been parsed.
 * RuntimeException may be thrown by this method, and are reported appropriately.
 *
 * @return program exit status.
 */
@Override
protected int doWork() {
    IOUtil.assertFileIsReadable(INPUT);
    IOUtil.assertFileIsWritable(OUTPUT);
    final SamReaderFactory factory = SamReaderFactory.makeDefault().referenceSequence(REFERENCE_SEQUENCE);
    if (VALIDATION_STRINGENCY == ValidationStringency.STRICT) {
        factory.validationStringency(ValidationStringency.LENIENT);
    }
    final SamReader reader = factory.open(INPUT);
    final SAMFileWriter writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(reader.getFileHeader(), true, OUTPUT);
    final CloseableIterator<SAMRecord> it = reader.iterator();
    final ProgressLogger progress = new ProgressLogger(Log.getInstance(CleanSam.class));

    // If the read (or its mate) maps off the end of the alignment, clip it
    while (it.hasNext()) {
        final SAMRecord rec = it.next();

        // If the read (or its mate) maps off the end of the alignment, clip it
        AbstractAlignmentMerger.createNewCigarsIfMapsOffEndOfReference(rec);

        // check the read's mapping quality
        if (rec.getReadUnmappedFlag() && 0 != rec.getMappingQuality()) {
            rec.setMappingQuality(0);
        }

        writer.addAlignment(rec);
        progress.record(rec);
    }

    writer.close();
    it.close();
    CloserUtil.close(reader);
    return 0;
}
 
Example 9
Source File: GTFReader.java    From Drop-seq with MIT License 4 votes vote down vote up
private FilteringGTFParser(final File gtf) {
    super(new GTFParser(gtf, ValidationStringency.STRICT));
}
 
Example 10
Source File: ReduceGtf.java    From Drop-seq with MIT License 4 votes vote down vote up
private FilteringGTFParser(final File gtf) {
    super(new GTFParser(gtf, ValidationStringency.STRICT));
}
 
Example 11
Source File: TileMetricsUtil.java    From picard with MIT License 4 votes vote down vote up
/**
 * Pulls out the phasing & prephasing value for the template reads and returns a collection of TilePhasingValues representing these
 */
private static Collection<TilePhasingValue> getTilePhasingValues(final Map<Integer, ? extends Collection<IlluminaTileMetrics>> codeMetricsMap, final ReadStructure readStructure, final ValidationStringency validationStringency) {
    boolean isFirstRead = true;
    final Collection<TilePhasingValue> tilePhasingValues = new ArrayList<>();
    for (int descriptorIndex = 0; descriptorIndex < readStructure.descriptors.size(); descriptorIndex++) {
        if (readStructure.descriptors.get(descriptorIndex).type == ReadType.Template) {
            final TileTemplateRead tileTemplateRead = isFirstRead ? TileTemplateRead.FIRST : TileTemplateRead.SECOND;
            // For both phasing & prephasing, pull out the value and create a TilePhasingValue for further processing
            final int phasingCode = IlluminaMetricsCode.getPhasingCode(descriptorIndex, IlluminaMetricsCode.PHASING_BASE);
            final int prePhasingCode = IlluminaMetricsCode.getPhasingCode(descriptorIndex, IlluminaMetricsCode.PREPHASING_BASE);

            final float phasingValue, prePhasingValue;

            // If both the phasing and pre-phasing data are missing, then likely something went wrong when imaging
            // this tile, for example a grain of sand disrupting the path of light to the sensor.  If only one of them
            // is missing, then likely the data is corrupt.
            if (codeMetricsMap.containsKey(phasingCode) && codeMetricsMap.containsKey(prePhasingCode)) {
                phasingValue = CollectionUtil.getSoleElement(codeMetricsMap.get(phasingCode)).getMetricValue();
                prePhasingValue = CollectionUtil.getSoleElement(codeMetricsMap.get(prePhasingCode)).getMetricValue();
            } else {
                final String message = String.format(
                        "Don't have both phasing and prephasing values for %s read cycle %s.  Phasing code was %d and prephasing code was %d.",
                        tileTemplateRead.toString(), descriptorIndex + 1, phasingCode, prePhasingCode
                );
                if (!codeMetricsMap.containsKey(phasingCode) && !codeMetricsMap.containsKey(prePhasingCode) && validationStringency != ValidationStringency.STRICT) {
                    // Ignore the error, and use the default (zero) for the phasing values
                    if (validationStringency == ValidationStringency.LENIENT) {
                        LOG.warn(message);
                    }
                } else {
                    throw new PicardException(message);
                }
                phasingValue = 0;
                prePhasingValue = 0;
            }

            tilePhasingValues.add(new TilePhasingValue(tileTemplateRead, phasingValue, prePhasingValue));
            isFirstRead = false;
        }
    }

    return tilePhasingValues;
}
 
Example 12
Source File: VCFRecordReader.java    From Hadoop-BAM with MIT License 4 votes vote down vote up
static ValidationStringency getValidationStringency(
	final Configuration conf)
{
	final String p = conf.get(VALIDATION_STRINGENCY_PROPERTY);
	return p == null ? ValidationStringency.STRICT : ValidationStringency.valueOf(p);
}
 
Example 13
Source File: VCFRecordReader.java    From Hadoop-BAM with MIT License 4 votes vote down vote up
@Override public boolean nextKeyValue() throws IOException {
	while (true) {
		String line;
		while (true) {
			if (!lineRecordReader.nextKeyValue()) {
				return false;
			}
			line = lineRecordReader.getCurrentValue().toString();
			if (!line.startsWith("#")) {
				break;
			}
		}

                       final VariantContext v;
                       try {
			v = codec.decode(line);
		} catch (TribbleException e) {
			if (stringency == ValidationStringency.STRICT) {
				if (logger.isErrorEnabled()) {
					logger.error("Parsing line {} failed with {}.", line, e);
				}
				throw e;
			} else {
				if (stringency == ValidationStringency.LENIENT &&
                                           logger.isWarnEnabled()) {
					logger.warn("Parsing line {} failed with {}. Skipping...",
                                                           line, e);
				}
				continue;
			}
		}

		if (!overlaps(v)) {
			continue;
		}

		Integer chromIdx = contigDict.get(v.getContig());
		if (chromIdx == null)
			chromIdx = (int) MurmurHash3.murmurhash3(v.getContig(), 0);

		key.set((long) chromIdx << 32 | (long) (v.getStart() - 1));
		vc.set(v, header);

		return true;
	}
}
 
Example 14
Source File: ValidateCramFile.java    From cramtools with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws IOException, IllegalArgumentException, IllegalAccessException {
	Params params = new Params();
	JCommander jc = new JCommander(params);
	try {
		jc.parse(args);
	} catch (Exception e) {
		System.out.println("Failed to parse parameteres, detailed message below: ");
		System.out.println(e.getMessage());
		System.out.println();
		System.out.println("See usage: -h");
		System.exit(1);
	}

	if (args.length == 0 || params.help) {
		printUsage(jc);
		System.exit(1);
	}

	if (params.reference == null) {
		System.out.println("A reference fasta file is required.");
		System.exit(1);
	}

	if (params.cramFile == null) {
		System.out.println("A CRAM input file is required. ");
		System.exit(1);
	}

	Log.setGlobalLogLevel(Log.LogLevel.INFO);

	ReferenceSequenceFile referenceSequenceFile = ReferenceSequenceFileFactory
			.getReferenceSequenceFile(params.reference);

	FileInputStream fis = new FileInputStream(params.cramFile);
	BufferedInputStream bis = new BufferedInputStream(fis);

	CRAMIterator iterator = new CRAMIterator(bis, new ReferenceSource(params.reference),
			ValidationStringency.STRICT);
	CramHeader cramHeader = iterator.getCramHeader();

	iterator.close();

	ProgressLogger progress = new ProgressLogger(log, 100000, "Validated Read");
	SamFileValidator v = new SamFileValidator(new PrintWriter(System.out), 1);
	final SamReader reader = SamReaderFactory.make().referenceSequence(params.reference).open(params.cramFile);
	List<SAMValidationError.Type> errors = new ArrayList<SAMValidationError.Type>();
	errors.add(SAMValidationError.Type.MATE_NOT_FOUND);
	// errors.add(Type.MISSING_TAG_NM);
	v.setErrorsToIgnore(errors);
	v.validateSamFileSummary(reader, ReferenceSequenceFileFactory.getReferenceSequenceFile(params.reference));
	log.info("Elapsed seconds: " + progress.getElapsedSeconds());
}