def is_within_region(readpos, contiglength, readlength, regionlength):
    """Checks if a read is within the given region."""
    return readpos - readlength <= regionlength \
      or readpos >= contiglength - regionlength