def _get_b2g_blast(self, input_fpath, goblast_settings): 'It gets a chopped blast ready for use with blast2go' if 'kind' in goblast_settings: db_kind = goblast_settings['kind'] else: db_kind = guess_blastdb_kind(goblast_settings['path']) seq_type = scrape_info_from_fname(input_fpath)['st'] blast_program = guess_blast_program(seq_type, db_kind, prefer_tblastx=True) blastdb = goblast_settings['path'] project_dir = self._project_settings['General_settings']['project_path'] blast = backbone_blast_runner(query_fpath=input_fpath, project_dir=project_dir, blast_program=blast_program, blast_db=blastdb, dbtype=db_kind, threads=self.threads) chop_big_xml, num_items = True, 2 if chop_big_xml: #chopped_blast = open('/tmp/blast_itemized.xml', 'w') chopped_blast = NamedTemporaryFile(suffix='.xml') for blast_parts in xml_itemize(blast, 'Iteration', num_items): chopped_blast.write(blast_parts) chopped_blast.flush() return chopped_blast else: return open(blast)
def test_xml_itemize_by_chunks(): '''It tests xml itemize but with more than one item''' string = '<h><t><c>1</c><c>2</c><c>3</c><c>4</c><c>5</c></t></h>' xml = StringIO.StringIO(string) xmls = list(xml_itemize(xml, 'c', num_items=2)) assert xmls[0] == '<h><t><c>1</c><c>2</c></t></h>' assert xmls[1] == '<h><t><c>3</c><c>4</c></t></h>' assert xmls[2] == '<h><t><c>5</c></t></h>' assert len(xmls) == 3
def test_xml_itemize(): '''It tests xml itemize''' string = '<h><t><c></c><c></c></t></h>' xml = StringIO.StringIO(string) cont = 0 for result in xml_itemize(xml, 'c'): assert result == '<h><t><c></c></t></h>' cont += 1 assert cont == 2
def xml_iprscan_parser_iter(fhand): """It parses an iprscan xml result file. It's an iterator that yields the different protein sections """ parser = make_parser() handler = InterProHandler() parser.setContentHandler(handler) for protein_section in xml_itemize(fhand, "protein"): fhand = StringIO.StringIO(protein_section) parser.parse(fhand) yield handler.get_protein()