def test_aln_to_no_gap_input(self): try: dh.check_sequence_matrix(["aaca", "aaa"]) except dh.sequenceNotSameLength: pass else: self.fail("here should raise a exception!") dh.aln2inputNogap("./tmp.aln","./tmp2.input")
def test_aln_to_no_gap_input(self): try: dh.check_sequence_matrix(["aaca", "aaa"]) except dh.sequenceNotSameLength: pass else: self.fail("here should raise a exception!") dh.aln2inputNogap("./tmp.aln", "./tmp2.input")
def main(): # main part aln_files_folder = "d:/Workspace/Ecoli/ecoli_10_species" #aln_files_folder = "d:/Workspace/Ecoli/test" target_path = "d:/Workspace/Ecoli/NoGapP1" aln_files = [ single_file for single_file in os.listdir(aln_files_folder) if ".aln" == os.path.splitext(single_file)[-1] ] model_gtr = "rebuild_model.mdl" model_nest = "rna_full_length_structure.mdl" job_ids = [] seq_length = [] for aln in aln_files: aln_path_full = os.path.join(aln_files_folder, aln) gene_in_aln, length_in_aln = dh.aln_info(aln_path_full) seq_length.append(length_in_aln[0]) job_id = aln.split(".")[0] if 10 == len(gene_in_aln): # only those gene shared in 10 species job_ids.append(job_id) input_file_path_full = os.path.join(target_path, job_id + ".input") shutil.copyfile(aln_path_full, os.path.join(target_path, aln)) # write input file dh.aln2inputNogap(aln_path_full, input_file_path_full) # make bf file for full length no gap gtr and empirical model os.chdir(target_path) bf_maker_nest = BfH.HYPHYBatchFile(species_name="ecoli", model_file=model_nest, bf_template_file="templateNoGap") bf_maker_gtr = BfH.HYPHYBatchFile(species_name="ecoli", model_file=model_gtr, bf_template_file="templateNoGap") for job_id in job_ids: # aln_path_full = os.path.join(aln_files_folder,aln) # input_file_path_full = os.path.join(target_path, job_id + ".input") # shutil.copyfile(aln_path_full, os.path.join(target_path,aln)) # # write input file # dh.aln2inputNogap(aln_path_full, input_file_path_full) # make bf file for full length no gap gtr and empirical model bfgtr = job_id + "gtr.bf" bf_maker_gtr.write_batch_file(dot_input=job_id + ".input", dot_aln=job_id + ".aln", 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=job_id + ".aln", hyphy_result_file=job_id + "nest.result", hyphy_batch_file=bfnest) bf_maker_gtr.set_partition(0, 51) bf_maker_nest.set_partition(0, 51) for job_id in job_ids: bfgtr = job_id + "gtrp1.bf" bf_maker_gtr.write_batch_file(dot_input=job_id + ".input", dot_aln=job_id + ".aln", hyphy_result_file=job_id + "gtrp1.result", hyphy_batch_file=bfgtr) bfnest = job_id + "nestp1.bf" bf_maker_nest.write_batch_file(dot_input=job_id + ".input", dot_aln=job_id + ".aln", hyphy_result_file=job_id + "nestp1.result", hyphy_batch_file=bfnest) for indexI, job_id in enumerate(job_ids): bf_maker_gtr.set_partition(51, seq_length[indexI]) bf_maker_nest.set_partition(51, seq_length[indexI]) bfgtr = job_id + "gtrp2.bf" bf_maker_gtr.write_batch_file(dot_input=job_id + ".input", dot_aln=job_id + ".aln", hyphy_result_file=job_id + "gtrp2.result", hyphy_batch_file=bfgtr) bfnest = job_id + "nestp2.bf" bf_maker_nest.write_batch_file(dot_input=job_id + ".input", dot_aln=job_id + ".aln", hyphy_result_file=job_id + "nestp2.result", hyphy_batch_file=bfnest)
def main(): # main part aln_files_folder = "d:/Workspace/Ecoli/ecoli_10_species" #aln_files_folder = "d:/Workspace/Ecoli/test" target_path = "d:/Workspace/Ecoli/NoGapP1" aln_files = [single_file for single_file in os.listdir(aln_files_folder) if ".aln" == os.path.splitext(single_file)[-1]] model_gtr = "rebuild_model.mdl" model_nest = "rna_full_length_structure.mdl" job_ids = [] seq_length = [] for aln in aln_files: aln_path_full = os.path.join(aln_files_folder, aln) gene_in_aln, length_in_aln = dh.aln_info(aln_path_full) seq_length.append(length_in_aln[0]) job_id = aln.split(".")[0] if 10 == len(gene_in_aln): # only those gene shared in 10 species job_ids.append(job_id) input_file_path_full = os.path.join(target_path, job_id + ".input") shutil.copyfile(aln_path_full, os.path.join(target_path, aln)) # write input file dh.aln2inputNogap(aln_path_full, input_file_path_full) # make bf file for full length no gap gtr and empirical model os.chdir(target_path) bf_maker_nest = BfH.HYPHYBatchFile(species_name="ecoli", model_file=model_nest, bf_template_file="templateNoGap") bf_maker_gtr = BfH.HYPHYBatchFile(species_name="ecoli", model_file=model_gtr, bf_template_file="templateNoGap") for job_id in job_ids: # aln_path_full = os.path.join(aln_files_folder,aln) # input_file_path_full = os.path.join(target_path, job_id + ".input") # shutil.copyfile(aln_path_full, os.path.join(target_path,aln)) # # write input file # dh.aln2inputNogap(aln_path_full, input_file_path_full) # make bf file for full length no gap gtr and empirical model bfgtr = job_id + "gtr.bf" bf_maker_gtr.write_batch_file(dot_input=job_id + ".input", dot_aln=job_id + ".aln", 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=job_id + ".aln", hyphy_result_file=job_id + "nest.result", hyphy_batch_file=bfnest) bf_maker_gtr.set_partition(0, 51) bf_maker_nest.set_partition(0, 51) for job_id in job_ids: bfgtr = job_id + "gtrp1.bf" bf_maker_gtr.write_batch_file(dot_input=job_id + ".input", dot_aln=job_id + ".aln", hyphy_result_file=job_id + "gtrp1.result", hyphy_batch_file=bfgtr) bfnest = job_id + "nestp1.bf" bf_maker_nest.write_batch_file(dot_input=job_id + ".input", dot_aln=job_id + ".aln", hyphy_result_file=job_id + "nestp1.result", hyphy_batch_file=bfnest) for indexI, job_id in enumerate(job_ids): bf_maker_gtr.set_partition(51, seq_length[indexI]) bf_maker_nest.set_partition(51, seq_length[indexI]) bfgtr = job_id + "gtrp2.bf" bf_maker_gtr.write_batch_file(dot_input=job_id + ".input", dot_aln=job_id + ".aln", hyphy_result_file=job_id + "gtrp2.result", hyphy_batch_file=bfgtr) bfnest = job_id + "nestp2.bf" bf_maker_nest.write_batch_file(dot_input=job_id + ".input", dot_aln=job_id + ".aln", hyphy_result_file=job_id + "nestp2.result", hyphy_batch_file=bfnest)