예제 #1
0
 def get_and_submit_bam_stats(self):
     from reademptionlib.readalignerstats import ReadAlignerStats
     get_bam_stats = ReadAlignerStats()
     total_aligned_reads = []
     total_uniquely_aligned_reads = []
     all_aligned_reads = []
     for sample_or_stats_total, sub_dic in (
             get_bam_stats.count(self._args.input_coverage, "NA")).items():
         for stats_total, value in sub_dic.items():
             if sample_or_stats_total == 'stats_total':
                 if stats_total == 'no_of_uniquely_aligned_reads':
                     total_uniquely_aligned_reads.append(value)
                 if stats_total == 'no_of_aligned_reads':
                     total_aligned_reads.append(value)
             else:
                 for align_type, Nr in value.items():
                     if align_type == 'no_of_aligned_reads':
                         all_aligned_reads.append(Nr)
     min_no_of_aligned_reads = min(all_aligned_reads)
     if not self._args.normalize_by_uniquely:
         no_of_aligned_reads = "".join([
             '{:.1f}'.format(x) for x in total_aligned_reads])
     else:
         no_of_aligned_reads = "".join([
             '{:.1f}'.format(x) for x in total_uniquely_aligned_reads])
     jobs = []
     with concurrent.futures.ProcessPoolExecutor(
             max_workers=self._args.processes) as executor:
         jobs.append(executor.submit(
             self.create_coverage_files_TK, float(no_of_aligned_reads),
             float(min_no_of_aligned_reads)))
     self._check_job_completeness(jobs)
예제 #2
0
 def _generate_read_alignment_stats(
     self,
     lib_names,
     result_bam_paths,
     unaligned_reads_paths,
     output_stats_path,
 ):
     """Manage the generation of alingment statistics."""
     raw_stat_data_writer = RawStatDataWriter(pretty=True)
     read_files_and_jobs = {}
     if not self._file_needs_to_be_created(output_stats_path):
         return
     with concurrent.futures.ProcessPoolExecutor(
             max_workers=self._args.processes) as executor:
         for (
                 lib_name,
                 read_alignment_bam_path,
                 unaligned_reads_path,
         ) in zip(lib_names, result_bam_paths, unaligned_reads_paths):
             read_aligner_stats = ReadAlignerStats()
             read_files_and_jobs[lib_name] = executor.submit(
                 read_aligner_stats.count,
                 read_alignment_bam_path,
                 unaligned_reads_path,
             )
     # Evaluate thread outcome
     self._check_job_completeness(read_files_and_jobs.values())
     read_files_and_stats = dict([
         (lib_name, job.result())
         for lib_name, job in read_files_and_jobs.items()
     ])
     raw_stat_data_writer.write(read_files_and_stats, output_stats_path)
예제 #3
0
 def generate_read_alignment_stats(
         self, filenames, BAM_files, output_path, output_file):
     """Manage the generation of alingment statistics."""
     raw_stat_data_writer = RawStatDataWriter(pretty=True)
     read_files_and_jobs = {}
     with concurrent.futures.ProcessPoolExecutor(
             max_workers=self._args.processes) as executor:
         for (filename, BAM_file) in zip(
                 filenames, BAM_files):
             read_aligner_stats = ReadAlignerStats()
             read_files_and_jobs[filename] = executor.submit(
                 read_aligner_stats.count, BAM_files, "NA")
     # Evaluate thread outcome
     self._helpers.check_job_completeness(read_files_and_jobs.values())
     read_files_and_stats = dict(
         [(filename, job.result())
          for filename, job in read_files_and_jobs.items()])
     raw_stat_data_writer.write(
         read_files_and_stats, output_file)