当前位置: 首页>>代码示例>>Python>>正文


Python Multiparser.combine_wig方法代码示例

本文整理汇总了Python中annogesiclib.multiparser.Multiparser.combine_wig方法的典型用法代码示例。如果您正苦于以下问题:Python Multiparser.combine_wig方法的具体用法?Python Multiparser.combine_wig怎么用?Python Multiparser.combine_wig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在annogesiclib.multiparser.Multiparser的用法示例。


在下文中一共展示了Multiparser.combine_wig方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ArgsContainer

# 需要导入模块: from annogesiclib.multiparser import Multiparser [as 别名]
# 或者: from annogesiclib.multiparser.Multiparser import combine_wig [as 别名]
class ArgsContainer(object):

    def __init__(self):
        self.multiparser = Multiparser()
        self.helper = Helper()

    def _check_replicates(self, replicates_tex, replicates_frag):
        if (replicates_tex is not None) and (replicates_frag is not None):
            replicates = {"tex": int(replicates_tex),
                          "frag": int(replicates_frag)}
        elif replicates_tex is not None:
            replicates = {"tex": int(replicates_tex), "frag": -1}
        elif replicates_frag is not None:
            replicates = {"tex": -1, "frag": int(replicates_frag)}
        else:
            print("Error:No replicates number assign!!!")
            sys.exit()
        return replicates

    def _check_libs(self, tex_notex_libs, frag_libs):
        if (tex_notex_libs is None) and (frag_libs is None):
            print("Error: please input proper libraries!!")
        if (tex_notex_libs is not None) and (frag_libs is not None):
            libs = tex_notex_libs + frag_libs
        elif (tex_notex_libs is not None):
            libs = tex_notex_libs
        elif (frag_libs is not None):
            libs = frag_libs
        return libs

    def _parser_combine_wigs(self, subcommand):
        self.tex_path = None
        self.frag_path = None
        self.multiparser.parser_gff(self.gffs, None)
        if subcommand == "terminator":
            gff_path = os.path.join(self.gffs, "tmp")
            self.multiparser.parser_gff(gff_path, None)
        else:
            gff_path = self.gffs
        if self.tex_wigs is not None:
            self.tex_path = os.path.join(self.tex_wigs, "tmp")
            self.multiparser.parser_wig(self.tex_wigs)
            self.multiparser.combine_wig(gff_path, self.tex_path,
                                         None, self.libs)
            self.merge_wigs = self.tex_wigs
            self.wig_path = self.tex_path
        if self.frag_wigs is not None:
            self.frag_path = os.path.join(self.frag_wigs, "tmp")
            self.multiparser.parser_wig(self.frag_wigs)
            self.multiparser.combine_wig(gff_path, self.frag_path,
                                         None, self.libs)
            self.merge_wigs = self.frag_wigs
            self.wig_path = self.frag_path
        if (self.tex_path is not None) and (
                self.frag_path is not None):
            self = self._merge_wig()
        if (self.tex_path is None) and (
                self.frag_path is None):
            print("Error: There is no proper wig files assigned!!")
            sys.exit()
        return self

    def _merge_wig(self):
        self.merge_wigs = os.path.join(self.out_folder, "merge_wigs")
        if (self.tex_wigs is not None) and (
                self.frag_wigs is not None):
            self.helper.check_make_folder(self.merge_wigs)
            self.wig_path = os.path.join(self.merge_wigs, "tmp")
            self.helper.check_make_folder(self.wig_path)
            for wig in os.listdir(self.tex_wigs):
                if os.path.isfile(os.path.join(self.tex_wigs, wig)):
                    shutil.copy(os.path.join(self.tex_wigs, wig),
                                self.merge_wigs)
            for wig in os.listdir(self.frag_wigs):
                if os.path.isfile(os.path.join(self.frag_wigs, wig)):
                    shutil.copy(os.path.join(self.frag_wigs, wig),
                                self.merge_wigs)
            for wig in os.listdir(self.tex_path):
                if os.path.isfile(os.path.join(self.tex_path, wig)):
                    shutil.copy(os.path.join(self.tex_path, wig),
                                self.wig_path)
            for wig in os.listdir(self.frag_path):
                if os.path.isfile(os.path.join(self.frag_path, wig)):
                    self.helper.merge_file(os.path.join(self.frag_path, wig),
                                           os.path.join(self.wig_path, wig))
        elif (self.tex_wigs is not None):
            self.merge_wigs = self.tex_wigs
        elif (self.frag_wigs is not None):
            self.merge_wigs = self.frag_wigs
        return self

    def _deal_multi_inputs(self, inputs, file_type, num, command):
        if inputs is not None:
            datas = inputs.split(",")
            if num is not None:
                if (len(datas) != num):
                    print("Error: the amount of {0} is not correct!!".format(
                        command))
            new_inputs = []
            for data in datas:
#.........这里部分代码省略.........
开发者ID:malvikasharan,项目名称:ANNOgesic,代码行数:103,代码来源:args_container.py

示例2: TSSpredator

# 需要导入模块: from annogesiclib.multiparser import Multiparser [as 别名]
# 或者: from annogesiclib.multiparser.Multiparser import combine_wig [as 别名]

#.........这里部分代码省略.........
                    if tss.endswith("_processing.gff"):
                        ref = self.helper.get_correct_file(
                                args_tss.overlap_gffs, "_TSS.gff",
                                tss.replace("_processing.gff", ""), None, None)
                        filter_tss_pro(os.path.join(out_folder, tss),
                                       ref, args_tss.program,
                                       args_tss.cluster)

    def _low_expression(self, args_tss, gff_folder):
        '''deal with the low expressed TSS'''
        prefix = None
        self._merge_wigs(args_tss.wig_folder, "wig", args_tss.libs)
        for gff in os.listdir(gff_folder):
            if (args_tss.program.lower() == "tss") and (
                    gff.endswith("_TSS.gff")):
                prefix = gff.replace("_TSS.gff", "")
            elif (args_tss.program.lower() == "processing") and (
                    gff.endswith("_processing.gff")):
                prefix = gff.replace("_processing.gff", "")
            if prefix:
                out = open(os.path.join(
                    self.stat_outfolder, prefix, "_".join([
                        "stat", prefix, "low_expression_cutoff.csv"])), "w")
                out.write("\t".join(["Genome", "Cutoff_coverage"]) + "\n")
                cutoff = filter_low_expression(
                        os.path.join(gff_folder, gff), args_tss,
                        "tmp/merge_forward.wig", "tmp/merge_reverse.wig",
                        "tmp/without_low_expression.gff")
                out.write("\t".join([prefix, str(cutoff)]) + "\n")
                os.remove(os.path.join(gff_folder, gff))
                shutil.move("tmp/without_low_expression.gff",
                            os.path.join(gff_folder, gff))
                prefix = None
        out.close()

    def run_tsspredator(self, args_tss, log):
        input_folder = os.path.join(args_tss.out_folder, "configs")
        for gff in os.listdir(args_tss.gffs):
            if gff.endswith(".gff"):
                self.helper.check_uni_attributes(os.path.join(
                                                 args_tss.gffs, gff))
        self.helper.check_make_folder(self.gff_outfolder)
        self.multiparser.parser_fasta(args_tss.fastas)
        self.multiparser.parser_gff(args_tss.gffs, None)
        self.multiparser.parser_wig(args_tss.wig_folder)
        prefixs = self._set_gen_config(args_tss, input_folder, log)
        for prefix in prefixs:
            out_path = os.path.join(
                    self.master, "_".join(["MasterTable", prefix]))
            config_file = os.path.join(
                    input_folder, "_".join(["config", prefix]) + ".ini")
            self._start_to_run(args_tss.tsspredator_path, config_file,
                               out_path, prefix, log)
            if os.path.exists(os.path.join(out_path, "TSSstatistics.tsv")):
                shutil.move(os.path.join(out_path, "TSSstatistics.tsv"),
                            os.path.join(
                                self.stat_outfolder, "TSSstatistics.tsv"))
        if args_tss.program.lower() == "ps":
            args_tss.program = "processing"
        self._convert_gff(prefixs, args_tss, log)
        if args_tss.check_orphan:
            print("checking the orphan TSSs")
            log.write("Running check_orphan.py to re-check orphan TSSs.\n")
            self._check_orphan(prefixs,
                               os.path.join(args_tss.wig_folder, "tmp"),
                               args_tss)
        self.multiparser.combine_gff(args_tss.gffs, self.gff_outfolder,
                                     None, args_tss.program)
        datas = []
        for gff in os.listdir(self.gff_outfolder):
            if gff.endswith(".gff"):
                gff_folder = gff.replace("".join(["_", args_tss.program,
                                                  ".gff"]), "")
                self.helper.check_make_folder(
                     os.path.join(self.stat_outfolder, gff_folder))
                datas.append(gff_folder)
        if args_tss.remove_low_expression is not None:
            log.write("Running filter_low_expression.py to filter out "
                      "low expressed TSS/PS.\n")
            self._low_expression(args_tss, self.gff_outfolder)
        if args_tss.manual is not None:
            self.multiparser.parser_gff(args_tss.manual, None)
            self.multiparser.combine_gff(args_tss.gffs, self.manual_path,
                                         None, None)
            self.multiparser.combine_fasta(args_tss.gffs, self.fasta_path,
                                         None)
            self.multiparser.combine_wig(args_tss.gffs, self.wig_path,
                                         None, args_tss.libs)
            log.write("Running merge_manual.py to merge the manual TSSs.\n")
            self._merge_manual(datas, args_tss)
        log.write("Running filter_TSS_pro.py to deal with the overlap "
                  "position between TSS and PS.\n")
        self._deal_with_overlap(self.gff_outfolder, args_tss)
        log.write("Running stat_TSSpredator.py to do statistics.\n")
        self._stat_tss(datas, args_tss.program, log)
        if args_tss.validate:
            self._validate(datas, args_tss, log)
        if args_tss.ta_files is not None:
            self._compare_ta(datas, args_tss, log)
        self._remove_files(args_tss)
开发者ID:Sung-Huan,项目名称:ANNOgesic,代码行数:104,代码来源:tsspredator.py

示例3: TestMultiparser

# 需要导入模块: from annogesiclib.multiparser import Multiparser [as 别名]
# 或者: from annogesiclib.multiparser.Multiparser import combine_wig [as 别名]
class TestMultiparser(unittest.TestCase):

    def setUp(self):
        self.multiparser = Multiparser()
        self.example = Example()
        self.ref_folder = "ref_folder"
        if (not os.path.exists(self.ref_folder)):
            os.mkdir(self.ref_folder)
        self.tar_folder = "tar_folder"
        if (not os.path.exists(self.tar_folder)):
            os.mkdir(self.tar_folder)

    def tearDown(self):
        if os.path.exists(self.ref_folder):
            shutil.rmtree(self.ref_folder)
        if os.path.exists(self.tar_folder):
            shutil.rmtree(self.tar_folder)

    def test_combine_fasta(self):
        tmp_tar = os.path.join(self.tar_folder, "tmp")
        tmp_ref = os.path.join(self.ref_folder, "test.gff_folder")
        os.mkdir(tmp_ref)
        os.mkdir(tmp_tar)
        sub_fasta1 = os.path.join(tmp_tar, "aaa.fa")
        with open(sub_fasta1, "w") as rh:
            rh.write(self.example.sub_fasta1)
        sub_fasta2 = os.path.join(tmp_tar, "bbb.fa")
        with open(sub_fasta2, "w") as rh:
            rh.write(self.example.sub_fasta2)
        sub_gff1 = os.path.join(tmp_ref, "aaa.gff")
        with open(sub_gff1, "w") as rh:
            rh.write(self.example.sub_gff1)
        sub_gff2 = os.path.join(tmp_ref, "bbb.gff")
        with open(sub_gff2, "w") as rh:
            rh.write(self.example.sub_gff2)
        self.multiparser.combine_fasta(self.ref_folder, tmp_tar, None)
        self.assertTrue(os.path.exists(os.path.join(tmp_tar, "test.fa")))

    def test_combine_wig(self):
        tmp_tar = os.path.join(self.tar_folder, "tmp")
        tmp_ref = os.path.join(self.ref_folder, "test.fa_folder")
        os.mkdir(tmp_ref)
        os.mkdir(tmp_tar)
        sub_fasta1 = os.path.join(tmp_ref, "aaa.fa")
        with open(sub_fasta1, "w") as rh:
            rh.write(self.example.sub_fasta1)
        sub_fasta2 = os.path.join(tmp_ref, "bbb.fa")
        with open(sub_fasta2, "w") as rh:
            rh.write(self.example.sub_fasta2)
        sub_wig1 = os.path.join(tmp_tar, "test_forward.wig_STRAIN_aaa.wig")
        sub_wig2 = os.path.join(tmp_tar, "test_forward.wig_STRAIN_bbb.wig")
        sub_wig3 = os.path.join(tmp_tar, "test_reverse.wig_STRAIN_aaa.wig")
        sub_wig4 = os.path.join(tmp_tar, "test_reverse.wig_STRAIN_bbb.wig")
        wig_files = [sub_wig1, sub_wig2, sub_wig3, sub_wig4]
        example_wigs = [self.example.sub_f_wig1, self.example.sub_f_wig2,
                        self.example.sub_r_wig1, self.example.sub_r_wig2]
        for index in range(0, 4):
            with open(wig_files[index], "w") as fh:
                fh.write(example_wigs[index])
        libs = ["test_forward.wig_STRAIN_aaa.wig:frag:1:a:+", "test_reverse.wig_STRAIN_aaa.wig:frag:1:a:-"]
        self.multiparser.combine_wig(self.ref_folder, tmp_tar, "fasta", libs)
        self.assertTrue(os.path.exists(os.path.join(tmp_tar, "test_forward.wig")))
        self.assertTrue(os.path.exists(os.path.join(tmp_tar, "test_reverse.wig")))

    def test_combine_gff(self):
        tmp_tar = os.path.join(self.tar_folder, "tmp")
        tmp_ref = os.path.join(self.ref_folder, "test.fa_folder")
        os.mkdir(tmp_ref)
        os.mkdir(tmp_tar)
        sub_fasta1 = os.path.join(tmp_ref, "aaa.fa")
        with open(sub_fasta1, "w") as rh:
            rh.write(self.example.sub_fasta1)
        sub_fasta2 = os.path.join(tmp_ref, "bbb.fa")
        with open(sub_fasta2, "w") as rh:
            rh.write(self.example.sub_fasta2)
        sub_gff1 = os.path.join(tmp_tar, "aaa.gff")
        with open(sub_gff1, "w") as rh:
            rh.write(self.example.sub_gff1)
        sub_gff2 = os.path.join(tmp_tar, "bbb.gff")
        with open(sub_gff2, "w") as rh:
            rh.write(self.example.sub_gff2)
        self.multiparser.combine_gff(self.ref_folder, tmp_tar, "fasta", None)
        self.assertTrue(os.path.exists(os.path.join(tmp_tar, "test.gff")))

    def test_parser_fasta(self):
        fasta_file = os.path.join(self.ref_folder, "test.fa")
        with open(fasta_file, "w") as rh:
            rh.write(self.example.fasta_file)
        self.multiparser.parser_fasta(self.ref_folder)
        self.assertTrue(os.path.exists(os.path.join(self.ref_folder, "tmp/aaa.fa")))
        self.assertTrue(os.path.exists(os.path.join(self.ref_folder, "tmp/bbb.fa")))
        self.assertTrue(os.path.exists(os.path.join(self.ref_folder, "test.fa_folder/aaa.fa")))
        self.assertTrue(os.path.exists(os.path.join(self.ref_folder, "test.fa_folder/bbb.fa")))

    def test_parser_gff(self):
        gff_file = os.path.join(self.ref_folder, "test.gff")
        with open(gff_file, "w") as rh:
            rh.write(self.example.gff_file)
        self.multiparser.parser_gff(self.ref_folder, None)
        self.assertTrue(os.path.exists(os.path.join(self.ref_folder, "tmp/aaa.gff")))
#.........这里部分代码省略.........
开发者ID:malvikasharan,项目名称:ANNOgesic,代码行数:103,代码来源:test_multiparser.py

示例4: TSSpredator

# 需要导入模块: from annogesiclib.multiparser import Multiparser [as 别名]
# 或者: from annogesiclib.multiparser.Multiparser import combine_wig [as 别名]

#.........这里部分代码省略.........
            print("Comparing TSS and Processing site...")
            if args_tss.program.lower() == "tss":
                for tss in os.listdir(out_folder):
                    if tss.endswith("_TSS.gff"):
                        ref = self.helper.get_correct_file(
                                args_tss.references, "_processing.gff",
                                tss.replace("_TSS.gff", ""), None, None)
                        filter_tss_pro(os.path.join(out_folder, tss),
                                       ref, args_tss.overlap_feature,
                                       args_tss.cluster)
            elif args_tss.program.lower() == "processing_site":
                for tss in os.listdir(out_folder):
                    if tss.endswith("_processing.gff"):
                        ref = self.helper.get_correct_file(
                                args_tss.references, "_TSS.gff",
                                tss.replace("_processing.gff", ""), None, None)
                        filter_tss_pro(os.path.join(out_folder, tss),
                                       ref, args_tss.overlap_feature,
                                       args_tss.cluster)

    def _low_expression(self, args_tss, gff_folder):
        prefix = None
        self._merge_wigs(args_tss.wig_folder, "wig", args_tss.libs)
        for gff in os.listdir(gff_folder):
            if (args_tss.program.lower() == "tss") and (
                    gff.endswith("_TSS.gff")):
                prefix = gff.replace("_TSS.gff", "")
            elif (args_tss.program.lower() == "processing") and (
                    gff.endswith("_processing.gff")):
                prefix = gff.replace("_processing.gff", "")
            if prefix:
                out = open(os.path.join(
                    self.stat_outfolder, prefix, "_".join([
                        "stat", prefix, "low_expression_cutoff.csv"])), "w")
                out.write("\t".join(["strain", "cutoff_coverage"]) + "\n")
                cutoff = filter_low_expression(
                        os.path.join(gff_folder, gff), args_tss,
                        "tmp/merge_forward.wig", "tmp/merge_reverse.wig",
                        "tmp/without_low_expression.gff")
                out.write("\t".join([prefix, str(cutoff)]) + "\n")
                os.remove(os.path.join(gff_folder, gff))
                shutil.move("tmp/without_low_expression.gff",
                            os.path.join(gff_folder, gff))
                prefix = None
        out.close()

    def run_tsspredator(self, args_tss):
        input_folder = os.path.join(args_tss.out_folder, "configs")
        for gff in os.listdir(args_tss.gffs):
            if gff.endswith(".gff"):
                self.helper.check_uni_attributes(os.path.join(
                                                 args_tss.gffs, gff))
        self.helper.check_make_folder(self.gff_outfolder)
        self.multiparser.parser_fasta(args_tss.fastas)
        self.multiparser.parser_gff(args_tss.gffs, None)
        self.multiparser.parser_wig(args_tss.wig_folder)
        prefixs = self._set_gen_config(args_tss, input_folder)
        for prefix in prefixs:
            out_path = os.path.join(
                    self.master, "_".join(["MasterTable", prefix]))
            config_file = os.path.join(
                    input_folder, "_".join(["config", prefix]) + ".ini")
            self._start_to_run(args_tss.tsspredator_path, config_file,
                               out_path, prefix)
            if os.path.exists(os.path.join(out_path, "TSSstatistics.tsv")):
                shutil.move(os.path.join(out_path, "TSSstatistics.tsv"),
                            os.path.join(
                                self.stat_outfolder, "TSSstatistics.tsv"))
        if args_tss.program.lower() == "processing_site":
            args_tss.program = "processing"
        self._convert_gff(prefixs, args_tss)
        if args_tss.check_orphan:
            print("checking the orphan TSS...")
            self._check_orphan(prefixs,
                               os.path.join(args_tss.wig_folder, "tmp"),
                               args_tss)
        self.multiparser.combine_gff(args_tss.gffs, self.gff_outfolder,
                                     None, args_tss.program)
        datas = []
        for gff in os.listdir(self.gff_outfolder):
            if gff.endswith(".gff"):
                gff_folder = gff.replace("".join(["_", args_tss.program,
                                                  ".gff"]), "")
                self.helper.check_make_folder(
                     os.path.join(self.stat_outfolder, gff_folder))
                datas.append(gff_folder)
        if args_tss.remove_low_expression is not None:
            self._low_expression(args_tss, self.gff_outfolder)
        if args_tss.manual is not None:
            self.multiparser.combine_wig(args_tss.gffs, self.wig_path,
                                         None, args_tss.libs)
            self._merge_manual(datas, args_tss)
        self._deal_with_overlap(self.gff_outfolder, args_tss)
        if args_tss.stat:
            self._stat_tss(datas, args_tss.program)
        if args_tss.validate:
            self._validate(datas, args_tss)
        if args_tss.ta_files is not None:
            self._compare_ta(datas, args_tss)
        self._remove_files(args_tss)
开发者ID:malvikasharan,项目名称:ANNOgesic,代码行数:104,代码来源:tsspredator.py


注:本文中的annogesiclib.multiparser.Multiparser.combine_wig方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。