def batch_for_batch(): os.chdir("/home/zerodel/Workspace/mouse/FullLengthMouse") model_gtr = "rebuild_model.mdl" model_nest = "rna_structure_full_mouse.mdl" aln_path = "/home/zerodel/Workspace/mouse/mouse_8_species" bf_maker_nest = BfH.HYPHYBatchFile(species_name="mouse", model_file=model_nest, bf_template_file="template_global") bf_maker_gtr = BfH.HYPHYBatchFile(species_name="mouse", model_file=model_gtr, bf_template_file="template_global") jobids = [file1.split(".")[0] for file1 in os.listdir(aln_path) if ".aln" == file1[-4:]] for job_id in jobids: aln_file_path_full = os.path.join(aln_path, job_id + ".aln") input_file = os.path.join(os.curdir, job_id + ".input") if not os.path.exists(input_file): DH.aln2input(aln_file_path_full, input_file) bfgtr = job_id + "gtr.bf" bf_maker_gtr.write_batch_file( dot_input=job_id + ".input", dot_aln=aln_file_path_full, hyphy_result_file=job_id + "gtr.result", hyphy_batch_file=bfgtr, ) bfnest = job_id + "nest.bf" bf_maker_nest.write_batch_file( dot_input=job_id + ".input", dot_aln=aln_file_path_full, hyphy_result_file=job_id + "nest.result", hyphy_batch_file=bfnest, )
def make_bf_p2(): workpath = "d:\Workspace\Ecoli\P2" os.chdir(workpath) model_gtr = "rebuild_model.mdl" model_nest = "rna_full_length_structure.mdl" bf_maker_gtr = BfH.HYPHYBatchFile(species_name="ecoli", model_file=model_gtr, bf_template_file="templateNoGap") bf_maker_nest = BfH.HYPHYBatchFile(species_name="ecoli", model_file=model_nest, bf_template_file="templateNoGap") bf_maker_gtr.set_tree_from_outside(SS.ecoli()) bf_maker_nest.set_tree_from_outside(SS.ecoli()) aln_file_folder = "d:\Workspace\Ecoli\ecoli_10_species" aln_files = [file_single for file_single in os.listdir(aln_file_folder) if ".aln" == os.path.splitext(file_single)[-1]] for single_aln in aln_files: aln_full_path = os.path.join(aln_file_folder, single_aln) genes, lengths = DH.aln_info(aln_full_path) gene_full_length = lengths[0] jobid = single_aln.split(".")[0] input_file_name = "%s.input" % jobid DH.aln2input(aln_full_path, input_file_name) if gene_full_length < 52: print "%s too short ---" % single_aln continue bf_maker_gtr.set_partition(51, gene_full_length) bf_maker_nest.set_partition(51, gene_full_length) bf_maker_gtr.write_batch_file(dot_input=input_file_name, dot_aln="", hyphy_batch_file="%sp2gtr.bf" % jobid, hyphy_result_file="%sp2gtr.result" % jobid) bf_maker_nest.write_batch_file(dot_input=input_file_name, dot_aln="", hyphy_batch_file="%sp2nest.bf" % jobid, hyphy_result_file="%sp2nest.result" % jobid)
def batch_for_batch(): os.chdir("/home/zerodel/Workspace/mouse/FullLengthMouse") model_gtr = "rebuild_model.mdl" model_nest = "rna_structure_full_mouse.mdl" aln_path = "/home/zerodel/Workspace/mouse/mouse_8_species" bf_maker_nest = BfH.HYPHYBatchFile(species_name="mouse", model_file=model_nest, bf_template_file="template_global") bf_maker_gtr = BfH.HYPHYBatchFile(species_name="mouse", model_file=model_gtr, bf_template_file="template_global") jobids = [ file1.split(".")[0] for file1 in os.listdir(aln_path) if ".aln" == file1[-4:] ] for job_id in jobids: aln_file_path_full = os.path.join(aln_path, job_id + ".aln") input_file = os.path.join(os.curdir, job_id + ".input") if not os.path.exists(input_file): DH.aln2input(aln_file_path_full, input_file) bfgtr = job_id + "gtr.bf" bf_maker_gtr.write_batch_file(dot_input=job_id + ".input", dot_aln=aln_file_path_full, hyphy_result_file=job_id + "gtr.result", hyphy_batch_file=bfgtr) bfnest = job_id + "nest.bf" bf_maker_nest.write_batch_file(dot_input=job_id + ".input", dot_aln=aln_file_path_full, hyphy_result_file=job_id + "nest.result", hyphy_batch_file=bfnest)
def aln_folder_traversal(folder_name): """ """ built_in_gy94mdl = "/usr/lib/hyphy/TemplateBatchFiles/TemplateModels/GY94.mdl" gy94bf = bfHYPHY.HYPHYBatchFile(species_name="ecoli", model_file=built_in_gy94mdl, bf_template_file="partition.bf") own_model = "nest_gy.mdl" nested_model = bfHYPHY.HYPHYBatchFile(species_name="ecoli", model_file=own_model, bf_template_file="partition.bf") nt_nest_model = "nt_nest_gy.mdl" bf_nt_nest = bfHYPHY.HYPHYBatchFile(species_name="ecoli", model_file=nt_nest_model, bf_template_file="partition.bf") gu_model = "myCodonMatrix.def" gu_bf = bfHYPHY.HYPHYBatchFile(species_name="ecoli", model_file=gu_model, bf_template_file="synAlphaWPsiModelP.bf") pwd = os.path.abspath(folder_name) os.chdir(folder_name) aln_files = [file1 for file1 in os.listdir(pwd) if "aln" == file1.split(".")[-1]] for index, aln_name in enumerate(aln_files): # write batch file for each aln gene_id = aln_name.split(".")[0] genes, gene_len = dataHYPHY.aln_info(aln_name) len_gene = max(gene_len) gy94bf1 = "%sgy94.bf" % gene_id input_filename = "%s.input" % gene_id # input file here dataHYPHY.aln2input(dot_aln_file=aln_name, hyphy_input_file=input_filename) # gy model , full length gy94bf.write_batch_file(dot_aln=aln_name, dot_input=input_filename, hyphy_batch_file=gy94bf1, hyphy_result_file="gy94%s_%s.result" % (gene_id, "")) # gy model , part 1 gy94p1_name = "%sgy94p1.bf" % gene_id gy94bf.set_partition(0, 60) gy94bf.write_batch_file(dot_aln=aln_name, dot_input=input_filename, hyphy_batch_file=gy94p1_name, hyphy_result_file="gy94p1%s_%s.result" % (gene_id, "")) # gy model , part 2 gy94p2_name = "%sgy94p2.bf" % gene_id gy94bf.set_partition(60, len_gene) gy94bf.write_batch_file(dot_aln=aln_name, dot_input=input_filename, hyphy_batch_file=gy94p2_name, hyphy_result_file="gy94p2%s_%s.result" % (gene_id, "")) # nested model , full length nested_model.write_batch_file(dot_aln=aln_name, dot_input=input_filename, hyphy_result_file="nest_gy%s.result" % gene_id, hyphy_batch_file="%snest_gy.bf" % gene_id) # nested model , part 1 nested_model.set_partition(0, 60) nested_model.write_batch_file(dot_aln=aln_name, dot_input=input_filename, hyphy_result_file="nest_gy%s_p1.result" % gene_id, hyphy_batch_file="%snest_gyp1.bf" % gene_id) # nested model , part 2 nested_model.set_partition(60, len_gene) nested_model.write_batch_file(dot_aln=aln_name, dot_input=input_filename, hyphy_result_file="nest_gy%s_p2.result" % gene_id, hyphy_batch_file="%snest_gyp2.bf" % gene_id) # nt nested ,full bf_nt_nest.write_batch_file(dot_aln=aln_name, dot_input=input_filename, hyphy_result_file="%snt_nest.result" % gene_id, hyphy_batch_file="%snt_nest.bf" % gene_id) # nt nested , part1 bf_nt_nest.set_partition(0, 60) bf_nt_nest.write_batch_file(dot_aln=aln_name, dot_input=input_filename, hyphy_result_file="%snt_nest_p1.result" % gene_id, hyphy_batch_file="%snt_nest_p1.bf" % gene_id) # nt nested , part2 bf_nt_nest.set_partition(60, len_gene) bf_nt_nest.write_batch_file(dot_aln=aln_name, dot_input=input_filename, hyphy_result_file="%snt_nest_p2.result" % gene_id, hyphy_batch_file="%snt_nest_p2.bf" % gene_id) # gu model . full length gu_bf.write_batch_file(dot_aln=aln_name, dot_input=input_filename, hyphy_result_file="%sgu.result" % gene_id, hyphy_batch_file="%sgu.bf" % gene_id) gu_bf.set_partition(0, 60) gu_bf.write_batch_file(dot_aln=aln_name, dot_input=input_filename, hyphy_result_file="%sgup1.result" % gene_id, hyphy_batch_file="%sgup1.bf" % gene_id) gu_bf.set_partition(60 ,len_gene) gu_bf.write_batch_file(dot_aln=aln_name, dot_input=input_filename, hyphy_result_file="%sgup2.result" % gene_id, hyphy_batch_file="%sgup2.bf" % gene_id)