@Test public void testEmptyRecord() { //Note: this does not blow up now but it will once we enforce non empty fields final FastqRecord record = new FastqRecord(null, (String) null, null, null); // assert how null is handled Assert.assertNull(record.getReadName()); Assert.assertNull(record.getReadString()); Assert.assertNull(record.getBaseQualityString()); Assert.assertEquals(record.getReadBases(), SAMRecord.NULL_SEQUENCE); Assert.assertEquals(record.getBaseQualities(), SAMRecord.NULL_QUALS); // copy the FastqRecord to check that equals and hashCode is working for the null read without blow up final FastqRecord copy = new FastqRecord(record); Assert.assertEquals(record, copy); Assert.assertEquals(record.hashCode(), copy.hashCode()); }
private void testRecord(final String expectedReadName, final FastqRecord fastqRecord, final SAMRecord samRecord) { Assert.assertEquals(fastqRecord.getReadName(), expectedReadName); Assert.assertEquals(fastqRecord.getBaseQualities(), samRecord.getBaseQualities()); Assert.assertEquals(fastqRecord.getReadBases(), samRecord.getReadBases()); Assert.assertEquals(fastqRecord.getBaseQualityHeader(), samRecord.getStringAttribute(SAMTag.CO.name())); }
/** * Converts a {@link FastqRecord} into a simple unmapped {@link SAMRecord}. * * <p>This method allows to pass a {@link BiConsumer} to add the information from the record in * a customizable manner. * * @param record object to encode. * @param header header for the returned object. * @param custom function to customize encoding. Note that default information might be overriden. */ public static SAMRecord asSAMRecord(final FastqRecord record, final SAMFileHeader header, final BiConsumer<FastqRecord, SAMRecord> custom) { // construct the SAMRecord and set the unmapped flag final SAMRecord samRecord = new SAMRecord(header); samRecord.setReadUnmappedFlag(true); // get the read name from the FastqRecord correctly formatted final String readName = SequenceUtil.getSamReadNameFromFastqHeader(record.getReadName()); // set the basic information from the FastqRecord samRecord.setReadName(readName); samRecord.setReadBases(record.getReadBases()); samRecord.setBaseQualities(record.getBaseQualities()); custom.accept(record, samRecord); return samRecord; }
/** * Converts a {@link FastqRecord} into a simple unmapped {@link SAMRecord}. * * <p>This method allows to pass a {@link BiConsumer} to add the information from the record in * a customizable manner. * * @param record object to encode. * @param header header for the returned object. * @param custom function to customize encoding. Note that default information might be overriden. */ public static SAMRecord asSAMRecord(final FastqRecord record, final SAMFileHeader header, final BiConsumer<FastqRecord, SAMRecord> custom) { // construct the SAMRecord and set the unmapped flag final SAMRecord samRecord = new SAMRecord(header); samRecord.setReadUnmappedFlag(true); // get the read name from the FastqRecord correctly formatted final String readName = SequenceUtil.getSamReadNameFromFastqHeader(record.getReadName()); // set the basic information from the FastqRecord samRecord.setReadName(readName); samRecord.setReadBases(record.getReadBases()); samRecord.setBaseQualities(record.getBaseQualities()); custom.accept(record, samRecord); return samRecord; }