def run_dnaml(self, seq_align, ptree, seqpattern, cdrfile, wdir, rep, tag=""): """Run dnaml. Arguments are: seq_align: the input nt sequences (MultipleSequenceAlignment) ptree: phylogenetic tree (Bio.Phylo) seqpattern: A list of sequence number directives, in the format accepted by Alignment.set_position_numbers wdir: the name of a directory that run_paml should use. This must exist already. rep: a function that takes a string as an argument. This will be called should an error or warning be necessary (may be called multiple times in one invocation). tag: an optional tag to prefix filenames with Sequences in seq_align must be the same length, must start on a codon boundary, and be an integral number of codons in length. The first sequence must be the ancestral sequence or outgroup. Exactly he same sequence names must occur in the alignment and the tree. Sequence name format is pretty flexible (sequences are mapped to names acceptable to PAML and remapped after PAML has run). """ root_id = seq_align[0].id # Translate clade names to something safe namedict = {} serial = 1 for seq in seq_align: namedict[seq.id] = "N%09d" % serial seq.id = namedict[seq.id] serial += 1 qtree = copy.deepcopy(ptree) for clade in qtree.get_terminals(): if clade.name and clade.name in namedict: clade.name = namedict[clade.name] # Root the tree on the first record first = "N%09d" % 1 try: qtree.root_with_outgroup( qtree.find_clades(name=re.escape(first)).next()) except: raise ValueError("Error: root sequence not found in tree.") try: inv_dict = {v: k for k, v in namedict.items()} ptree.root_with_outgroup( ptree.find_clades(name=re.escape(inv_dict[first]))) Phylo.write(ptree, wdir + "/" + "input_treefile.new", "newick", plain=False) except: raise ValueError( "Error rooting trees: check for corrupt tree file or duplicated sequences." ) # Write the sequences, in PHYLIP format (real PHYLIP format, as used by PHYLIP!) with open(wdir + "/" + "infile", "w") as f: f.write(" %d %d\n" % (len(seq_align), len(seq_align[0]))) for seq in seq_align: f.write("%10s%s\n" % (seq.id, seq.seq.upper())) # Write the tree file Phylo.write(qtree, wdir + "/" + "intree", "newick") if os.path.exists(wdir + "/" + "outfile"): os.remove(wdir + "/" + "outfile") if os.path.exists(wdir + "/" + "outtree"): os.remove(wdir + "/" + "outtree") # The path to the module may reference either a .py or a .pyc file... ctlfile = os.path.abspath(__file__).replace(".pyc", ".ctl") if ".pyc" in os.path.abspath(__file__) \ else os.path.abspath(__file__).replace(".py", ".ctl") # Check for dnaml in the current directory dnamlfile = os.path.abspath(__file__).replace("Dnaml.pyc", "dnaml") if ".pyc" in os.path.abspath(__file__) \ else os.path.abspath(__file__).replace("Dnaml.py", "dnaml") if not os.path.exists(dnamlfile): dnamlfile = "dnaml" # must be on the path somewhere with open(wdir + "/" + "dnaml.txt", "w") as o, open(ctlfile, "r") as i: subprocess.call(dnamlfile, cwd=wdir, stdin=i, stdout=o) if not os.path.isfile(wdir + "/" + "outfile"): rep("No output returned by dnaml: please check the logs for the issue." ) return None if os.path.isfile(wdir + "/" + "outfile.txt"): os.remove(wdir + "/" + "outfile.txt") os.rename(wdir + "/" + "outfile", wdir + "/" + "outfile.txt") intseqs = self.__parse_outfile(wdir + "/" + "outfile.txt") if not intseqs: rep("Unexpected output returned by dnaml: please check the logs for the issue." ) return None # Custom sort function to put the root record first, then others supplied by the user, then intermediate nodes def key_ids(rec): if rec.id == "N%09d" % 1: return 'a__' + rec.id elif 'node_' in rec.id: return 'z__' + "%04d" % (int)(rec.id.split("_")[1]) else: return 'l__' + rec.id labelled_tree = Phylo.read(wdir + "/" + "outtree", "newick") intseqs.seek(0) int_seqs = Alignment(file_name=intseqs, format="fasta") int_seqs.sort(key=key_ids) intseqs.seek(0) int_aas = Alignment() int_aas.read_nt(intseqs, "fasta") int_aas.sort(key=key_ids) int_aas.set_position_numbers(position_numbers=seqpattern) # Put back the original names in all our collections for seq in int_seqs: if seq.id in inv_dict: seq.id = inv_dict[seq.id] seq.name = "" seq.description = "" for seq in int_aas: if seq.id in inv_dict: seq.id = inv_dict[seq.id] seq.name = "" seq.description = "" nodeid = 1 for clade in labelled_tree.find_clades(order="preorder"): if clade.name is None: clade.name = "node_%d" % nodeid # This relies on our traversal using the same order as dnaml nodeid += 1 else: if clade.name in inv_dict: clade.name = inv_dict[clade.name] # Now we need to map the labelling of the nodes in the labelled tree to the nodes in the original tree self.__map_names(ptree, labelled_tree) Phylo.write(ptree, wdir + "/" + tag + "intermediates_treefile.new", "newick", plain=False) cladenames = [] new_int_aas = Alignment() for clade in ptree.find_clades(): if clade.name is not None: cladenames.append(clade.name) for rec in int_aas: if rec.id in cladenames: new_int_aas.append(rec) int_aas = new_int_aas int_aas.set_position_numbers(position_numbers=seqpattern) copy_tree = copy.deepcopy(ptree) # Calculate AA diffs between each node and its parent, and write to the tree labels = {} def diffkey(diff): return int_aas.index_of(diff[1:-1]) for clade in ptree.find_clades(): if clade.name is not None: parent = self.__get_parent(ptree, clade) if parent is None: path = ptree.get_path(clade) if len(path) == 1 and clade.name != first: fname = inv_dict[first] parent = ptree.find_clades( name=re.escape(fname)).next() if parent is not None and parent.name is not None: diffs = list(int_aas.seqdiff(clade.name, parent.name)) diffs.sort(key=diffkey) diffs = "+".join(diffs) if "node_" in clade.name: labels[clade.name] = diffs else: labels[clade.name] = str(clade.name) + " " + diffs for clade in ptree.find_clades(): if clade.name is not None and clade.name in labels: clade.name = labels[clade.name] Phylo.write(ptree, wdir + "/" + tag + "annotated_treefile.new", "newick", plain=False) # Now write a tree with summary CDR/FR total changes if cdrfile is not None: ptree = copy.deepcopy(copy_tree) acdr = AnalyseCDR(int_aas, file_name=cdrfile) labels = {} for clade in ptree.find_clades(): if clade.name is not None: parent = self.__get_parent(ptree, clade) if parent is None: path = ptree.get_path(clade) if len(path) == 1 and clade.name != first: fname = inv_dict[first] parent = ptree.find_clades( name=re.escape(fname)).next() if parent is not None and parent.name is not None: diffs = acdr.category_diff(clade.name, parent.name) if "node_" in clade.name: labels[clade.name] = diffs else: labels[clade.name] = str(clade.name) + " " + diffs for clade in ptree.find_clades(): if clade.name is not None and clade.name in labels: clade.name = labels[clade.name] Phylo.write(ptree, wdir + "/" + tag + "annotated_treefile_sum.new", "newick", plain=False) # And write a tree with counts of total AA changes ptree = copy.deepcopy(copy_tree) labels = {} for clade in ptree.find_clades(): if clade.name is not None: parent = self.__get_parent(ptree, clade) if parent is None: path = ptree.get_path(clade) if len(path) == 1 and clade.name != first: fname = inv_dict[first] parent = ptree.find_clades( name=re.escape(fname)).next() if parent is not None and parent.name is not None: diffs = list(int_aas.seqdiff(clade.name, parent.name)) if "node_" in clade.name: labels[clade.name] = str( len(diffs)) if len(diffs) > 0 else "" else: labels[clade.name] = str(clade.name) + ( " " + str(len(diffs)) if len(diffs) > 0 else "") for clade in ptree.find_clades(): if clade.name is not None and clade.name in labels: clade.name = labels[clade.name] Phylo.write(ptree, wdir + "/" + tag + "annotated_treefile_tot.new", "newick", plain=False) f = open(wdir + "/" + tag + "aa_alignment.txt", "w") f.write(int_aas.report(100)) f.close() f = open(wdir + "/" + tag + "nt_alignment.txt", "w") f.write(int_seqs.report(100)) f.close() for rec in int_aas: rec.description = "" AlignIO.write(int_aas, wdir + "/" + tag + "aa_alignment.fa", "fasta") AlignIO.write(int_seqs, wdir + "/" + tag + "nt_alignment.fa", "fasta") return int_aas
def run_dnaml(self, seq_align, ptree, seqpattern, cdrfile, wdir, rep, tag=""): """Run dnaml. Arguments are: seq_align: the input nt sequences (MultipleSequenceAlignment) ptree: phylogenetic tree (Bio.Phylo) seqpattern: A list of sequence number directives, in the format accepted by Alignment.set_position_numbers wdir: the name of a directory that run_paml should use. This must exist already. rep: a function that takes a string as an argument. This will be called should an error or warning be necessary (may be called multiple times in one invocation). tag: an optional tag to prefix filenames with Sequences in seq_align must be the same length, must start on a codon boundary, and be an integral number of codons in length. The first sequence must be the ancestral sequence or outgroup. Exactly he same sequence names must occur in the alignment and the tree. Sequence name format is pretty flexible (sequences are mapped to names acceptable to PAML and remapped after PAML has run). """ root_id = seq_align[0].id # Translate clade names to something safe namedict = {} serial = 1 for seq in seq_align: namedict[seq.id] = "N%09d" % serial seq.id = namedict[seq.id] serial += 1 qtree = copy.deepcopy(ptree) for clade in qtree.get_terminals(): if clade.name and clade.name in namedict: clade.name = namedict[clade.name] # Root the tree on the first record first = "N%09d" % 1 try: qtree.root_with_outgroup(qtree.find_clades(name=re.escape(first)).next()) except: raise ValueError("Error: root sequence not found in tree.") try: inv_dict = {v: k for k, v in namedict.items()} ptree.root_with_outgroup(ptree.find_clades(name=re.escape(inv_dict[first]))) Phylo.write(ptree, wdir + "/" + "input_treefile.new", "newick", plain=False) except: raise ValueError("Error rooting trees: check for corrupt tree file or duplicated sequences.") # Write the sequences, in PHYLIP format (real PHYLIP format, as used by PHYLIP!) with open(wdir + "/" + "infile", "w") as f: f.write(" %d %d\n" % (len(seq_align), len(seq_align[0]))) for seq in seq_align: f.write("%10s%s\n" % (seq.id, seq.seq.upper())) # Write the tree file Phylo.write(qtree, wdir + "/" + "intree", "newick") if os.path.exists(wdir + "/" + "outfile"): os.remove(wdir + "/" + "outfile") if os.path.exists(wdir + "/" + "outtree"): os.remove(wdir + "/" + "outtree") # The path to the module may reference either a .py or a .pyc file... ctlfile = os.path.abspath(__file__).replace(".pyc", ".ctl") if ".pyc" in os.path.abspath(__file__) \ else os.path.abspath(__file__).replace(".py", ".ctl") # Check for dnaml in the current directory dnamlfile = os.path.abspath(__file__).replace("Dnaml.pyc", "dnaml") if ".pyc" in os.path.abspath(__file__) \ else os.path.abspath(__file__).replace("Dnaml.py", "dnaml") if not os.path.exists(dnamlfile): dnamlfile = "dnaml" # must be on the path somewhere with open(wdir + "/" + "dnaml.txt", "w") as o, open(ctlfile, "r") as i: subprocess.call(dnamlfile, cwd=wdir, stdin = i, stdout=o) if not os.path.isfile(wdir + "/" + "outfile"): rep("No output returned by dnaml: please check the logs for the issue.") return None if os.path.isfile(wdir + "/" + "outfile.txt"): os.remove(wdir + "/" + "outfile.txt") os.rename(wdir + "/" + "outfile", wdir + "/" + "outfile.txt") intseqs = self.__parse_outfile(wdir + "/" + "outfile.txt") if not intseqs: rep("Unexpected output returned by dnaml: please check the logs for the issue.") return None # Custom sort function to put the root record first, then others supplied by the user, then intermediate nodes def key_ids(rec): if rec.id == "N%09d" % 1: return 'a__' + rec.id elif 'node_' in rec.id: return 'z__' + "%04d" % (int)(rec.id.split("_")[1]) else: return 'l__' + rec.id labelled_tree = Phylo.read(wdir + "/" + "outtree", "newick") intseqs.seek(0) int_seqs = Alignment(file_name=intseqs, format="fasta") int_seqs.sort(key=key_ids) intseqs.seek(0) int_aas = Alignment() int_aas.read_nt(intseqs, "fasta") int_aas.sort(key=key_ids) int_aas.set_position_numbers(position_numbers = seqpattern) # Put back the original names in all our collections for seq in int_seqs: if seq.id in inv_dict: seq.id = inv_dict[seq.id] seq.name = "" seq.description = "" for seq in int_aas: if seq.id in inv_dict: seq.id = inv_dict[seq.id] seq.name = "" seq.description = "" nodeid = 1 for clade in labelled_tree.find_clades(order="preorder"): if clade.name is None: clade.name = "node_%d" % nodeid # This relies on our traversal using the same order as dnaml nodeid += 1 else: if clade.name in inv_dict: clade.name = inv_dict[clade.name] # Now we need to map the labelling of the nodes in the labelled tree to the nodes in the original tree self.__map_names(ptree, labelled_tree) Phylo.write(ptree, wdir + "/" + tag + "intermediates_treefile.new", "newick", plain=False) cladenames = [] new_int_aas = Alignment() for clade in ptree.find_clades(): if clade.name is not None: cladenames.append(clade.name) for rec in int_aas: if rec.id in cladenames: new_int_aas.append(rec) int_aas = new_int_aas int_aas.set_position_numbers(position_numbers = seqpattern) copy_tree = copy.deepcopy(ptree) # Calculate AA diffs between each node and its parent, and write to the tree labels = {} def diffkey(diff): return int_aas.index_of(diff[1:-1]) for clade in ptree.find_clades(): if clade.name is not None: parent = self.__get_parent(ptree, clade) if parent is None: path = ptree.get_path(clade) if len(path) == 1 and clade.name != first: fname = inv_dict[first] parent = ptree.find_clades(name = re.escape(fname)).next() if parent is not None and parent.name is not None: diffs = list(int_aas.seqdiff(clade.name, parent.name)) diffs.sort(key = diffkey) diffs = "+".join(diffs) if "node_" in clade.name: labels[clade.name] = diffs else: labels[clade.name] = str(clade.name) + " " + diffs for clade in ptree.find_clades(): if clade.name is not None and clade.name in labels: clade.name = labels[clade.name] Phylo.write(ptree, wdir + "/" + tag + "annotated_treefile.new", "newick", plain=False) # Now write a tree with summary CDR/FR total changes if cdrfile is not None: ptree = copy.deepcopy(copy_tree) acdr = AnalyseCDR(int_aas, file_name=cdrfile) labels = {} for clade in ptree.find_clades(): if clade.name is not None: parent = self.__get_parent(ptree, clade) if parent is None: path = ptree.get_path(clade) if len(path) == 1 and clade.name != first: fname = inv_dict[first] parent = ptree.find_clades(name = re.escape(fname)).next() if parent is not None and parent.name is not None: diffs = acdr.category_diff(clade.name, parent.name) if "node_" in clade.name: labels[clade.name] = diffs else: labels[clade.name] = str(clade.name) + " " + diffs for clade in ptree.find_clades(): if clade.name is not None and clade.name in labels: clade.name = labels[clade.name] Phylo.write(ptree, wdir + "/" + tag + "annotated_treefile_sum.new", "newick", plain=False) # And write a tree with counts of total AA changes ptree = copy.deepcopy(copy_tree) labels = {} for clade in ptree.find_clades(): if clade.name is not None: parent = self.__get_parent(ptree, clade) if parent is None: path = ptree.get_path(clade) if len(path) == 1 and clade.name != first: fname = inv_dict[first] parent = ptree.find_clades(name = re.escape(fname)).next() if parent is not None and parent.name is not None: diffs = list(int_aas.seqdiff(clade.name, parent.name)) if "node_" in clade.name: labels[clade.name] = str(len(diffs)) if len(diffs) > 0 else "" else: labels[clade.name] = str(clade.name) + (" " + str(len(diffs)) if len(diffs) > 0 else "") for clade in ptree.find_clades(): if clade.name is not None and clade.name in labels: clade.name = labels[clade.name] Phylo.write(ptree, wdir + "/" + tag + "annotated_treefile_tot.new", "newick", plain=False) f = open(wdir + "/" + tag + "aa_alignment.txt", "w") f.write(int_aas.report(100)) f.close() f = open(wdir + "/" + tag + "nt_alignment.txt", "w") f.write(int_seqs.report(100)) f.close() for rec in int_aas: rec.description = "" AlignIO.write(int_aas, wdir + "/" + tag + "aa_alignment.fa", "fasta") AlignIO.write(int_seqs, wdir + "/" + tag + "nt_alignment.fa", "fasta") return int_aas
def main(argv): print "AnnotateTreeCmd v1.0" if len(argv) == 2 and argv[1] == '-t': conduct_tests() exit(0) elif len(argv) != 7: print 'usage python AnnotateTreeCmd.py seqnumfile seqfile treefile cdrfile tag wd.' sys.exit(0) for file in argv[1:4]: check_file(file) (seqnumfile, seqfile, treefile, cdrfile, tag, wdir) = argv[1:7] if len(cdrfile) > 0: check_file(cdrfile) else: cdrfile = None try: if not os.path.exists(wdir): os.makedirs(wdir) except: print "Error creating directory %s." % wdir sys.exit(0) try: msa = Alignment() msa.read_nt(seqfile) # Check that the sequence comprises a valid set of codons for seq in msa: if '*' in seq: print "Stop codon found in sequence %s." % seq.id sys.exit(0) except: print "Error parsing %s: %s." % (seqfile, sys.exc_info()[1]) sys.exit(0) try: seq_pos = msa.read_position_numbers(seqnumfile) except: print "Error parsing %s: %s." % (seqnumfile, sys.exc_info()[1]) sys.exit(0) if cdrfile is not None: try: acdr = AnalyseCDR(msa, file_name=cdrfile) except: print "Error parsing %s: %s." % (cdrfile, sys.exc_info()[1]) sys.exit(0) try: seq_align = AlignIO.read(seqfile, "fasta") except: try: seq_align = AlignIO.read(seqfile, "phylip") except: print "Error parsing %s: %s." % (seqfile, sys.exc_info()[1]) sys.exit(0) try: tree = Phylo.read(treefile, "newick") except: print "Error parsing %s: %s." % (treefile, sys.exc_info()[1]) sys.exit(0) dnaml = Dnaml() int_aas = dnaml.run_dnaml(seq_align, tree, seq_pos, cdrfile, wdir, report, tag) if int_aas is not None: try: if cdrfile is not None: acdr = AnalyseCDR(int_aas, file_name=cdrfile) cdr_output = acdr.analyse() fo = open(wdir + "/" + tag + "cdr_analysis.html", "w") fo.write(cdr_output) fo.close() except: print "Warning: CDRs were not analysed: " + str(sys.exc_info()[1]) try: gc.collect() RenderTree.render_annotate(wdir + "/" + tag + "annotated_treefile.new", wdir + "/" + tag + "annotated_treefile.png") gc.collect() RenderTree.render_annotate(wdir + "/" + tag + "annotated_treefile.new", wdir + "/" + tag + "annotated_treefile.svg") gc.collect() if cdrfile is not None: RenderTree.render_annotate(wdir + "/" + tag + "annotated_treefile_sum.new", wdir + "/" + tag + "annotated_treefile_sum.png") gc.collect() RenderTree.render_annotate(wdir + "/" + tag + "annotated_treefile_sum.new", wdir + "/" + tag + "annotated_treefile_sum.svg") gc.collect() RenderTree.render_annotate(wdir + "/" + tag + "annotated_treefile_tot.new", wdir + "/" + tag + "annotated_treefile_tot.png") gc.collect() RenderTree.render_annotate(wdir + "/" + tag + "annotated_treefile_tot.new", wdir + "/" + tag + "annotated_treefile_tot.svg") gc.collect() RenderTree.render_annotate(wdir + "/" + tag + "intermediates_treefile.new", wdir + "/" + tag + "intermediates_treefile.png") gc.collect() RenderTree.render_annotate(wdir + "/" + tag + "intermediates_treefile.new", wdir + "/" + tag + "intermediates_treefile.svg") gc.collect() except: print "Error rendering trees: " + str(sys.exc_info()[1]) first = True orig_recs = [] for rec in SeqIO.parse(wdir + "/" + tag + "aa_alignment.fa", "fasta"): if not first and "node_" not in rec.id: orig_recs.append(rec) first = False logo_alignment_file = wdir + "/" + tag + "alignment_for_logo.fa" SeqIO.write(orig_recs, wdir + "/" + tag + "alignment_for_logo.fa", "fasta") with open(wdir + "/" + tag + "weblogo_status.txt", "w") as fo: retcode = subprocess.call("seqlogo -f %salignment_for_logo.fa -F PNG -o aa_logo -h 2 -w 20 -acS" % tag, cwd=wdir, shell=True, stdout=fo, stderr=subprocess.STDOUT) if retcode == 1: fo.write("Trying seqlogo.pl instead.\n") retcode = subprocess.call("seqlogo.pl -f %salignment_for_logo.fa -F PNG -o aa_logo -h 2 -w 20 -acS" % tag, cwd=wdir, shell=True, stdout=fo, stderr=subprocess.STDOUT) if retcode == 1: print "Weblogo not installed: logo plot will not be generated."
def main(argv): print "AnnotateTreeCmd v1.0" if len(argv) == 2 and argv[1] == '-t': conduct_tests() exit(0) elif len(argv) != 7: print 'usage python AnnotateTreeCmd.py seqnumfile seqfile treefile cdrfile tag wd.' sys.exit(0) for file in argv[1:4]: check_file(file) (seqnumfile, seqfile, treefile, cdrfile, tag, wdir) = argv[1:7] if len(cdrfile) > 0: check_file(cdrfile) else: cdrfile = None try: if not os.path.exists(wdir): os.makedirs(wdir) except: print "Error creating directory %s." % wdir sys.exit(0) try: msa = Alignment() msa.read_nt( seqfile) # Check that the sequence comprises a valid set of codons for seq in msa: if '*' in seq: print "Stop codon found in sequence %s." % seq.id sys.exit(0) except: print "Error parsing %s: %s." % (seqfile, sys.exc_info()[1]) sys.exit(0) try: seq_pos = msa.read_position_numbers(seqnumfile) except: print "Error parsing %s: %s." % (seqnumfile, sys.exc_info()[1]) sys.exit(0) if cdrfile is not None: try: acdr = AnalyseCDR(msa, file_name=cdrfile) except: print "Error parsing %s: %s." % (cdrfile, sys.exc_info()[1]) sys.exit(0) try: seq_align = AlignIO.read(seqfile, "fasta") except: try: seq_align = AlignIO.read(seqfile, "phylip") except: print "Error parsing %s: %s." % (seqfile, sys.exc_info()[1]) sys.exit(0) try: tree = Phylo.read(treefile, "newick") except: print "Error parsing %s: %s." % (treefile, sys.exc_info()[1]) sys.exit(0) dnaml = Dnaml() int_aas = dnaml.run_dnaml(seq_align, tree, seq_pos, cdrfile, wdir, report, tag) if int_aas is not None: try: if cdrfile is not None: acdr = AnalyseCDR(int_aas, file_name=cdrfile) cdr_output = acdr.analyse() fo = open(wdir + "/" + tag + "cdr_analysis.html", "w") fo.write(cdr_output) fo.close() except: print "Warning: CDRs were not analysed: " + str(sys.exc_info()[1]) try: gc.collect() RenderTree.render_annotate( wdir + "/" + tag + "annotated_treefile.new", wdir + "/" + tag + "annotated_treefile.png") gc.collect() RenderTree.render_annotate( wdir + "/" + tag + "annotated_treefile.new", wdir + "/" + tag + "annotated_treefile.svg") gc.collect() if cdrfile is not None: RenderTree.render_annotate( wdir + "/" + tag + "annotated_treefile_sum.new", wdir + "/" + tag + "annotated_treefile_sum.png") gc.collect() RenderTree.render_annotate( wdir + "/" + tag + "annotated_treefile_sum.new", wdir + "/" + tag + "annotated_treefile_sum.svg") gc.collect() RenderTree.render_annotate( wdir + "/" + tag + "annotated_treefile_tot.new", wdir + "/" + tag + "annotated_treefile_tot.png") gc.collect() RenderTree.render_annotate( wdir + "/" + tag + "annotated_treefile_tot.new", wdir + "/" + tag + "annotated_treefile_tot.svg") gc.collect() RenderTree.render_annotate( wdir + "/" + tag + "intermediates_treefile.new", wdir + "/" + tag + "intermediates_treefile.png") gc.collect() RenderTree.render_annotate( wdir + "/" + tag + "intermediates_treefile.new", wdir + "/" + tag + "intermediates_treefile.svg") gc.collect() except: print "Error rendering trees: " + str(sys.exc_info()[1]) first = True orig_recs = [] for rec in SeqIO.parse(wdir + "/" + tag + "aa_alignment.fa", "fasta"): if not first and "node_" not in rec.id: orig_recs.append(rec) first = False logo_alignment_file = wdir + "/" + tag + "alignment_for_logo.fa" SeqIO.write(orig_recs, wdir + "/" + tag + "alignment_for_logo.fa", "fasta") with open(wdir + "/" + tag + "weblogo_status.txt", "w") as fo: retcode = subprocess.call( "seqlogo -f %salignment_for_logo.fa -F PNG -o aa_logo -h 2 -w 20 -acS" % tag, cwd=wdir, shell=True, stdout=fo, stderr=subprocess.STDOUT) if retcode == 1: fo.write("Trying seqlogo.pl instead.\n") retcode = subprocess.call( "seqlogo.pl -f %salignment_for_logo.fa -F PNG -o aa_logo -h 2 -w 20 -acS" % tag, cwd=wdir, shell=True, stdout=fo, stderr=subprocess.STDOUT) if retcode == 1: print "Weblogo not installed: logo plot will not be generated."