def extract_ss(input_path, suffix, tree_file): tree = Tree(tree_file, format=1) leaves_set = set(tree.get_leaf_names()) msa = SeqGroup(input_path.alignment, "fasta") path_argv = [input_path._version, input_path._dataset + suffix] output_path = common.Paths(path_argv, 0) data_versioning.setup_new_dataset(output_path) new_msa = SeqGroup() for entry in msa.iter_entries(): label = entry[0] sequence = entry[1] if (label in leaves_set): new_msa.set_seq(label, sequence) open(output_path.alignment, "w").write(new_msa.write(format="fasta")) shutil.copy(input_path.duplicates_json, output_path.duplicates_json) shutil.copy(input_path.outgroups_file, output_path.outgroups_file)
def extract_ss(input_path, suffix, tree_file): print( "Extracting alignment generated with the support selection tree thinning technique..." ) tree = Tree(tree_file, format=1) leaves_set = set(tree.get_leaf_names()) msa = SeqGroup(input_path.alignment, "fasta") path_argv = [input_path._version, input_path._dataset + suffix] output_path = common.Paths(path_argv, 0) data_versioning.setup_new_dataset(output_path) new_msa = SeqGroup() for entry in msa.iter_entries(): label = entry[0] sequence = entry[1] if (label in leaves_set): new_msa.set_seq(label, sequence) open(output_path.alignment, "w").write(new_msa.write(format="fasta")) shutil.copy(input_path.duplicates_json, output_path.duplicates_json) shutil.copy(input_path.outgroups_file, output_path.outgroups_file) print("New version of the snapshot: " + output_path.path)
for name, seq, _ in alg_aa: try: cdna = F.id2seq[F.name2id[name]] except KeyError: print "cdna for %s not found" % name continue cdna_aln = "" for pos in seq: if pos != "-": cdna_aln += cdna[:3] cdna = cdna[3:] else: cdna_aln += "---" # Last the stop codon cdna_aln += cdna[:3] alg_dna.set_seq(name, cdna_aln) print "Input protein alignment contains %s aa sequences" % len(alg_aa) print "Output cdna alignment contains %s cdna sequences" % len(alg_dna) print alg_dna.write(outfile=infile.replace(".clustalo", ".clustalo.cdna.aln"))
F = parser.fasta.read_fasta(sys.argv[2]) for infile in infiles: print infile if os.stat(infile).st_size == 0: continue alg_aa = SeqGroup(infile) alg_dna = SeqGroup() for name, seq, _ in alg_aa: try: cdna = F.id2seq[F.name2id[name]] except KeyError: print "cdna for %s not found" % name continue cdna_aln = "" for pos in seq: if pos != "-": cdna_aln += cdna[:3] cdna = cdna[3:] else: cdna_aln += "---" # Last the stop codon cdna_aln += cdna[:3] alg_dna.set_seq(name, cdna_aln) print "Input protein alignment contains %s aa sequences" % len(alg_aa) print "Output cdna alignment contains %s cdna sequences" % len(alg_dna) print alg_dna.write(outfile=infile.replace(".clustalo", ".clustalo.cdna.aln"))