def categorize_disorder(scores_df, disfrac_df):
    """Take a merged disorder input and the derived aggregated disorder fractions
    and classify proteins categorically according to Deiana et al.
    (http://dx.doi.org/10.1101/446351)

    The criteria used are:
    A10 = 10% disorder fraction
    A30 = 30% disorder fraction
    B = 22 consecutive disordered amino acids (we need the raw scores!)

    The disordered classes are defined below.

    Arguments:
        scores_df {pd.DataFrame} -- [description]
        disfrac_df {pd.DataFrame} -- [description]

    Returns:
        cat_disfrac {pd.DataFrame} -- [description]
    """
    # First, conditions are checked for each protein

    condA10 = {}
    condA30 = {}
    condB = {}

    grouped_disfrac = disfrac_df.groupby(["protein_ac"])
    grouped_scores = scores_df.groupby(["protein_ac"])

    # Condition A: Disorder fraction
    for gp, df in grouped_disfrac:
        if df["disorder_fraction"].unique() < 0.1:
            condA10[gp] = False
            condA30[gp] = False
        elif df["disorder_fraction"].unique() < 0.3:
            condA10[gp] = True
            condA30[gp] = False
        elif df["disorder_fraction"].unique() >= 0.3:
            condA10[gp] = True
            condA30[gp] = True
        else:
            print("Disorder fraction value not found for {}".format(gp))

    # Condition B:Disordered stretches
    for gp, df in grouped_scores:
        # Define a rolling window of 22 amino acids
        wdw = df["score"].rolling(22)
        # Check how many stretches exist where all scores indicate disorder
        idrs = df[wdw.min() >= 0.5]
        if len(idrs) > 0:
            condB[gp] = True
        else:
            condB[gp] = False

    disorder_type_dict = {}

    # Categorize disorder fractions
    for protein in disfrac_df["protein_ac"]:
        A10 = condA10[protein]
        A30 = condA30[protein]
        B = condB[protein]

        if A10 is False:
            # 'ORD': Ordered protein
            disorder_type_dict[protein] = "ORD"
        elif A10 is True and A30 is False:
            if B is False:
                # 'NDP': Not disordered protein
                disorder_type_dict[protein] = "NDP"
            else:
                # 'PDR': Partially disordered protein
                disorder_type_dict[protein] = "PDR"
        elif A30 is True:
            if B is False:
                # 'FRAG': Fragmentarily disordered protein
                disorder_type_dict[protein] = "FRAG"
            else:
                # 'IDP':Intrinsically disordered protein
                disorder_type_dict[protein] = "IDP"

    # Copy disorder fraction and add classification column
    cat_disfrac = disfrac_df
    cat_disfrac["disorder_category"] = cat_disfrac["protein_ac"].map(disorder_type_dict)

    return cat_disfrac