Example #1
0
def count_reads_matching_intervals(bam_filename, intervals_filename,
                                   output_filename, logger):
    """
    Count number of reads matching the given intervals
    filename, which could be a BED or a GFF.

    Output the resulting file (a BED) to output filename.
    """
    if not os.path.isfile(intervals_filename):
        logger.critical("Cannot find exons file %s" % (output_filename))
        return None
    # intersect BAM with merged exons, outputting one line per
    # read that overlaps any region in the merged exons BED
    output_filename = get_reads_matching_regions(bam_filename,
                                                 intervals_filename,
                                                 output_filename, logger)
    if output_filename is None:
        logger.warning("Cannot access matching regions file %s" \
                       %(output_filename))
        return 0
    if not os.path.isfile(output_filename):
        logger.warning("Matching regions file %s does not exist" \
                       %(output_filename))
        return None
    num_reads = utils.count_lines(output_filename)
    return num_reads
Example #2
0
def count_reads_matching_intervals(bam_filename, intervals_filename, output_filename, logger):
    """
    Count number of reads matching the given intervals
    filename, which could be a BED or a GFF.

    Output the resulting file (a BED) to output filename.
    """
    if not os.path.isfile(intervals_filename):
        logger.critical("Cannot find exons file %s" % (output_filename))
        return None
    # intersect BAM with merged exons, outputting one line per
    # read that overlaps any region in the merged exons BED
    output_filename = get_reads_matching_regions(bam_filename, intervals_filename, output_filename, logger)
    if output_filename is None:
        logger.warning("Cannot access matching regions file %s" % (output_filename))
        return 0
    if not os.path.isfile(output_filename):
        logger.warning("Matching regions file %s does not exist" % (output_filename))
        return None
    num_reads = utils.count_lines(output_filename)
    return num_reads
Example #3
0
def count_reads_matching_intervals(bam_filename,
                                   intervals_filename,
                                   output_filename):
    """
    Count number of reads matching the given intervals
    filename, which could be a BED or a GFF.

    Output the resulting file (a BED) to output filename.
    """
    if not os.path.isfile(intervals_filename):
        print "WARNING: Cannot find exons file %s" %(output_filename)
        return None
    # intersect BAM with merged exons, outputting one line per read that
    # overlaps any region in the merged exons BED
    intersect_bam_with_bed(bam_filename,
                           intervals_filename,
                           output_filename)
    if not os.path.isfile(output_filename):
        return None
    num_reads = utils.count_lines(output_filename)
    return num_reads