def corrected_pas(partitionA, partitionB, taxlen=None, excluded=None):
    """
    Computed corrected partition agreement score.

    The corrected partition agreement score corrects for singleton character
    states and for character states that recur in all the taxonomic units in
    the data. These extreme cases are successively ignored when computing the
    partition agreement score.

    @param partitionA, partitionB: set partitions to be compared
    @param taxlen: if set to None, the number of taxa will be computed from
      partitionA
    @param excluded: how to return excluded characters (defaults to None)
    """
    links, matches = [], []

    # prune by getting number of taxa described by partition
    if not taxlen:
        all_taxa = set()
        for prt in partitionA:
            for taxon in prt:
                all_taxa.add(taxon)
        taxlenA = len(all_taxa)
        all_taxa = set()
        for prt in partitionB:
            for taxon in prt:
                all_taxa.add(taxon)
        taxlenB = len(all_taxa)
    else:
        taxlenA, taxlenB = taxlen, taxlen

    for i, prtB in enumerate(partitionB):
        for j, prtA in enumerate(partitionA):
            if taxlenA > len(prtA) > 1 and taxlenB > len(prtB) > 1:
                if prtA.intersection(prtB):
                    links += [1]
                if prtB.issubset(prtA):
                    matches += [1]
    if matches:
        return sum(matches)/sum(links)
    elif links:
        return 0
    return excluded