def testCorrectNumberOfAlignmentsWhenReadIdsAreAbbreviated(self): """ A JSONRecordsReader must return the expected number of alignments when read ids are truncated at the first space. That is, the BLAST output has query names that are long and which contain a space but the reads in the FASTA have just the first part of those names (up to the first space). """ reads = Reads([ DNARead( 'BIOMICS-HISEQTP:140:HJFH5BCXX:1:1101:9489:4234', 'AGGGCTCGGATGCTGTGGGTGTTTGTGTGGAGTTGGGTGTGTTTTCGGGG' 'GTGGTTGAGTGGAGGGATTGCTGTTGGATTGTGTGTTTTGTTGTGGTTGCG'), DNARead( 'BIOMICS-HISEQTP:140:HJFH5BCXX:1:1101:19964:6287', 'TTTTTCTCCTGCGTAGATGAACCTACCCATGGCTTAGTAGGTCCTCTTTC' 'ACCACGAGTTAAACCATTAACATTATATTTTTCTATAATTATACCACTGGC'), DNARead( 'BIOMICS-HISEQTP:140:HJFH5BCXX:1:1101:11488:7488', 'ACCTCCGCCTCCCAGGTTCAAGCAATTCTCCTGCCTTAGCCTCCTGAATA' 'GCTGGGATTACAGGTATGCAGGAGGCTAAGGCAGGAGAATTGCTTGAACCT'), DNARead( 'BIOMICS-HISEQTP:140:HJFH5BCXX:1:1101:14734:7512', 'GAGGGTGGAGGTAACTGAGGAAGCAAAGGCTTGGAGACAGGGCCCCTCAT' 'AGCCAGTGAGTGCGCCATTTTCTTTGGAGCAATTGGGTGGGGAGATGGGGC'), ]) mockOpener = mockOpen(read_data=JSON) with patch.object(builtins, 'open', mockOpener): reader = JSONRecordsReader('file.json') alignments = list(reader.readAlignments(reads)) self.assertEqual(4, len(alignments))
def testCorrectNumberOfAlignments(self): """ A JSONRecordsReader must return the expected number of alignments. """ reads = Reads([ DNARead( 'BIOMICS-HISEQTP:140:HJFH5BCXX:1:1101:9489:4234 1:N:0:TGACCA', 'AGGGCTCGGATGCTGTGGGTGTTTGTGTGGAGTTGGGTGTGTTTTCGGGG' 'GTGGTTGAGTGGAGGGATTGCTGTTGGATTGTGTGTTTTGTTGTGGTTGCG'), DNARead( 'BIOMICS-HISEQTP:140:HJFH5BCXX:1:1101:19964:6287 1:N:0:TGACCA', 'TTTTTCTCCTGCGTAGATGAACCTACCCATGGCTTAGTAGGTCCTCTTTC' 'ACCACGAGTTAAACCATTAACATTATATTTTTCTATAATTATACCACTGGC'), DNARead( 'BIOMICS-HISEQTP:140:HJFH5BCXX:1:1101:11488:7488 1:N:0:TGACCA', 'ACCTCCGCCTCCCAGGTTCAAGCAATTCTCCTGCCTTAGCCTCCTGAATA' 'GCTGGGATTACAGGTATGCAGGAGGCTAAGGCAGGAGAATTGCTTGAACCT'), DNARead( 'BIOMICS-HISEQTP:140:HJFH5BCXX:1:1101:14734:7512 1:N:0:TGACCA', 'GAGGGTGGAGGTAACTGAGGAAGCAAAGGCTTGGAGACAGGGCCCCTCAT' 'AGCCAGTGAGTGCGCCATTTTCTTTGGAGCAATTGGGTGGGGAGATGGGGC'), ]) mockOpener = mockOpen(read_data=JSON) with patch.object(builtins, 'open', mockOpener): reader = JSONRecordsReader('file.json') alignments = list(reader.readAlignments(reads)) self.assertEqual(4, len(alignments))
def testCorrectNumberOfAlignmentsWhenReadIdsAreAbbreviated(self): """ A JSONRecordsReader must return the expected number of alignments when read ids are truncated at the first space. That is, the BLAST output has query names that are long and which contain a space but the reads in the FASTA have just the first part of those names (up to the first space). """ reads = Reads([ DNARead( 'BIOMICS-HISEQTP:140:HJFH5BCXX:1:1101:9489:4234', 'AGGGCTCGGATGCTGTGGGTGTTTGTGTGGAGTTGGGTGTGTTTTCGGGG' 'GTGGTTGAGTGGAGGGATTGCTGTTGGATTGTGTGTTTTGTTGTGGTTGCG'), DNARead( 'BIOMICS-HISEQTP:140:HJFH5BCXX:1:1101:19964:6287', 'TTTTTCTCCTGCGTAGATGAACCTACCCATGGCTTAGTAGGTCCTCTTTC' 'ACCACGAGTTAAACCATTAACATTATATTTTTCTATAATTATACCACTGGC'), DNARead( 'BIOMICS-HISEQTP:140:HJFH5BCXX:1:1101:11488:7488', 'ACCTCCGCCTCCCAGGTTCAAGCAATTCTCCTGCCTTAGCCTCCTGAATA' 'GCTGGGATTACAGGTATGCAGGAGGCTAAGGCAGGAGAATTGCTTGAACCT'), DNARead( 'BIOMICS-HISEQTP:140:HJFH5BCXX:1:1101:14734:7512', 'GAGGGTGGAGGTAACTGAGGAAGCAAAGGCTTGGAGACAGGGCCCCTCAT' 'AGCCAGTGAGTGCGCCATTTTCTTTGGAGCAATTGGGTGGGGAGATGGGGC'), ]) mockOpener = mockOpen(read_data=JSON) with patch.object(builtins, 'open', mockOpener): reader = JSONRecordsReader('file.json') readAlignments = list(reader.readAlignments(reads)) self.assertEqual(4, len(readAlignments))
def testCorrectNumberOfReadAlignments(self): """ A JSONRecordsReader must return the expected number of read alignments. """ mockOpener = mockOpen(read_data=JSON) with patch.object(builtins, 'open', mockOpener): reader = JSONRecordsReader('file.json') alignments = list(reader.readAlignments(self.READS)) self.assertEqual(4, len(alignments))
def testIdentity(self): """ The identity value must be read correctly from the HSPs. """ mockOpener = mockOpen(read_data=JSON) with patch.object(builtins, 'open', mockOpener): reader = JSONRecordsReader('file.json') readAlignments = list(reader.readAlignments(self.READS)) self.assertEqual(38, readAlignments[0][0].hsps[0].identicalCount) self.assertEqual(77, readAlignments[0][0].hsps[0].positiveCount) self.assertEqual(380, readAlignments[1][0].hsps[0].identicalCount) self.assertEqual(770, readAlignments[1][0].hsps[0].positiveCount) self.assertEqual(3, readAlignments[1][1].hsps[0].identicalCount) self.assertEqual(7, readAlignments[1][1].hsps[0].positiveCount) self.assertEqual(3800, readAlignments[1][2].hsps[0].identicalCount) self.assertEqual(7700, readAlignments[1][2].hsps[0].positiveCount)
def _getReader(self, filename, scoreClass): """ Obtain a JSON record reader for BLAST records. @param filename: The C{str} file name holding the JSON. @param scoreClass: A class to hold and compare scores (see scores.py). """ if filename.endswith('.json') or filename.endswith('.json.bz2'): return JSONRecordsReader(filename, scoreClass) else: raise ValueError('Unknown BLAST record file suffix for file %r.' % filename)