Exemplo n.º 1
0
def each_exon_rpkm(list_exons, bam_reader, library_size):
    """
    Args:
        list_exons = array of Exon objects
        bam_reader = HTSeq.BAM_Reader instance, used to quantify the number of reads that map to SJ genomic range 'genomic_range' (command: bam_reader = HTSeq.BAM_Reader(path_to_bam_file) )
        gene_sym = string that is the gene symbol -> used to determine which elements (introns) are constitutive for that gene.
        library_size = integer that is the number of mapped reads in the sample
    Function: returns the RPKM for all exons in array 'list_exons'
    """
    #calculate expression of skipped exons
    hash_exon_rpkm = {
    }  #k = string of position (format = chrom:start-end), v = hash that are 2 counts, RPKM from unique reads & all reads
    for each_exon in list_exons:
        exon_count_uniq = Isoform.quant_genes_rpkm(bam_reader,
                                                   each_exon.str_genomic_pos(),
                                                   True)
        exon_count_all = Isoform.quant_genes_rpkm(bam_reader,
                                                  each_exon.str_genomic_pos(),
                                                  True)

        str_exon_pos = each_exon.str_genomic_pos()
        hash_exon_rpkm[str_exon_pos] = {}
        hash_exon_rpkm[str_exon_pos]['rpkm_uniq'] = Isoform.calc_read_density(
            exon_count_uniq, str_exon_pos, library_size)
        hash_exon_rpkm[str_exon_pos]['rpkm_all'] = Isoform.calc_read_density(
            exon_count_all, str_exon_pos, library_size)

    return hash_exon_rpkm
Exemplo n.º 2
0
def all_exons_rpkm(list_exons, bam_reader, library_size):
    """
    Args:
        list_exons = array of Exon objects
        bam_reader = HTSeq.BAM_Reader instance, used to quantify the number of reads that map to SJ genomic range 'genomic_range' (command: bam_reader = HTSeq.BAM_Reader(path_to_bam_file) )
        gene_sym = string that is the gene symbol -> used to determine which elements (introns) are constitutive for that gene.
        library_size = integer that is the number of mapped reads in the sample
    Function: returns the RPKM for all exons in array 'list_exons'
    """
    #calculate expression of skipped exons
    list_exons_rpkm = []  #records RPKM for all exons
    for each_exon in list_exons:
        exon_count = Isoform.quant_genes_rpkm(bam_reader,
                                              each_exon.str_genomic_pos(),
                                              True)
        exon_rpkm = Isoform.calc_read_density(exon_count,
                                              each_exon.str_genomic_pos(),
                                              library_size)
        list_exons_rpkm.append(exon_rpkm)

    return list_exons_rpkm