def __init__(self, chromosome, build="mm9", resolution=1000000, downweighting="none"): """Constructs an instance of the Contacts class. Args: chromosome (str): The chromosome to visualize, or "genome" for an interchromosomal heatmap. build (str): The genome assembly. resolution (int): The resolution of the heatmap, in bp. downweighting (str): The downweighting scheme. """ self._chromosome = chromosome self._resolution = resolution self._assembly = assembly.build(build, resolution) if downweighting == "none": self._downweighting = Downweighting.NONE elif downweighting == "n_minus_one": self._downweighting = Downweighting.N_MINUS_ONE elif downweighting == "n_over_two": self._downweighting = Downweighting.N_OVER_TWO else: self._downweighting = Downweighting.UNKNOWN if self._chromosome == "genome": self.init_genome_matrix() else: self.init_chromosome_matrix()
def main(): args = parse_arguments() contacts = np.loadtxt(args.heatmap) resolution = args.resolution assem = assembly.build(args.assembly, resolution) hubfile = args.hub compute_hub_avgs_and_print(contacts, hubfile, assem)
def filter_reads(args): '''Filter bam Params: args: argparse arguments Notes: Will filter reads without a full barcode, will remove alt chromosome and MT and if aligned with ensembl (1, 2, ..., X, Y) will change chromosomes to ucsc scheme (chr1, chr2, ..., chrX, chrY) ''' if args.assembly != 'none': #filter out reads that do not map to main assembly chroms = list(assembly.build(args.assembly, 1)._chromsizes.keys()) #add chr to bam header bam_header = add_chr_to_bam_header(args.input, chroms) # with pysam.AlignmentFile("/mnt/data/2p5-4.RNA.Aligned.sortedByCoord.out.bam.featureCounts.bam", "rb") as input_file,\ # pysam.AlignmentFile("/mnt/data/2p5-4.RNA.test.bam", "wb", header = bam_header) as output_file: filtered_count = 0 out_count = 0 with pysam.AlignmentFile(args.input, "rb") as input_file: if args.assembly == 'none': output_file = pysam.AlignmentFile(args.output, "wb", template=input_file) for read in input_file.fetch(until_eof=True): if not "NOT_FOUND" in read.query_name: output_file.write(read) out_count += 1 else: filtered_count += 1 else: output_file = pysam.AlignmentFile(args.output, "wb", header=bam_header) for read in input_file.fetch(until_eof=True): ref_name = read.reference_name if 'chr' in read.reference_name else 'chr' + read.reference_name if not "NOT_FOUND" in read.query_name and ref_name in chroms: output_file.write(read) out_count += 1 else: filtered_count += 1 output_file.close() print('Filtered reads:', filtered_count) print('Written out reads:', out_count)
def __init__(self, chromosome, build="mm9", resolution=1000000, downweighting="none"): self._chromosome = chromosome self._resolution = resolution self._assembly = assembly.build(build) self._assembly.init_offsets(self._resolution) if downweighting == "none": self._downweighting = Downweighting.NONE elif downweighting == "n_minus_one": self._downweighting = Downweighting.N_MINUS_ONE elif downweighting == "n_over_two": self._downweighting = Downweighting.N_OVER_TWO else: self._downweighting = Downweighting.UNKNOWN if self._chromosome == "genome": self.init_genome_matrix() else: self.init_chromosome_matrix()