Exemplo n.º 1
0
 def getReadAlignmentId(self, gaAlignment):
     """
     Returns a string ID suitable for use in the specified GA
     ReadAlignment object in this ReadGroupSet.
     """
     compoundId = datamodel.ReadAlignmentCompoundId(
         self.getCompoundId(), gaAlignment.fragment_name)
     return str(compoundId)
Exemplo n.º 2
0
 def testReadAlignment(self):
     readGroup = self.getReadGroup()
     readGroupSet = readGroup.getParentContainer()
     dataset = readGroupSet.getParentContainer()
     localId = "alignment"
     cid = datamodel.ReadAlignmentCompoundId(readGroupSet.getCompoundId(),
                                             localId)
     self.assertRaises(ValueError, datamodel.ReadAlignmentCompoundId,
                       dataset.getCompoundId())
     self.assertEqual(cid.dataset, dataset.getLocalId())
     self.assertEqual(cid.read_group_set, readGroupSet.getLocalId())
     self.assertEqual(cid.read_alignment, localId)
     self.assertEqual(cid.dataset_id, dataset.getId())
     self.assertEqual(cid.read_group_set_id, readGroupSet.getId())
Exemplo n.º 3
0
 def assertAlignmentsEqual(self, gaAlignment, pysamAlignment,
                           readGroupInfo):
     if pysamAlignment.query_qualities is None:
         self.assertEqual(gaAlignment.aligned_quality, [])
     else:
         self.assertEqual(gaAlignment.aligned_quality,
                          list(pysamAlignment.query_qualities))
     self.assertEqual(gaAlignment.aligned_sequence,
                      pysamAlignment.query_sequence)
     if reads.SamFlags.isFlagSet(pysamAlignment.flag,
                                 reads.SamFlags.READ_UNMAPPED):
         self.assertEqual(0, gaAlignment.alignment.ByteSize())
     else:
         self.assertEqual(gaAlignment.alignment.mapping_quality,
                          pysamAlignment.mapping_quality)
         self.assertEqual(
             gaAlignment.alignment.position.reference_name,
             readGroupInfo.samFile.getrname(pysamAlignment.reference_id))
         self.assertEqual(gaAlignment.alignment.position.position,
                          pysamAlignment.reference_start)
         # TODO test reverseStrand on position and on
         # nextMatePosition once it has been implemented.
         self.assertCigarEqual(gaAlignment.alignment.cigar,
                               pysamAlignment.cigar)
     self.assertFlag(gaAlignment.duplicate_fragment, pysamAlignment,
                     reads.SamFlags.DUPLICATE_READ)
     self.assertFlag(gaAlignment.failed_vendor_quality_checks,
                     pysamAlignment, reads.SamFlags.FAILED_QUALITY_CHECK)
     self.assertEqual(gaAlignment.fragment_length,
                      pysamAlignment.template_length)
     self.assertEqual(gaAlignment.fragment_name, pysamAlignment.query_name)
     compoundId = datamodel.ReadAlignmentCompoundId(
         self._gaObject.getCompoundId(), pysamAlignment.query_name)
     self.assertEqual(gaAlignment.id, str(compoundId))
     ret = protocol.ReadAlignment()
     for key, value in pysamAlignment.tags:
         protocol.setAttribute(ret.attributes.attr[key].values, value)
     self.assertEqual(protocol.toJson(gaAlignment.attributes),
                      protocol.toJson(ret.attributes))
     if reads.SamFlags.isFlagSet(pysamAlignment.flag,
                                 reads.SamFlags.MATE_UNMAPPED):
         self.assertEqual(0, gaAlignment.next_mate_position.ByteSize())
     else:
         self.assertEqual(gaAlignment.next_mate_position.position,
                          pysamAlignment.next_reference_start)
         if pysamAlignment.next_reference_id != -1:
             self.assertEqual(
                 gaAlignment.next_mate_position.reference_name,
                 readGroupInfo.samFile.getrname(
                     pysamAlignment.next_reference_id))
         else:
             self.assertEqual(gaAlignment.next_mate_position.reference_name,
                              "")
     if gaAlignment.number_reads == 1:
         self.assertFlag(False, pysamAlignment, reads.SamFlags.READ_PAIRED)
     elif gaAlignment.number_reads == 2:
         self.assertFlag(True, pysamAlignment, reads.SamFlags.READ_PAIRED)
     else:
         # we shouldn't be setting numberReads to anything else
         self.assertTrue(False)
     if gaAlignment.read_number is -1:
         self.assertFlag(False, pysamAlignment,
                         reads.SamFlags.FIRST_IN_PAIR)
         self.assertFlag(False, pysamAlignment,
                         reads.SamFlags.SECOND_IN_PAIR)
     elif gaAlignment.read_number == 0:
         self.assertFlag(True, pysamAlignment, reads.SamFlags.FIRST_IN_PAIR)
         self.assertFlag(False, pysamAlignment,
                         reads.SamFlags.SECOND_IN_PAIR)
     elif gaAlignment.read_number == 1:
         self.assertFlag(False, pysamAlignment,
                         reads.SamFlags.FIRST_IN_PAIR)
         self.assertFlag(True, pysamAlignment,
                         reads.SamFlags.SECOND_IN_PAIR)
     elif gaAlignment.read_number == 2:
         self.assertFlag(True, pysamAlignment, reads.SamFlags.FIRST_IN_PAIR)
         self.assertFlag(True, pysamAlignment,
                         reads.SamFlags.SECOND_IN_PAIR)
     else:
         # we shouldn't be setting readNumber to anything else
         self.assertTrue(False)
     self.assertFlag(not gaAlignment.improper_placement, pysamAlignment,
                     reads.SamFlags.READ_PROPER_PAIR)
     self.assertEqual(gaAlignment.read_group_id, readGroupInfo.id)
     self.assertFlag(gaAlignment.secondary_alignment, pysamAlignment,
                     reads.SamFlags.SECONDARY_ALIGNMENT)
     self.assertFlag(gaAlignment.supplementary_alignment, pysamAlignment,
                     reads.SamFlags.SUPPLEMENTARY_ALIGNMENT)