Пример #1
0
 def _merge_results(self, args_ribo, scan_folder, suffixs, tmp_files,
                    table_folder, stat_folder, feature_id, gff_outfolder,
                    feature, log):
     '''merge the results from the results of two searching'''
     for gff in os.listdir(args_ribo.gffs):
         if gff.endswith(".gff"):
             prefix = gff.replace(".gff", "")
             print("Merging results of {0}".format(prefix))
             pre_strain = ""
             self.helper.check_make_folder(os.path.join(
                                           scan_folder, prefix))
             fh = open(os.path.join(args_ribo.gffs, gff))
             log.write("Merging the results from Infernal to generate "
                       "tables for {0}.\n".format(prefix))
             for entry in self.gff_parser.entries(fh):
                 if entry.seq_id != pre_strain:
                     if len(pre_strain) == 0:
                         shutil.copyfile(os.path.join(
                             tmp_files["table"],
                             "_".join([entry.seq_id, suffixs["csv"]])),
                             os.path.join(
                                 table_folder,
                                 "_".join([prefix, suffixs["csv"]])))
                     else:
                         self.helper.merge_file(os.path.join(
                             tmp_files["table"],
                             "_".join([entry.seq_id, suffixs["csv"]])),
                             os.path.join(
                                 table_folder,
                                 "_".join([prefix, suffixs["csv"]])))
                     shutil.copy(os.path.join(
                         tmp_files["scan"],
                         "_".join([entry.seq_id, suffixs["txt"]])),
                         os.path.join(scan_folder, prefix))
                     shutil.copy(os.path.join(
                         tmp_files["scan"],
                         "_".join([entry.seq_id, suffixs["re_txt"]])),
                         os.path.join(scan_folder, prefix))
                     pre_strain = entry.seq_id
             log.write("The following files are generated.\n")
             for folder in (table_folder, scan_folder):
                 for file_ in os.listdir(folder):
                     log.write("\t" + os.path.join(folder, file_) + "\n")
             out_stat = os.path.join(
                     stat_folder,
                     "_".join(["stat", prefix, feature + ".txt"]))
             print("Computing statistics of {0}".format(prefix))
             log.write("Running ribo_gff.py to do statistics and generate "
                       "gff files for {0}.\n".format(prefix))
             log.write("The following files are generated:\n")
             out_gff = os.path.join(gff_outfolder, "_".join([
                prefix, feature + ".gff"]))
             stat_and_covert2gff(os.path.join(
                 table_folder, "_".join([prefix, suffixs["csv"]])),
                 feature_id, out_gff,
                 args_ribo.fuzzy, out_stat, feature)
             log.write("\t" + out_gff + "\n")
             log.write("\t" + out_stat + "\n")
             fh.close()
Пример #2
0
 def test_stat_and_covert2gff(self):
     ribo_table = os.path.join(self.test_folder, "ribo")
     rfam_table = os.path.join(self.test_folder, "rfam")
     gen_file(ribo_table, self.example.table)
     gen_file(rfam_table, self.example.rfam)
     gff_file = os.path.join(self.test_folder, "gff")
     out_stat = os.path.join(self.test_folder, "stat")
     rg.stat_and_covert2gff(ribo_table, rfam_table, gff_file, 3, out_stat, "riboswitch")
     data = import_data(gff_file)
     self.assertEqual("\n".join(data), self.example.out_gff)
Пример #3
0
 def test_stat_and_covert2gff(self):
     ribo_table = os.path.join(self.test_folder, "ribo")
     rfam_table = os.path.join(self.test_folder, "rfam")
     gen_file(ribo_table, self.example.table)
     gen_file(rfam_table, self.example.rfam)
     gff_file = os.path.join(self.test_folder, "gff")
     out_stat = os.path.join(self.test_folder, "stat")
     rg.stat_and_covert2gff(ribo_table, rfam_table, gff_file,
                            3, out_stat, "riboswitch")
     data = import_data(gff_file)
     self.assertEqual("\n".join(data), self.example.out_gff)
Пример #4
0
 def _merge_results(self, args_ribo, scan_folder, suffixs, tmp_files,
                    table_folder, stat_folder, feature_id, gff_outfolder,
                    feature):
     '''merge the results from the results of two searching'''
     for gff in os.listdir(args_ribo.gffs):
         if gff.endswith(".gff"):
             prefix = gff.replace(".gff", "")
             print("Merging results of {0}".format(prefix))
             pre_strain = ""
             self.helper.check_make_folder(os.path.join(
                 scan_folder, prefix))
             fh = open(os.path.join(args_ribo.gffs, gff))
             for entry in self.gff_parser.entries(fh):
                 if entry.seq_id != pre_strain:
                     if len(pre_strain) == 0:
                         shutil.copyfile(
                             os.path.join(
                                 tmp_files["table"],
                                 "_".join([entry.seq_id, suffixs["csv"]])),
                             os.path.join(
                                 table_folder,
                                 "_".join([prefix, suffixs["csv"]])))
                     else:
                         self.helper.merge_file(
                             os.path.join(
                                 tmp_files["table"],
                                 "_".join([entry.seq_id, suffixs["csv"]])),
                             os.path.join(
                                 table_folder,
                                 "_".join([prefix, suffixs["csv"]])))
                     shutil.copy(
                         os.path.join(
                             tmp_files["scan"],
                             "_".join([entry.seq_id, suffixs["txt"]])),
                         os.path.join(scan_folder, prefix))
                     shutil.copy(
                         os.path.join(
                             tmp_files["scan"],
                             "_".join([entry.seq_id, suffixs["re_txt"]])),
                         os.path.join(scan_folder, prefix))
                     pre_strain = entry.seq_id
             out_stat = os.path.join(
                 stat_folder, "_".join(["stat", prefix, feature + ".txt"]))
             print("Computing statistics of {0}".format(prefix))
             stat_and_covert2gff(
                 os.path.join(table_folder,
                              "_".join([prefix,
                                        suffixs["csv"]])), feature_id,
                 os.path.join(gff_outfolder,
                              "_".join([prefix, feature + ".gff"])),
                 args_ribo.fuzzy, out_stat, feature)
             fh.close()
Пример #5
0
 def _merge_results(self, args_ribo):
     for gff in os.listdir(args_ribo.gffs):
         if gff.endswith(".gff"):
             prefix = gff.replace(".gff", "")
             print("Merge results of {0}".format(prefix))
             pre_strain = ""
             self.helper.check_make_folder(
                 os.path.join(self.scan_folder, prefix))
             fh = open(os.path.join(args_ribo.gffs, gff))
             for entry in self.gff_parser.entries(fh):
                 if entry.seq_id != pre_strain:
                     if len(pre_strain) == 0:
                         shutil.copyfile(
                             os.path.join(
                                 self.tmp_files["table"], "_".join(
                                     [entry.seq_id, self.suffixs["csv"]])),
                             os.path.join(
                                 self.table_folder,
                                 "_".join([prefix, self.suffixs["csv"]])))
                     else:
                         self.helper.merge_file(
                             os.path.join(
                                 self.tmp_files["table"], "_".join(
                                     [entry.seq_id, self.suffixs["csv"]])),
                             os.path.join(
                                 self.table_folder,
                                 "_".join([prefix, self.suffixs["csv"]])))
                     shutil.copy(
                         os.path.join(
                             self.tmp_files["scan"],
                             "_".join([entry.seq_id, self.suffixs["txt"]])),
                         os.path.join(self.scan_folder, prefix))
                     shutil.copy(
                         os.path.join(
                             self.tmp_files["scan"], "_".join(
                                 [entry.seq_id, self.suffixs["re_txt"]])),
                         os.path.join(self.scan_folder, prefix))
                     pre_strain = entry.seq_id
             out_stat = os.path.join(
                 self.stat_folder,
                 "_".join(["stat", prefix, "riboswitch.txt"]))
             print("compute statistics of {0}".format(prefix))
             stat_and_covert2gff(
                 os.path.join(self.table_folder,
                              "_".join([prefix, self.suffixs["csv"]])),
                 args_ribo.ribos_id,
                 os.path.join(self.gff_outfolder,
                              "_".join([prefix, "riboswitch.gff"])),
                 args_ribo.fuzzy, out_stat)
             fh.close()
Пример #6
0
 def _merge_results(self, args_ribo):
     for gff in os.listdir(args_ribo.gffs):
         if gff.endswith(".gff"):
             prefix = gff.replace(".gff", "")
             print("Merge results of {0}".format(prefix))
             pre_strain = ""
             self.helper.check_make_folder(os.path.join(
                                           self.scan_folder, prefix))
             fh = open(os.path.join(args_ribo.gffs, gff))
             for entry in self.gff_parser.entries(fh):
                 if entry.seq_id != pre_strain:
                     if len(pre_strain) == 0:
                         shutil.copyfile(os.path.join(
                             self.tmp_files["table"],
                             "_".join([entry.seq_id, self.suffixs["csv"]])),
                             os.path.join(
                                 self.table_folder,
                                 "_".join([prefix, self.suffixs["csv"]])))
                     else:
                         self.helper.merge_file(os.path.join(
                             self.tmp_files["table"],
                             "_".join([entry.seq_id, self.suffixs["csv"]])),
                             os.path.join(
                                 self.table_folder,
                                 "_".join([prefix, self.suffixs["csv"]])))
                     shutil.copy(os.path.join(
                         self.tmp_files["scan"],
                         "_".join([entry.seq_id, self.suffixs["txt"]])),
                         os.path.join(self.scan_folder, prefix))
                     shutil.copy(os.path.join(
                         self.tmp_files["scan"],
                         "_".join([entry.seq_id, self.suffixs["re_txt"]])),
                         os.path.join(self.scan_folder, prefix))
                     pre_strain = entry.seq_id
             out_stat = os.path.join(
                     self.stat_folder,
                     "_".join(["stat", prefix, "riboswitch.txt"]))
             print("compute statistics of {0}".format(prefix))
             stat_and_covert2gff(os.path.join(
                 self.table_folder,
                 "_".join([prefix, self.suffixs["csv"]])),
                 args_ribo.ribos_id, os.path.join(
                     self.gff_outfolder,
                     "_".join([prefix, "riboswitch.gff"])),
                 args_ribo.fuzzy, out_stat)
             fh.close()
Пример #7
0
 def _merge_results(self, args_ribo, scan_folder, suffixs, tmp_files,
                    table_folder, stat_folder, feature_id, gff_outfolder,
                    feature, log):
     '''merge the results from the results of two searching'''
     for gff in os.listdir(args_ribo.gffs):
         if gff.endswith(".gff"):
             prefix = gff.replace(".gff", "")
             print("Merging results of {0}".format(prefix))
             pre_strain = ""
             self.helper.check_make_folder(os.path.join(
                 scan_folder, prefix))
             fh = open(os.path.join(args_ribo.gffs, gff))
             log.write("Merging the results from Infernal to generate "
                       "tables for {0}.\n".format(prefix))
             for entry in self.gff_parser.entries(fh):
                 if entry.seq_id != pre_strain:
                     if len(pre_strain) == 0:
                         shutil.copyfile(
                             os.path.join(
                                 tmp_files["table"],
                                 "_".join([entry.seq_id, suffixs["csv"]])),
                             os.path.join(
                                 table_folder,
                                 "_".join([prefix, suffixs["csv"]])))
                     else:
                         self.helper.merge_file(
                             os.path.join(
                                 tmp_files["table"],
                                 "_".join([entry.seq_id, suffixs["csv"]])),
                             os.path.join(
                                 table_folder,
                                 "_".join([prefix, suffixs["csv"]])))
                     shutil.copy(
                         os.path.join(
                             tmp_files["scan"],
                             "_".join([entry.seq_id, suffixs["txt"]])),
                         os.path.join(scan_folder, prefix))
                     shutil.copy(
                         os.path.join(
                             tmp_files["scan"],
                             "_".join([entry.seq_id, suffixs["re_txt"]])),
                         os.path.join(scan_folder, prefix))
                     pre_strain = entry.seq_id
             log.write("The following files are generated.\n")
             for folder in (table_folder, scan_folder):
                 for file_ in os.listdir(folder):
                     log.write("\t" + os.path.join(folder, file_) + "\n")
             out_stat = os.path.join(
                 stat_folder, "_".join(["stat", prefix, feature + ".txt"]))
             print("Computing statistics of {0}".format(prefix))
             log.write("Running ribo_gff.py to do statistics and generate "
                       "gff files for {0}.\n".format(prefix))
             log.write("The following files are generated:\n")
             out_gff = os.path.join(gff_outfolder,
                                    "_".join([prefix, feature + ".gff"]))
             stat_and_covert2gff(
                 os.path.join(table_folder,
                              "_".join([prefix, suffixs["csv"]])),
                 feature_id, out_gff, args_ribo.fuzzy, out_stat, feature)
             log.write("\t" + out_gff + "\n")
             log.write("\t" + out_stat + "\n")
             fh.close()