def testParams(self): """ When a BLAST XML file has been read, its parameters must be present in the reader instance. We only test a subset of the parameters. """ mockOpener = mockOpen(read_data=RECORD) with patch.object(builtins, 'open', mockOpener): reader = XMLRecordsReader('file.xml') list(reader.records()) self.assertEqual('BLASTN', reader.params['application']) self.assertEqual('virus-nt-20130719', reader.params['database'])
def testXMLInput(self): """ Test conversion of a chunk of BLAST XML. This is highly incomplete in what it tests. """ mockOpener = mockOpen(read_data=RECORD) with patch.object(builtins, 'open', mockOpener): reader = XMLRecordsReader('file.xml') record1, record2 = list(reader.records()) self.assertEqual(0, len(record1.alignments)) self.assertEqual(2, len(record2.alignments))
'compress the JSON output.')) parser.add_argument( '--json', metavar='JSON-output-file', help=('the JSON filename to write the converted XML to. If omitted, ' 'standard output will be used.')) parser.add_argument( '--xml', metavar='BLAST-XML-file', default=sys.stdin, help=('the BLAST XML output file to convert. If omitted, standard ' 'input will be read.')) parser.add_argument('--bzip2', default=False, action='store_true', help='If True, compress the JSON output using bzip2.') args = parser.parse_args() if args.bzip2: fp = bz2file.BZ2File(args.json or sys.stdout, 'w') else: fp = open(args.json, 'w') if args.json else sys.stdout reader = XMLRecordsReader(args.xml) reader.saveAsJSON(fp) fp.close()