Search in sources :

Example 1 with Position

use of com.google.api.services.genomics.model.Position 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 Position

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

the class GoogleGenomicsReadToGATKReadAdapter method mateIsReverseStrand.

@Override
public boolean mateIsReverseStrand() {
    Utils.validate(isPaired(), "Cannot get mate information for an unpaired read");
    final Position matePosition = assertFieldValueNotNull(genomicsRead.getNextMatePosition(), "mate position");
    return assertFieldValueNotNull(matePosition.getReverseStrand(), "mate strand");
}
Also used : Position(com.google.api.services.genomics.model.Position)

Example 3 with Position

use of com.google.api.services.genomics.model.Position 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)

Example 4 with Position

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

the class GATKReadAdaptersUnitTest method basicGoogleGenomicsRead.

/**
     * Creates a basic mapped Google read with a mapped mate.
     * @return GoogleGenomicsRead
     */
private static Read basicGoogleGenomicsRead() {
    final Read read = ArtificialReadUtils.createArtificialGoogleGenomicsRead(BASIC_READ_NAME, BASIC_READ_CONTIG, BASIC_READ_START, BASIC_READ_BASES, BASIC_READ_BASE_QUALITIES, BASIC_READ_CIGAR);
    read.setReadGroupId(BASIC_READ_GROUP);
    read.getAlignment().getPosition().setReverseStrand(false);
    read.getAlignment().setMappingQuality(BASIC_READ_MAPPING_QUALITY);
    read.setNextMatePosition(new Position());
    read.getNextMatePosition().setReferenceName(BASIC_READ_MATE_CONTIG);
    read.getNextMatePosition().setPosition((long) BASIC_READ_MATE_START - 1);
    read.getNextMatePosition().setReverseStrand(false);
    read.setNumberReads(2);
    read.setReadNumber(0);
    read.setProperPlacement(false);
    Map<String, List<Object>> infoMap = new LinkedHashMap<>();
    infoMap.put(SAMTag.PG.name(), Collections.singletonList(BASIC_PROGRAM));
    read.setInfo(infoMap);
    return read;
}
Also used : Read(com.google.api.services.genomics.model.Read) Position(com.google.api.services.genomics.model.Position)

Example 5 with Position

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

the class GATKReadAdaptersUnitTest method getAndSetMatePositionData.

@DataProvider(name = "GetAndSetMatePositionData")
public Object[][] getAndSetMatePositionData() {
    final SAMRecord samWithUnmappedMate = basicSAMRecord();
    samWithUnmappedMate.setMateUnmappedFlag(true);
    final Read googleReadWithUnmappedMate = basicGoogleGenomicsRead();
    // NOTE: we're taking advantage here of a quirk of the current adapter implementation to allow us to run
    // all the getSAMString tests.
    //
    // The GoogleGenomicsReadToGATKReadAdapter throws if the caller attempts to call isMateReverseStrand
    // when it has never previously been explicitly set to true or false, but we need to query it in order
    // to get the flags needed for getSAMString. In order to ensure that all of the getSAMString tests here
    // can query this flag, we artificially set a matePosition with no position value but with the reverseStrandFlag
    // set to false. Doing this does not toggle the value returned by the mateIsUnmapped (it will still return true),
    // and ensures that we will subsequently be able to run all the getSAMString tests on these reads once they have
    // had a mate position established.
    //
    // (See the note on setMatePosition in GoogleGenomicsReadToGATKReadAdapter)
    final Position matePos = new Position();
    matePos.setReverseStrand(false);
    googleReadWithUnmappedMate.setNextMatePosition(matePos);
    // verify that the read still has mateIsUnmapped == true
    Assert.assertTrue(new GoogleGenomicsReadToGATKReadAdapter(googleReadWithUnmappedMate).mateIsUnmapped());
    return new Object[][] { { basicReadBackedBySam(), BASIC_READ_MATE_CONTIG, BASIC_READ_MATE_START }, { basicReadBackedByGoogle(), BASIC_READ_MATE_CONTIG, BASIC_READ_MATE_START }, { new SAMRecordToGATKReadAdapter(samWithUnmappedMate), null, ReadConstants.UNSET_POSITION }, { new GoogleGenomicsReadToGATKReadAdapter(googleReadWithUnmappedMate), null, ReadConstants.UNSET_POSITION } };
}
Also used : Read(com.google.api.services.genomics.model.Read) Position(com.google.api.services.genomics.model.Position) DataProvider(org.testng.annotations.DataProvider)

Aggregations

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