def _count_in_window(window, sites, matrix_id=None):
    """Function to calculate count of PWMs in subsequence.
    
    Args:
        window (pd.DataFrame): dataframe with columns id, start, end
        sites (pd.DataFrame): dataframe containing locations of binding sites
        matrix_id (str): selected PWM
    
    Returns:
        count (int): Number of binding sites for given PWM in selected window.

    """
    sites_to_count = sites[(sites.id==window.id) & (sites.start >= window.start) & (sites.start < window.end)]
    if matrix_id is not None:
        sites_to_count = sites_to_count[(sites_to_count.Matrix_id==matrix_id)]
    return len(sites_to_count)