示例#1
0
def make_bf_TIR():
    workpath = "d:\Workspace\Ecoli\combinedP1"
    os.chdir(workpath)
    model_gtr = "rebuild_model.mdl"
    model_nest = "rna_full_length_structure.mdl"

    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")

    bf_maker_gtr.set_tree_from_outside(SS.ecoli())
    bf_maker_nest.set_tree_from_outside(SS.ecoli())

    for window_width_offset in range(15):
        length_window = 30 + 5*window_width_offset
        aln_files = "d:\Workspace\Ecoli\ecoli_10_species"

        extracted_input_file = workpath + "\TIR" + str(length_window) + ".input"
        gene_conjunction(aln_files, extracted_input_file, length_window)

        bf_maker_gtr.write_batch_file(dot_input="TIR%d.input" % length_window,
                                      dot_aln="",
                                      hyphy_batch_file="TIR%dgtr.bf" % length_window,
                                      hyphy_result_file="TIR%dgtr.result" % length_window)

        bf_maker_nest.write_batch_file(dot_input="TIR%d.input" % length_window,
                                       dot_aln="",
                                       hyphy_batch_file="TIR%dnest.bf" % length_window,
                                       hyphy_result_file="TIR%dnest.result" % length_window)
示例#2
0
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)
示例#3
0
def test_bf():
    bf1 = bf.HYPHYBatchFile(species_name="ecoli",
                            model_file="../rebuild_model.mdl",
                            bf_template_file="../pyHYPHY/templateNoGap")
    bf1.use_given_tree = True
    bf1.tree_definition_external = "(g1,g2)"

    bf1.write_batch_file("./tmp2.input", "./tmp.aln", "xxx.bf", "xxx.result")
示例#4
0
def sliding_window():
    workpath = "d:\Workspace\Ecoli\slidingWindow"
    os.chdir(workpath)
    model_gtr = "rebuild_model.mdl"
    model_nest = "rna_full_length_structure.mdl"

    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")

    bf_maker_gtr.set_tree_from_outside(SS.ecoli())
    bf_maker_nest.set_tree_from_outside(SS.ecoli())

    step_num = 15
    step_width_step = 5
    window_width_min = 30
    site_start_point = 0
    site_shift_step = 5
    for window_start_offset in range(step_num):
        for window_width_offset in range(step_num):

            start_site = site_shift_step*window_start_offset + site_start_point
            length_window = step_width_step*window_width_offset + window_width_min
            aln_files = "d:\Workspace\Ecoli\ecoli_10_species"

            # extracted_input_file = workpath + "\TIR" + str(length_window) + ".input"
            job_description = "w%ds%d" % (length_window, start_site)
            extracted_input_file = "%s\\TIR%s.input" % (workpath, job_description)
            print extracted_input_file

            gene_conjunction(aln_files, extracted_input_file, length_window, start_site)

            bf_maker_gtr.write_batch_file(dot_input="TIR%s.input" % job_description,
                                          dot_aln="",
                                          hyphy_batch_file="TIR%sgtr.bf" % job_description,
                                          hyphy_result_file="TIR%sgtr.result" % job_description)

            bf_maker_nest.write_batch_file(dot_input="TIR%s.input" % job_description,
                                           dot_aln="",
                                          hyphy_batch_file="TIR%snest.bf" % job_description,
                                          hyphy_result_file="TIR%snest.result" % job_description)
示例#5
0
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)
示例#6
0
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 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)
示例#8
0
def sliding_window():
    """perform a sliding window analysis over sequence alignment
"""
    workpath = "/Users/zerodel/WorkSpace/test/test_slidingWindow"

    # important here, has changed path.
    os.chdir(workpath)
    model_gtr = "rebuild_model.mdl"
    model_nest = "rna_full_length_structure.mdl"
    aln_files = "/Users/zerodel/WorkSpace/ecoli_aln"

    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")

    bf_maker_gtr.set_tree_from_outside(SS.ecoli())
    bf_maker_nest.set_tree_from_outside(SS.ecoli())

    step_num = 21
    step_width_step = 15
    window_width_min = 30
    site_start_point = 0
    site_shift_step = 15

    window_axis = [0,2]
    start_axis = range(step_num)

    for window_width_offset in window_axis:
        for window_start_offset in start_axis:

            start_site = site_shift_step*window_start_offset + site_start_point
            length_window = step_width_step*window_width_offset + window_width_min

            # extracted_input_file = workpath + "\TIR" + str(length_window) + ".input"
            job_description = "w%ds%d" % (length_window, start_site)
            extracted_input_file = "TIR%s.input" % job_description
            extracted_input_no_gap = "TIR%sN.input" % job_description

            gene_conjunction(aln_files, os.path.join(workpath, extracted_input_file), length_window, start_site)
            gene_conjunction(aln_files, os.path.join(workpath, extracted_input_no_gap), length_window, start_site, False)


            bf_maker_gtr.write_batch_file(dot_input=extracted_input_file,
                                          dot_aln="",
                                          hyphy_batch_file="TIR%sgtr.bf" % job_description,
                                          hyphy_result_file="TIR%sgtr.result" % job_description)

            bf_maker_nest.write_batch_file(dot_input=extracted_input_file,
                                           dot_aln="",
                                           hyphy_batch_file="TIR%snest.bf" % job_description,
                                           hyphy_result_file="TIR%snest.result" % job_description)



                # no gap
            bf_maker_gtr.write_batch_file(dot_input=extracted_input_no_gap,
                                          dot_aln="",
                                          hyphy_batch_file="TIR%sgtrN.bf" % job_description,
                                          hyphy_result_file="TIR%sgtrN.result" % job_description)

            bf_maker_nest.write_batch_file(dot_input=extracted_input_no_gap,
                                           dot_aln="",
                                           hyphy_batch_file="TIR%snestN.bf" % job_description,
                                           hyphy_result_file="TIR%snestN.result" % job_description)