Search in sources :

Example 1 with LinearAlignment

use of com.google.api.services.genomics.model.LinearAlignment in project gatk by broadinstitute.

the class ArtificialReadUtils method createArtificialGoogleGenomicsRead.

public static Read createArtificialGoogleGenomicsRead(final String name, final String contig, final int start, final byte[] bases, final byte[] quals, final String cigar) {
    Read googleRead = new Read();
    googleRead.setFragmentName(name);
    googleRead.setAlignment(new LinearAlignment());
    googleRead.getAlignment().setPosition(new Position());
    googleRead.getAlignment().getPosition().setReferenceName(contig);
    googleRead.getAlignment().getPosition().setPosition((long) start - 1);
    googleRead.setAlignedSequence(StringUtil.bytesToString(bases));
    googleRead.getAlignment().setCigar(CigarConversionUtils.convertSAMCigarToCigarUnitList(TextCigarCodec.decode(cigar)));
    List<Integer> convertedQuals = new ArrayList<>();
    for (byte b : quals) {
        convertedQuals.add((int) b);
    }
    googleRead.setAlignedQuality(convertedQuals);
    // Create a fully formed read that can be wrapped by a GATKRead and have a valid
    // SAMString without GATKRead throwing missing field exceptions.
    googleRead.setFailedVendorQualityChecks(false);
    googleRead.setSecondaryAlignment(false);
    googleRead.setSupplementaryAlignment(false);
    googleRead.setDuplicateFragment(false);
    Position matePos = new Position();
    matePos.setReverseStrand(false);
    googleRead.setNextMatePosition(matePos);
    return googleRead;
}
Also used : Read(com.google.api.services.genomics.model.Read) LinearAlignment(com.google.api.services.genomics.model.LinearAlignment) Position(com.google.api.services.genomics.model.Position)

Example 2 with LinearAlignment

use of com.google.api.services.genomics.model.LinearAlignment in project gatk by broadinstitute.

the class GoogleGenomicsReadToGATKReadAdapter method workAroundHttpClientCloneBug.

// TODO: Remove once https://github.com/broadinstitute/hellbender/issues/650 is solved.
private void workAroundHttpClientCloneBug() {
    final List<Integer> alignedQuality = genomicsRead.getAlignedQuality();
    if (null != alignedQuality) {
        genomicsRead.setAlignedQuality(new ArrayList<>(alignedQuality));
    }
    if (null != genomicsRead.getInfo()) {
        Map<String, List<Object>> infoCopy = new LinkedHashMap<>();
        for (Map.Entry<String, List<Object>> entry : genomicsRead.getInfo().entrySet()) {
            infoCopy.put(entry.getKey(), new ArrayList<>(entry.getValue()));
        }
        genomicsRead.setInfo(infoCopy);
    }
    final LinearAlignment alignment = genomicsRead.getAlignment();
    if (null != alignment) {
        alignment.setCigar(new ArrayList<>(alignment.getCigar()));
    }
}
Also used : LinearAlignment(com.google.api.services.genomics.model.LinearAlignment)

Example 3 with LinearAlignment

use of com.google.api.services.genomics.model.LinearAlignment in project gatk by broadinstitute.

the class ReadUtilsUnitTest method readHasNoAssignedPositionTestData.

@DataProvider(name = "ReadHasNoAssignedPositionTestData")
public Object[][] readHasNoAssignedPositionTestData() {
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader();
    // To test the "null contig" cases, we need to use a Google Genomics Read, since SAMRecord doesn't allow it
    final Read unmappedGoogleReadWithNullContigSetStart = new Read();
    unmappedGoogleReadWithNullContigSetStart.setAlignment(new LinearAlignment());
    unmappedGoogleReadWithNullContigSetStart.getAlignment().setPosition(new Position());
    unmappedGoogleReadWithNullContigSetStart.getAlignment().getPosition().setReferenceName(null);
    unmappedGoogleReadWithNullContigSetStart.getAlignment().getPosition().setPosition(10l);
    final GATKRead unmappedReadWithNullContigSetStart = new GoogleGenomicsReadToGATKReadAdapter(unmappedGoogleReadWithNullContigSetStart);
    final Read unmappedGoogleReadWithNullContigUnsetStart = new Read();
    unmappedGoogleReadWithNullContigUnsetStart.setAlignment(new LinearAlignment());
    unmappedGoogleReadWithNullContigUnsetStart.getAlignment().setPosition(new Position());
    unmappedGoogleReadWithNullContigUnsetStart.getAlignment().getPosition().setReferenceName(null);
    unmappedGoogleReadWithNullContigUnsetStart.getAlignment().getPosition().setPosition(Long.valueOf(ReadConstants.UNSET_POSITION));
    final GATKRead unmappedReadWithNullContigUnsetStart = new GoogleGenomicsReadToGATKReadAdapter(unmappedGoogleReadWithNullContigUnsetStart);
    // We'll also test the improbable case of a SAMRecord marked as mapped, but with an unset contig/start
    final SAMRecord mappedSAMWithUnsetContigSetStart = new SAMRecord(header);
    mappedSAMWithUnsetContigSetStart.setReferenceName(ReadConstants.UNSET_CONTIG);
    mappedSAMWithUnsetContigSetStart.setAlignmentStart(10);
    mappedSAMWithUnsetContigSetStart.setReadUnmappedFlag(false);
    final GATKRead mappedReadWithUnsetContigSetStart = new SAMRecordToGATKReadAdapter(mappedSAMWithUnsetContigSetStart);
    final SAMRecord mappedSAMWithSetContigUnsetStart = new SAMRecord(header);
    mappedSAMWithSetContigUnsetStart.setReferenceName("1");
    mappedSAMWithSetContigUnsetStart.setAlignmentStart(ReadConstants.UNSET_POSITION);
    mappedSAMWithSetContigUnsetStart.setReadUnmappedFlag(false);
    final GATKRead mappedReadWithSetContigUnsetStart = new SAMRecordToGATKReadAdapter(mappedSAMWithSetContigUnsetStart);
    return new Object[][] { // Mapped read with position
    { ArtificialReadUtils.createArtificialRead(header, "foo", 0, 5, 10), false }, // Basic unmapped read with no position
    { ArtificialReadUtils.createArtificialUnmappedRead(header, new byte[] { 'A' }, new byte[] { 30 }), true }, // Unmapped read with set position (contig and start)
    { ArtificialReadUtils.createArtificialUnmappedReadWithAssignedPosition(header, "1", 10, new byte[] { 'A' }, new byte[] { 30 }), false }, // Unmapped read with null contig, set start
    { unmappedReadWithNullContigSetStart, true }, // Unmapped read with "*" contig, set start
    { ArtificialReadUtils.createArtificialUnmappedReadWithAssignedPosition(header, ReadConstants.UNSET_CONTIG, 10, new byte[] { 'A' }, new byte[] { 30 }), true }, // Unmapped read with set contig, unset start
    { ArtificialReadUtils.createArtificialUnmappedReadWithAssignedPosition(header, "1", ReadConstants.UNSET_POSITION, new byte[] { 'A' }, new byte[] { 30 }), true }, // Unmapped read with null contig, unset start
    { unmappedReadWithNullContigUnsetStart, true }, // Unmapped read with "*" contig, unset start
    { ArtificialReadUtils.createArtificialUnmappedReadWithAssignedPosition(header, ReadConstants.UNSET_CONTIG, ReadConstants.UNSET_POSITION, new byte[] { 'A' }, new byte[] { 30 }), true }, // "Mapped" read with unset contig, set start
    { mappedReadWithUnsetContigSetStart, true }, // "Mapped" read with set contig, unset start
    { mappedReadWithSetContigUnsetStart, true } };
}
Also used : Read(com.google.api.services.genomics.model.Read) LinearAlignment(com.google.api.services.genomics.model.LinearAlignment) Position(com.google.api.services.genomics.model.Position) SAMRecord(htsjdk.samtools.SAMRecord) SAMFileHeader(htsjdk.samtools.SAMFileHeader) DataProvider(org.testng.annotations.DataProvider)

Aggregations

LinearAlignment (com.google.api.services.genomics.model.LinearAlignment)3 Position (com.google.api.services.genomics.model.Position)2 Read (com.google.api.services.genomics.model.Read)2 SAMFileHeader (htsjdk.samtools.SAMFileHeader)1 SAMRecord (htsjdk.samtools.SAMRecord)1 DataProvider (org.testng.annotations.DataProvider)1