예제 #1
0
 def verifyFullConversion(self, readGroupSet, readGroup, reference):
     """
     Verify that the conversion of the specified readGroup in the
     specified readGroupSet for the specified reference is correct.
     This involves pulling out the reads from the original BAM file
     and comparing these with the converted SAM records.
     """
     with tempfile.NamedTemporaryFile() as fileHandle:
         converter = converters.SamConverter(self._client,
                                             readGroup.getId(),
                                             reference.getId(),
                                             outputFileName=fileHandle.name)
         converter.convert()
         samFile = pysam.AlignmentFile(fileHandle.name, "r")
         try:
             # TODO suppressed because of pysam output:
             # [W::sam_parse1] mapped mate cannot have zero coordinate;
             # treated as unmapped
             # and
             # [W::sam_parse1] mapped mate cannot have zero coordinate;
             # treated as unmapped
             # see discussion in https://github.com/ga4gh/server/pull/789
             with utils.suppressOutput():
                 convertedReads = list(samFile.fetch())
         finally:
             samFile.close()
         samFile = pysam.AlignmentFile(readGroupSet.getDataUrl(), "rb")
         try:
             sourceReads = []
             referenceName = reference.getName().encode()
             readGroupName = readGroup.getLocalId().encode()
             for readAlignment in samFile.fetch(referenceName):
                 tags = dict(readAlignment.tags)
                 if 'RG' in tags and tags['RG'] == readGroupName:
                     sourceReads.append(readAlignment)
         finally:
             samFile.close()
         self.verifySamRecordsEqual(sourceReads, convertedReads)
예제 #2
0
 def verifyFullConversion(self, readGroupSet, readGroup, reference):
     """
     Verify that the conversion of the specified readGroup in the
     specified readGroupSet for the specified reference is correct.
     This involves pulling out the reads from the original BAM file
     and comparing these with the converted SAM records.
     """
     with tempfile.NamedTemporaryFile() as fileHandle:
         converter = converters.SamConverter(
             self._client, readGroup.getId(), reference.getId(),
             outputFileName=fileHandle.name)
         converter.convert()
         samFile = pysam.AlignmentFile(fileHandle.name, "r")
         try:
             # TODO suppressed because of pysam output:
             # [W::sam_parse1] mapped mate cannot have zero coordinate;
             # treated as unmapped
             # and
             # [W::sam_parse1] mapped mate cannot have zero coordinate;
             # treated as unmapped
             # see discussion in https://github.com/ga4gh/server/pull/789
             with utils.suppressOutput():
                 convertedReads = list(samFile.fetch())
         finally:
             samFile.close()
         samFile = pysam.AlignmentFile(readGroupSet.getDataUrl(), "rb")
         try:
             sourceReads = []
             referenceName = reference.getName().encode()
             readGroupName = readGroup.getLocalId().encode()
             for readAlignment in samFile.fetch(referenceName):
                 tags = dict(readAlignment.tags)
                 if 'RG' in tags and tags['RG'] == readGroupName:
                     sourceReads.append(readAlignment)
         finally:
             samFile.close()
         self.verifySamRecordsEqual(sourceReads, convertedReads)
예제 #3
0
 def testParseFailure(self):
     cliInput = "invalidCommand"
     with utils.suppressOutput():
         with mock.patch('sys.exit', self._raiseParseFailureException):
             with self.assertRaises(self.ParseFailureException):
                 self.parser.parse_args(cliInput.split())