Ejemplo n.º 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:
             convertedReads = list(samFile.fetch())
         finally:
             samFile.close()
         samFile = pysam.AlignmentFile(readGroupSet.getSamFilePath(), "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)
Ejemplo n.º 2
0
 def run(self):
     readGroup = self._httpClient.getReadGroup(self._readGroupIds[0])
     iterator = self._httpClient.searchReads(
         readGroupIds=self._readGroupIds, referenceId=self._referenceId,
         start=self._start, end=self._end)
     # do conversion
     samConverter = converters.SamConverter(
         readGroup, iterator, self._outputFile, self._binaryOutput)
     samConverter.convert()
Ejemplo n.º 3
0
 def run(self):
     samConverter = converters.SamConverter(
         self._client,
         readGroupId=self._readGroupIds[0],
         referenceId=self._referenceId,
         start=self._start,
         end=self._end,
         outputFileName=self._outputFile,
         binaryOutput=self._binaryOutput)
     samConverter.convert()
Ejemplo n.º 4
0
def ga2sam_run(args):
    # instantiate params
    searchReadsRequest = RequestFactory(args).createSearchReadsRequest()
    workarounds = getWorkarounds(args)
    httpClient = client.HttpClient(args.baseUrl, args.verbose, workarounds,
                                   args.key)

    # do conversion
    samConverter = converters.SamConverter(httpClient, searchReadsRequest,
                                           args.outputFile, args.binaryOutput)
    samConverter.convert()
Ejemplo n.º 5
0
    def _testRoundTrip(self, binaryOutput):
        with tempfile.NamedTemporaryFile() as fileHandle:
            # write SAM file
            filePath = fileHandle.name
            samConverter = converters.SamConverter(None, self.getReads(),
                                                   filePath, binaryOutput)
            samConverter.convert()

            # read SAM file
            samfile = pysam.AlignmentFile(filePath, "r")
            reads = list(samfile.fetch())
            self.assertEqual(reads[0].query_name, "SRR622461.77861202")
            # TODO more in-depth testing
            samfile.close()
Ejemplo n.º 6
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)