Simple wrapper around sacreBLEU's chrF implementation, without tokenization.

    :param hypotheses: Hypotheses stream.
    :param references: Reference stream.
    :return: chrF score as float between 0 and 1.
971578
def raw_corpus_chrf(hypotheses: Iterable[str], references: Iterable[str]) -> float:
    
    return sacrebleu.corpus_chrf(hypotheses, references, order=sacrebleu.CHRF_ORDER, beta=sacrebleu.CHRF_BETA,
                                 remove_whitespace=True)
139638
def BP(candidate, references):
    
    c = len(candidate)
    ref_lens = (len(reference) for reference in references)
    r = min(ref_lens, key=lambda ref_len: (abs(ref_len - c), ref_len))

    if c > r:
        return 1
    else:
        return math.exp(1 - r / c)
508551
def analyzed_projects(raw_df):
    
    df = raw_df[['PRONAC', 'proponenteCgcCpf']]

    analyzed_projects = df.groupby('proponenteCgcCpf')[
        'PRONAC'
    ].agg(['unique', 'nunique'])

    analyzed_projects.columns = ['pronac_list', 'num_pronacs']

    return analyzed_projects
1244451
def _srels_for(phys_reader, source_uri):
        
        rels_xml = phys_reader.rels_xml_for(source_uri)
        return _SerializedRelationships.load_from_xml(
            source_uri.baseURI, rels_xml)
252867
def filtered_error_rate(hyps_path: Union[str, Path], refs_path: Union[str, Path], labels: Set[str]) -> float:
    
    if isinstance(hyps_path, Path):
        hyps_path = str(hyps_path)
    if isinstance(refs_path, Path):
        refs_path = str(refs_path)

    with open(hyps_path) as hyps_f:
        lines = hyps_f.readlines()
        hyps = [filter_labels(line.split(), labels) for line in lines]
    with open(refs_path) as refs_f:
        lines = refs_f.readlines()
        refs = [filter_labels(line.split(), labels) for line in lines]

    # For the case where there are no tokens left after filtering.
    only_empty = True
    for entry in hyps:
        if entry is not []:
            only_empty = False
            break # found something so can move on immediately
    if only_empty:
        return -1

    return utils.batch_per(hyps, refs)
250735
def MP(candidate, references, n):
    
    counts = Counter(ngrams(candidate, n))
    if not counts:
        return 0

    max_counts = {}
    for reference in references:
        reference_counts = Counter(ngrams(reference, n))
        for ngram in counts:
            max_counts[ngram] = max(max_counts.get(ngram, 0), reference_counts[ngram])

    clipped_counts = dict((ngram, min(count, max_counts[ngram])) for ngram, count in counts.items())

    return sum(clipped_counts.values()) / sum(counts.values())
540501
def phi_coef_curve(self, delta_tau=0.01):
        
        # compute thresholds based on the sorted probabilities
        orig_thresh = self.threshold
        sorted_labels, sorted_probs = self.sorted_values

        scores = []
        taus = []
        tau = 0
        for k in range(len(sorted_labels)):
            # compute new accuracy
            self.threshold = tau
            scores.append(self.phi_coef)
            taus.append(tau)

            # update threshold
            tau = sorted_probs[k]

        # add last datapoint
        tau = 1.0
        self.threshold = tau
        scores.append(self.phi_coef)
        taus.append(tau)

        self.threshold = orig_thresh
        return scores, taus
1046080
def _compute_reference_correlations(reference_sources, filters_len):
    """"""

    # reshape references as nsrc X nchan X nsampl
    (nsrc, nsampl, nchan) = reference_sources.shape
    reference_sources = np.moveaxis(reference_sources, (1), (2))

    # zero padding and FFT of references
    reference_sources = _zeropad(reference_sources, filters_len - 1, axis=2)
    n_fft = int(2**np.ceil(np.log2(nsampl + filters_len - 1.)))
    sf = scipy.fftpack.fft(reference_sources, n=n_fft, axis=2)

    # compute intercorrelation between sources
    G = np.zeros((nsrc, nsrc, nchan, nchan, filters_len, filters_len))
    for ((i, c1), (j, c2)) in itertools.combinations_with_replacement(
        itertools.product(
            list(range(nsrc)), list(range(nchan))
        ),
        2
    ):

        ssf = sf[j, c2] * np.conj(sf[i, c1])
        ssf = np.real(scipy.fftpack.ifft(ssf))
        ss = toeplitz(
            np.hstack((ssf[0], ssf[-1:-filters_len:-1])),
            r=ssf[:filters_len]
        )
        G[j, i, c2, c1] = ss
        G[i, j, c1, c2] = ss.T
    return G, sf
1029666
def eval(self, restore_model_path: Optional[str]=None) -> None:
        

        saver = tf.train.Saver()
        with tf.Session(config=allow_growth_config) as sess:
            if restore_model_path:
                logger.info("restoring model from %s", restore_model_path)
                saver.restore(sess, restore_model_path)
            else:
                assert self.saved_model_path, "{}".format(self.saved_model_path)
                logger.info("restoring model from %s", self.saved_model_path)
                saver.restore(sess, self.saved_model_path)

            test_x, test_x_lens, test_y = self.corpus_reader.test_batch()

            feed_dict = {self.batch_x: test_x,
                         self.batch_x_lens: test_x_lens,
                         self.batch_y: test_y}

            test_ler, dense_decoded, dense_ref = sess.run(
                [self.ler, self.dense_decoded, self.dense_ref],
                feed_dict=feed_dict)
            hyps, refs = self.corpus_reader.human_readable_hyp_ref(
                dense_decoded, dense_ref)
            # Log hypotheses
            hyps_dir = os.path.join(self.exp_dir, "test")
            if not os.path.isdir(hyps_dir):
                os.mkdir(hyps_dir)
            with open(os.path.join(hyps_dir, "hyps"), "w",
                      encoding=ENCODING) as hyps_f:
                for hyp in hyps:
                    print(" ".join(hyp), file=hyps_f)
            with open(os.path.join(hyps_dir, "refs"), "w",
                      encoding=ENCODING) as refs_f:
                for ref in refs:
                    print(" ".join(ref), file=refs_f)

            test_per = utils.batch_per(hyps, refs)
            assert test_per == test_ler
            with open(os.path.join(hyps_dir, "test_per"), "w",
                      encoding=ENCODING) as per_f:
                print("LER: %f" % (test_ler), file=per_f)
132810
def run_sacrebleu(self, detok_eval_path, reference_path):
        
        if reference_path is None:
            reference_path = os.path.join(self.dataset_dir,
                                          config.TGT_TEST_TARGET_FNAME)
        sacrebleu_params = '--score-only -lc --tokenize intl'
        logging.info(f'Running sacrebleu (parameters: {sacrebleu_params})')
        sacrebleu = subprocess.run([f'sacrebleu --input {detok_eval_path} \
                                    {reference_path} {sacrebleu_params}'],
                                   stdout=subprocess.PIPE, shell=True)
        test_bleu = float(sacrebleu.stdout.strip())
        return test_bleu
822307
def normalized_mutual_info_score(self, reference_clusters):
        
        return normalized_mutual_info_score(self.get_labels(self), self.get_labels(reference_clusters))
3371
def find(self, symbol, chrom=None, create=False):
        
        queryset = self.get_query_set()

        # Filter by chromosome if one is specified
        if chrom:
            queryset = queryset.filter(chr=chrom)

        # Look for direct match
        matches = queryset.filter(symbol__iexact=symbol)

        try:
            return matches[0]
        except IndexError:
            pass

        # Attempt to disambiguate, only if this is the only synonym may it be
        # associated
        potential = list(
            queryset.filter(synonyms__label__iexact=symbol).distinct())

        if len(potential) == 1:
            return potential[0]

        # Only if there are no matches should we create a new record,
        # otherwise the synonym war will continue
        if create and len(potential) == 0:
            instance = self.model(chr=chrom, symbol=symbol)
            try:
                instance.save()
            except IntegrityError:
                instance = queryset.get(chr=chrom, symbol=symbol)
            return instance
179416
def calc_motif_enrichment(sample, background, mtc=None, len_sample=None, len_back=None):
    """"""
    
    INF = "Inf"


    if mtc not in [None, "Bonferroni", "Benjamini-Hochberg", "None"]:
        raise RuntimeError("Unknown correction: %s" % mtc)

    sig = {}
    p_value  = {}
    n_sample = {}
    n_back = {}
    
    if not(len_sample):
        len_sample = sample.seqn()
    if not(len_back):
        len_back = background.seqn()

    for motif in sample.motifs.keys():
        p = "NA"
        s = "NA"
        q = len(sample.motifs[motif])
        m = 0
        if(background.motifs.get(motif)):
            m = len(background.motifs[motif])
            n = len_back - m
            k = len_sample
            p = phyper(q - 1, m, n, k) 
            if p != 0:
                s = -(log(p)/log(10))
            else:
                s = INF
        else:
            s = INF
            p = 0.0

        sig[motif] = s
        p_value[motif] = p
        n_sample[motif] = q
        n_back[motif] = m
    
    if mtc == "Bonferroni":
        for motif in p_value.keys():
            if  p_value[motif] != "NA":
                p_value[motif] = p_value[motif] * len(p_value.keys())
                if p_value[motif] > 1:
                    p_value[motif] = 1
    elif mtc == "Benjamini-Hochberg":
        motifs = sorted(p_value.keys(), key=lambda x: -p_value[x])
        l = len(p_value)
        c = l
        for m in motifs:
            if  p_value[m] != "NA":
                p_value[m] = p_value[m] * l / c 
            c -= 1

    return (sig, p_value, n_sample, n_back)
1297340
def checkReference(self, reference):
        
        pattern = re.compile(r'[\s,;"\'&\\]')
        if pattern.findall(reference.strip()):
            return False
        return True
119985
def _l_skew_weight(self, donor_catchment):
        
        try:
            dist = donor_catchment.similarity_dist
        except AttributeError:
            dist = self._similarity_distance(self.catchment, donor_catchment)
        b = 0.0219 * (1 - exp(-dist / 0.2360))
        c = 0.2743 / (donor_catchment.record_length - 2)
        return 1 / (b + c)
678813
def human_readable_hyp_ref(self, dense_decoded, dense_y):
        

        hyps = []
        refs = []
        for i in range(len(dense_decoded)):
            ref = [phn_i for phn_i in dense_y[i] if phn_i != 0]
            hyp = [phn_i for phn_i in dense_decoded[i] if phn_i != 0]
            ref = self.corpus.indices_to_labels(ref)
            hyp = self.corpus.indices_to_labels(hyp)
            refs.append(ref)
            hyps.append(hyp)

        return hyps, refs
737594
def get_uniprot_evidence_level(header):
    """"""
    header = header.split()
    for item in header:
        item = item.split('=')
        try:
            if item[0] == 'PE':
                return 5 - int(item[1])
        except IndexError:
            continue
    return -1