def filter_ribo_counts(counts, orf_start=None, orf_stop=None):
filtered_counts = dict.copy(counts)<EOL>for position in counts:<EOL><INDENT>if orf_start and orf_stop:<EOL><INDENT>if (position > orf_start and position < orf_stop):<EOL><INDENT>filtered_counts.pop(position)<EOL><DEDENT><DEDENT>elif orf_start:<EOL><INDENT>if position >= orf_start:<EOL><INDENT>filtered_counts.pop(position)<EOL><DEDENT><DEDENT>elif orf_stop:<EOL><INDENT>if position <= orf_stop:<EOL><INDENT>filtered_counts.pop(position)<EOL><DEDENT><DEDENT><DEDENT>total_reads = sum(sum(item.values()) for item in filtered_counts.values())<EOL>return filtered_counts, total_reads<EOL>
Filter read counts  and return only upstream of orf_start or downstream
    of orf_stop.

    Keyword arguments:
    counts -- Ribo-Seq read counts obtained from get_ribo_counts.
    orf_start -- Start position of the longest ORF.
    orf_stop -- Stop position of the longest ORF.