def bamdiff(pair, out_prefix=None): """ takes two coordinate sorted BAM files and outputs only the records unique to each one. requires bamUtil to be installed: https://github.com/statgen/bamUtil """ out_dir = os.path.dirname(pair[0]) if not out_prefix: out_prefix = os.path.join(out_dir, "diff.bam") else: out_prefix = os.path.join(out_dir, out_prefix) def get_out_file(out_prefix, in_file, number): base, _ = os.path.splitext(out_prefix) in_base, in_ext = os.path.splitext(os.path.basename(in_file)) out_file = "_".join([base, "only" + str(number), in_base]) + in_ext return out_file if not is_pair(pair): raise ValueError("bamdiff needs to be run on a pair of input BAM " "files.") out_files = [get_out_file(out_prefix, y, x + 1) for x, y in enumerate(pair)] if all(map(file_exists, out_files)): return out_files sh.bam.diff("--in1", pair[0], "--in2", pair[1], "--out", out_prefix) return out_files
def __call__(self, in_file): self._start_message(in_file) if is_pair(in_file): out_file = [run(x, self.stage_config, self.config) for x in in_file] else: out_file = run(in_file, self.stage_config, self.config) self._end_message(in_file, out_file) return out_file
def __call__(self, in_file): self._start_message(in_file) if is_pair(in_file): out_file = run_with_config(in_file[0], in_file[1], self.ref, self.stage, self.config, gtf=self.gtf) else: out_file = run_with_config(in_file[0], None, self.ref, self.stage, self.config, gtf=self.gtf)
def __call__(self, in_file): if is_pair(in_file): out_files = self._run_pe(in_file) return out_files elif isinstance(in_file, str): out_file = self._run_se(in_file) return out_file elif len(in_file) == 1: out_file = self._run_se(in_file[0]) return out_file else: raise ValueError("Cutadapt can only run on either a single " "file as a string or a pair of files to " "handle paired end data.")
def __call__(self, in_file): if isinstance(in_file, basestring): logger.info("Detected %s as non-paired." % in_file) out_file = run_with_config(in_file, None, self.ref, self.stage, self.config) elif is_pair(in_file): logger.info("Detected %s as a pair." % in_file) out_file = run_with_config(in_file[0], in_file[1], self.ref, self.stage, self.config) else: logger.info("Detected %s as non-paired." % in_file) out_file = run_with_config(in_file[0], None, self.ref, self.stage, self.config) return out_file
def __call__(self, in_file): self._start_message(in_file) out_file = self.out_file(in_file) if file_exists(out_file): return out_file with file_transaction(out_file) as tmp_out_file: if is_pair(in_file): self._bowtie_pe(in_file, tmp_out_file) else: self._bowtie_se(in_file, tmp_out_file) self._end_message(in_file) return out_file
def out_file(self, in_file): if is_pair(in_file): return self._get_out_file(in_file[0]) else: return self._get_out_file(in_file)