Ejemplo n.º 1
0
 def call_trim_galore(self):
     try:
         trimmer = TrimGalore(self.dir_info.first,
                              self.dir_info.second,
                              self.dir_info.trim_galore_output_dir)
         run_shell_command(trimmer.generate_command())
     except:
         raise Exception("Couldn't trim galore for mate " + self.name() + "! Please inspect the log file")
Ejemplo n.º 2
0
 def extract_methylation(self):
     try:
         extractor = BismarkMethylationExtractor(
             self.dir_info.deduplicated_bam_path, self.dir_info.bismark_methylation_extractor_output_dir
         )
         command = extractor.bismark_met_extractor_command()
         run_shell_command(command)
     except:
         raise Exception("Couldn't extract methylation for mate " + self.name + "! Please inspect the log file")
Ejemplo n.º 3
0
 def merge_aligned_bams(self):
     files = self.dir_info.list_aligned_bam_files()
     output_file = self.dir_info.aligned_bam_path
     if len(files) > 1:
         command = samtools_merge_files_command(output_file, files)
         print(command, file=self.log_file_handler)
         run_shell_command(command, redirect_output_path=self.dir_info.analysis_log_path, append=True)
     else:
         print("Only one bam file, skipping merging", file = self.log_file_handler)
         shutil.copyfile(files[0], output_file)
Ejemplo n.º 4
0
 def call_bismark(self):
     try:
         bismark = BismarkAligner(self.dir_info.first_mate_trimmed_file_path,
                                  self.dir_info.second_mate_trimmed_file_path,
                                  self.dir_info.bismark_output_dir,
                                  self.dir_info.bismark_output_dir)
         command = bismark.generate_command()
         run_shell_command(command)
     except:
         raise Exception("Couldn't use bismark for mate " + self.name() + ", please inspect the log file")
Ejemplo n.º 5
0
    def extract_methylation(self):
        for file_path in os.listdir(self.dir_info.splitted_dir):
            file_path = os.path.join(self.dir_info.splitted_dir, file_path)
            extractor = BismarkMethylationExtractor(file_path,
                                                    self.dir_info.bismark_methylation_extractor_output_dir,
                                                    ncores=45)
            command = extractor.bismark_met_extractor_command()

            # perform logging
            print("*************************************", file=self.log_file_handler)
            print("This is how the extractor will be called: ", file=self.log_file_handler)
            print(command, file=self.log_file_handler)
            print("", file=self.log_file_handler)
            print("Logging extractor output to: " + extractor.log_file_path(), file=self.log_file_handler)
            print("*************************************", file=self.log_file_handler)
            print("", file=self.log_file_handler)
            print("", file=self.log_file_handler)

            # close log, because bismark likes to write to stderr and python doesnt' like it
            self.log_file_handler.close()

            # call thea actual command
            output = run_shell_command(command)

            # reopen log
            self.log_file_handler = open(self.dir_info.analysis_log_path, mode='a')
Ejemplo n.º 6
0
 def split_bam_by_chromosome(self):
     input_file_path = self.latest_processed_file()
     command = split_by_chromosome_command(input_file_path, self.dir_info.splitted_dir)
     print(command, file=self.log_file_handler)
     run_shell_command(command, redirect_output_path=self.dir_info.analysis_log_path, append=True)
Ejemplo n.º 7
0
 def filter_quality(self):
     input_file_path = self.latest_processed_file()
     command = bamtools_clean_command(input_file_path, self.dir_info.filtered_bam_path)
     print(command, file=self.log_file_handler)
     run_shell_command(command, redirect_output_path=self.dir_info.analysis_log_path, append=True)
Ejemplo n.º 8
0
 def call_deduplicate(self):
     try:
         command_str = deduplicate_bismark_command_str(self.dir_info.aligned_bam_path)
         run_shell_command(command_str)
     except:
         raise Exception("Couldn't deduplicate for mate " + self.name + "! Please inspect the log file")