Java Code Examples for htsjdk.samtools.SAMRecord#getHeader()

The following examples show how to use htsjdk.samtools.SAMRecord#getHeader() . 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: CRAMRecordWriter.java    From Hadoop-BAM with MIT License 5 votes vote down vote up
protected void writeAlignment(final SAMRecord rec) {
    if (null == cramContainerStream) {
        final SAMFileHeader header = rec.getHeader();
        if (header == null) {
            throw new RuntimeException("Cannot write record to CRAM: null header in SAM record");
        }
        if (writeHeader) {
            this.writeHeader(header);
        }
        cramContainerStream = new CRAMContainerStreamWriter(
                origOutput, null, refSource, header, HADOOP_BAM_PART_ID);
    }
    cramContainerStream.writeAlignment(rec);
}
 
Example 2
Source File: TestQualityScorePreservation.java    From cramtools with Apache License 2.0 5 votes vote down vote up
@Ignore("Broken test.")
@Test
public void test3() {
	String line1 = "98573 1107 20 1 60 100M = 999587 -415 CTGGTCTTAGTTCCGCAAGTGGGTATATATAAAGGCTCAAAATCAATCTTTATATTGACATCTCTCTACTTATTTGTGTTGTCTGATGCTCATATTGTAG ::A<<=D@BBC;C9=7DEEBHDEHHACEEBEEEDEE=EFFHEEFFFEHEF@HFBCEFEHFEHEHFEHDHHHFHHHEHHHHDFHHHHHGHHHHHHHHHHHH";
	String line2 = "98738 1187 20 18 29 99M1S = 1000253 432 AGCGGGGATATATAAAGGCTCAAAATTACTTTTTATATGGACAACTCTCTACTGCTTTGAGATGACTGATACTCATATTGATGGAGCTTTATCAAGAAAT !\"#$%&'()*+-./0'''''''''''#'#'#'''''''#''''#'''''''''##''''#'#''#'''''#'''''''''##''''#''##''''''''?";
	String seqName = "20";
	List<String> lines = Arrays.asList(new String[] { line2, line1 });

	byte[] ref = "CTGGTCTTAGTTCCGCAAGTGGGTATATATAAAGGCTCAAAATCAATCTTTATATTGACATCTCTCTACTTATTTGTGTTGTCTGATGCTCATATTGTAGGAGATTCCTCAAGAAAGG"
			.getBytes();
	ReferenceTracks tracks = new ReferenceTracks(0, seqName, ref);
	QualityScorePreservation p = new QualityScorePreservation("R8-N40-M40-D40");

	for (String line : lines) {
		SAMRecord record = buildSAMRecord(seqName, line);

		Sam2CramRecordFactory f = new Sam2CramRecordFactory(ref, record.getHeader(), CramVersions.CRAM_v3);
		CramCompressionRecord cramRecord = f.createCramRecord(record);

		p.addQualityScores(record, cramRecord, tracks);
		if (!cramRecord.isForcePreserveQualityScores()) {
			CramNormalizer.restoreQualityScores((byte) 30, Collections.singletonList(cramRecord));
		}

		StringBuffer sb = new StringBuffer();
		sb.append(record.getBaseQualityString());
		sb.append("\n");
		sb.append(SAMUtils.phredToFastq(cramRecord.qualityScores));

		assertArrayEquals(sb.toString(), record.getBaseQualities(), cramRecord.qualityScores);
	}
}
 
Example 3
Source File: TestQualityScorePreservation.java    From cramtools with Apache License 2.0 5 votes vote down vote up
@Ignore("Broken test.")
@Test
public void test4() {
	String line2 = "98738 1187 20 18 29 99M1S = 1000253 432 AGCGGGGATATATAAAGGCTCAAAATTACTTTTTATATGGACAACTCTCTACTGCTTTGAGATGACTGATACTCATATTGATGGAGCTTTATCAAGAAAT !\"#$%&'()*+-./0'''''''''''#'#'#'''''''#''''#'''''''''##''''#'#''#'''''#'''''''''##''''#''##''''''''?";
	String seqName = "20";
	List<String> lines = Arrays.asList(new String[] { line2 });

	byte[] ref = "CTGGTCTTAGTTCCGCAAGTGGGTATATATAAAGGCTCAAAATCAATCTTTATATTGACATCTCTCTACTTATTTGTGTTGTCTGATGCTCATATTGTAGGAGATTCCTCAAGAAAGG"
			.getBytes();
	ReferenceTracks tracks = new ReferenceTracks(0, seqName, ref);
	QualityScorePreservation p = new QualityScorePreservation("R40X10-N40-U40");
	for (int i = 0; i < ref.length; i++)
		tracks.addCoverage(i + 1, 66);

	for (String line : lines) {
		SAMRecord record = buildSAMRecord(seqName, line);

		Sam2CramRecordFactory f = new Sam2CramRecordFactory(ref, record.getHeader(), CramVersions.CRAM_v3);
		CramCompressionRecord cramRecord = f.createCramRecord(record);

		p.addQualityScores(record, cramRecord, tracks);
		if (!cramRecord.isForcePreserveQualityScores()) {
			CramNormalizer.restoreQualityScores((byte) 30, Collections.singletonList(cramRecord));
		}

		StringBuffer sb = new StringBuffer();
		sb.append(record.getBaseQualityString());
		sb.append("\n");
		sb.append(SAMUtils.phredToFastq(cramRecord.qualityScores));

		assertArrayEquals(sb.toString(), record.getBaseQualities(), cramRecord.qualityScores);
	}
}