def test_get_align(self): """get_align_for_phylip should return Aligment object for phylip files""" align = get_align_for_phylip(self.big_interleaved) align = get_align_for_phylip(self.interleaved_little) s = str(align) self.assertEqual(s, '''>Archaeopt CGATGCTTACCGCCGATGCTTACCGCCGATGCTTACCGC >Hesperorni CGTTACTCGTTGTCGTTACTCGTTGTCGTTACTCGTTGT >Baluchithe TAATGTTAATTGTTAATGTTAATTGTTAATGTTAATTGT >B. virgini TAATGTTCGTTGTTAATGTTCGTTGTTAATGTTCGTTGT >Brontosaur CAAAACCCATCATCAAAACCCATCATCAAAACCCATCAT >B.subtilis GGCAGCCAATCACGGCAGCCAATCACGGCAGCCAATCAC ''') align = get_align_for_phylip(self.noninterleaved_little) s = str(align) self.assertEqual(s, '''>Archaeopt CGATGCTTACCGCCGATGCT >Hesperorni CGTTACTCGTTGTCGTTACT >Baluchithe TAATGTTAATTGTTAATGTT >B. virgini TAATGTTCGTTGTTAATGTT >Brontosaur CAAAACCCATCATCAAAACC >B.subtilis GGCAGCCAATCACGGCAGCC ''')
def setUp(self): """Check if Raxml version is supported for this test""" acceptable_version = (7, 3, 0) self.assertTrue(app_path('raxmlHPC'), "raxmlHPC not found. This may or may not be a problem depending on "+\ "which components of QIIME you plan to use.") command = "raxmlHPC -v | grep version" proc = Popen(command,shell=True,universal_newlines=True,\ stdout=PIPE,stderr=STDOUT) stdout = proc.stdout.read() version_string = stdout.strip().split(' ')[4].strip() try: version = tuple(map(int, version_string.split('.'))) pass_test = version == acceptable_version except ValueError: pass_test = False version_string = stdout self.assertTrue(pass_test,\ "Unsupported raxmlHPC version. %s is required, but running %s." \ % ('.'.join(map(str,acceptable_version)), version_string)) """Setup data for raxml tests""" self.seqs1 = [ 'ACUGCUAGCUAGUAGCGUACGUA', 'GCUACGUAGCUAC', 'GCGGCUAUUAGAUCGUA' ] self.labels1 = ['>1', '>2', '>3'] self.lines1 = flatten(zip(self.labels1, self.seqs1)) self.test_model = "GTRCAT" self.align1 = get_align_for_phylip(StringIO(PHYLIP_FILE)) self.test_fn1 = "/tmp/raxml_test1.txt" self.test_fn2 = "raxml_test1.txt" self.test_fn1_space = "/tmp/raxml test1.txt"
def setUp(self): """Check if Raxml version is supported for this test""" acceptable_version = (7,3,0) self.assertTrue(app_path('raxmlHPC'), "raxmlHPC not found. This may or may not be a problem depending on "+\ "which components of QIIME you plan to use.") command = "raxmlHPC -v | grep version" proc = Popen(command,shell=True,universal_newlines=True,\ stdout=PIPE,stderr=STDOUT) stdout = proc.stdout.read() version_string = stdout.strip().split(' ')[4].strip() try: version = tuple(map(int,version_string.split('.'))) pass_test = version == acceptable_version except ValueError: pass_test = False version_string = stdout self.assertTrue(pass_test,\ "Unsupported raxmlHPC version. %s is required, but running %s." \ % ('.'.join(map(str,acceptable_version)), version_string)) """Setup data for raxml tests""" self.seqs1 = ['ACUGCUAGCUAGUAGCGUACGUA','GCUACGUAGCUAC', 'GCGGCUAUUAGAUCGUA'] self.labels1 = ['>1','>2','>3'] self.lines1 = flatten(zip(self.labels1,self.seqs1)) self.test_model = "GTRCAT" self.align1 = get_align_for_phylip(StringIO(PHYLIP_FILE)) self.test_fn1 = "/tmp/raxml_test1.txt" self.test_fn2 = "raxml_test1.txt" self.test_fn1_space = "/tmp/raxml test1.txt"
def setUp(self): """Setup data for raxml tests""" self.seqs1 = ['ACUGCUAGCUAGUAGCGUACGUA','GCUACGUAGCUAC', 'GCGGCUAUUAGAUCGUA'] self.labels1 = ['>1','>2','>3'] self.lines1 = flatten(zip(self.labels1,self.seqs1)) self.test_model = "GTRCAT" self.align1 = get_align_for_phylip(StringIO(PHYLIP_FILE)) self.test_fn1 = "/tmp/raxml_test1.txt" self.test_fn2 = "raxml_test1.txt" self.test_fn1_space = "/tmp/raxml test1.txt"
def insert_sequences_into_tree(aln, moltype, params={}, write_log=True): """Returns a tree from Alignment object aln. aln: an xxx.Alignment object, or data that can be used to build one. moltype: cogent.core.moltype.MolType object params: dict of parameters to pass in to the RAxML app controller. The result will be an xxx.Alignment object, or None if tree fails. """ # convert aln to phy since seq_names need fixed to run through pplacer new_aln=get_align_for_phylip(StringIO(aln)) # convert aln to fasta in case it is not already a fasta file aln2 = Alignment(new_aln) seqs = aln2.toFasta() ih = '_input_as_multiline_string' pplacer_app = Pplacer(params=params, InputHandler=ih, WorkingDir=None, SuppressStderr=False, SuppressStdout=False) pplacer_result = pplacer_app(seqs) # write a log file if write_log: log_fp = join(params["--out-dir"],'log_pplacer_' + \ split(get_tmp_filename())[-1]) log_file=open(log_fp,'w') log_file.write(pplacer_result['StdOut'].read()) log_file.close() # use guppy to convert json file into a placement tree guppy_params={'tog':None} new_tree=build_tree_from_json_using_params(pplacer_result['json'].name, \ output_dir=params['--out-dir'], \ params=guppy_params) pplacer_result.cleanUp() return new_tree
def setUp(self): """Setup data for raxml tests""" self.seqs1 = [ 'ACUGCUAGCUAGUAGCGUACGUA', 'GCUACGUAGCUAC', 'GCGGCUAUUAGAUCGUA' ] self.labels1 = ['>1', '>2', '>3'] self.lines1 = flatten(zip(self.labels1, self.seqs1)) self.test_model = "GTRCAT" self.align1 = get_align_for_phylip(StringIO(PHYLIP_FILE)) self.test_fn1 = "/tmp/raxml_test1.txt" self.test_fn2 = "raxml_test1.txt" self.test_fn1_space = "/tmp/raxml test1.txt"
def test_insert_sequences_into_tree(self): """Inserts sequences into Tree using params - test handles tree-insertion""" # generate temp filename for output outfname = splitext(get_tmp_filename('/tmp/'))[0] # create starting tree outtreefname = outfname + '.tre' outtree = open(outtreefname, 'w') outtree.write(REF_TREE) outtree.close() # set params for tree-insertion params = {} params["-w"] = "/tmp/" params["-n"] = get_tmp_filename().split("/")[-1] params["-f"] = 'v' #params["-G"] = '0.25' params["-t"] = outtreefname params["-m"] = 'GTRGAMMA' aln_ref_query = get_align_for_phylip( StringIO(PHYLIP_FILE_DNA_REF_QUERY)) aln = Alignment(aln_ref_query) seqs, align_map = aln.toPhylip() tree = insert_sequences_into_tree(seqs, DNA, params=params, write_log=False) for node in tree.tips(): removed_query_str = re.sub('QUERY___', '', str(node.Name)) new_node_name = re.sub('___\d+', '', str(removed_query_str)) if new_node_name in align_map: node.Name = align_map[new_node_name] self.assertTrue(isinstance(tree, PhyloNode)) self.assertEqual(tree.getNewick(with_distances=True), RESULT_TREE) self.assertEqual(len(tree.tips()), 7) self.assertRaises(NotImplementedError, build_tree_from_alignment, \ self.align1, RNA, True) remove(outtreefname)
def insert_sequences_into_tree(aln, moltype, params={}): """Returns a tree from placement of sequences """ # convert aln to phy since seq_names need fixed to run through parsinsert new_aln=get_align_for_phylip(StringIO(aln)) # convert aln to fasta in case it is not already a fasta file aln2 = Alignment(new_aln) seqs = aln2.toFasta() parsinsert_app = ParsInsert(params=params) result = parsinsert_app(seqs) # parse tree tree = DndParser(result['Tree'].read(), constructor=PhyloNode) # cleanup files result.cleanUp() return tree
def insert_sequences_into_tree(aln, moltype, params={}): """Returns a tree from placement of sequences """ # convert aln to phy since seq_names need fixed to run through parsinsert new_aln = get_align_for_phylip(StringIO(aln)) # convert aln to fasta in case it is not already a fasta file aln2 = Alignment(new_aln) seqs = aln2.toFasta() parsinsert_app = ParsInsert(params=params) result = parsinsert_app(seqs) # parse tree tree = DndParser(result['Tree'].read(), constructor=PhyloNode) # cleanup files result.cleanUp() return tree
def test_insert_sequences_into_tree(self): """Inserts sequences into Tree using params - test handles tree-insertion""" # generate temp filename for output outfname=splitext(get_tmp_filename('/tmp/'))[0] # create starting tree outtreefname=outfname+'.tre' outtree=open(outtreefname,'w') outtree.write(REF_TREE) outtree.close() # set params for tree-insertion params={} params["-w"]="/tmp/" params["-n"] = get_tmp_filename().split("/")[-1] params["-f"] = 'v' #params["-G"] = '0.25' params["-t"] = outtreefname params["-m"] = 'GTRGAMMA' aln_ref_query=get_align_for_phylip(StringIO(PHYLIP_FILE_DNA_REF_QUERY)) aln = Alignment(aln_ref_query) seqs, align_map = aln.toPhylip() tree = insert_sequences_into_tree(seqs, DNA, params=params, write_log=False) for node in tree.tips(): removed_query_str=re.sub('QUERY___','',str(node.Name)) new_node_name=re.sub('___\d+','',str(removed_query_str)) if new_node_name in align_map: node.Name = align_map[new_node_name] self.assertTrue(isinstance(tree, PhyloNode)) self.assertEqual(tree.getNewick(with_distances=True),RESULT_TREE) self.assertEqual(len(tree.tips()), 7) self.assertRaises(NotImplementedError, build_tree_from_alignment, \ self.align1, RNA, True) remove(outtreefname)