Input: list of nucmer hits. Returns the longest hit, taking hit length on the reference
349626
def _get_longest_hit_by_ref_length(self, nucmer_hits):
        ''''''
        if len(nucmer_hits) == 0:
            return None

        max_length = None
        longest_hit = None
        for hit in nucmer_hits:
            if max_length is None or hit.hit_length_ref > max_length:
                max_length = hit.hit_length_ref
                longest_hit = copy.copy(hit)

        assert longest_hit is not None
        return longest_hit
729145
def _get_cumulative_results(self, results):
        
        hits = {'total': 0, 'unique': 0}

        day_hits = list(hits[0] for hits in results.values() if hits)
        for metrics in day_hits:
            hits['total'] += metrics['nb_hits']
            hits['unique'] += metrics['nb_uniq_visitors']

        return hits
548396
def nucmer_hits_to_ref_and_qry_coords(cls, nucmer_hits, contig=None):
        ''''''
        if contig is None:
            ctg_coords = {key: [] for key in nucmer_hits.keys()}
        else:
            ctg_coords = {contig: []}

        ref_coords = {}

        for key in ctg_coords:
            hits = copy.copy(nucmer_hits[key])
            hits.sort(key=lambda x: len(x.ref_coords()))

            if len(hits) > 1:
                i = 0
                while i < len(hits) - 1:
                    c1 = hits[i].ref_coords()
                    c2 = hits[i+1].ref_coords()
                    if c2.contains(c1):
                        hits.pop(i)
                    else:
                        i += 1

            ref_coords[key] = [hit.ref_coords() for hit in hits]
            ctg_coords[key] = [hit.qry_coords() for hit in hits]
            pyfastaq.intervals.merge_overlapping_in_list(ref_coords[key])
            pyfastaq.intervals.merge_overlapping_in_list(ctg_coords[key])

        return ctg_coords, ref_coords
657126
function getStreaks(contributions) {
  const start = contributions[0].date;
  const end = contributions.slice(-1)[0].date;
  const streak = {days: 0, start: null, end: null, unmeasurable: false};
  let currentStreak = Object.assign({}, streak);
  let longestStreak = Object.assign({}, streak);
  contributions.forEach(ret => {
    if (ret.count > 0) {
      currentStreak.days += 1;
      currentStreak.end = ret.date;
      if (!currentStreak.start) {
        currentStreak.start = ret.date;
      }
      if (currentStreak.days >= longestStreak.days) {
        longestStreak = Object.assign({}, currentStreak);
      }
    } else if (ret.date !== end) {
      currentStreak = Object.assign({}, streak);
    }
  });
  if (currentStreak.start === start && currentStreak.end === end) {
    currentStreak.unmeasurable = true;
    longestStreak.unmeasurable = true;
  }
  return {currentStreak, longestStreak};
}
251353
def longest_in_list2 list  #:nodoc:
      longest = list.inject(list[0]) do |memo,word|
        memo.length >= word.length ? memo : word
      end    
      longest
    end
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())
301054
def total_hits(self, filename=None):
        
        if filename is not None:
            return len(self.hit_statements(filename))

        total = 0
        for filename in self.files():
            total += len(self.hit_statements(filename))

        return total
958188
def list():
    
    choice_len = max(map(len, _input_choices.keys()))
    tmpl = "  {:<%d}: {}\n" % choice_len
    text = ''.join(map(
        lambda k_v: tmpl.format(k_v[0], k_v[1][0]), six.iteritems(_input_choices)))
    click.echo(text)
81560
function longestCommonPathPrefix(stra, strb) {
  const minlen = min(stra.length, strb.length);
  let common = 0;
  let lastSep = -1;
  for (; common < minlen; ++common) {
    const chr = stra[common];
    if (chr !== strb[common]) {
      break;
    }
    if (chr === sep) {
      lastSep = common;
    }
  }
  if (common === minlen &&
      (stra.length === minlen ?
        strb.length === minlen || strb[minlen] === sep :
        stra[minlen] === sep)) {
    return minlen + 1;
  }
  return lastSep + 1;
}
863982
def get_padding_lengths(self) -> Dict[str, int]:
        
        # Our basic outline: we will iterate over `TokenIndexers`, and aggregate lengths over tokens
        # for each indexer separately.  Then we will combine the results for each indexer into a single
        # dictionary, resolving any (unlikely) key conflicts by taking a max.
        lengths = []
        if self._indexed_tokens is None:
            raise ConfigurationError("You must call .index(vocabulary) on a "
                                     "field before determining padding lengths.")

        # Each indexer can return a different sequence length, and for indexers that return
        # multiple arrays each can have a different length.  We'll keep track of them here.
        for indexer_name, indexer in self._token_indexers.items():
            indexer_lengths = {}

            for indexed_tokens_key in self._indexer_name_to_indexed_token[indexer_name]:
                # This is a list of dicts, one for each token in the field.
                token_lengths = [indexer.get_padding_lengths(token)
                                 for token in self._indexed_tokens[indexed_tokens_key]]
            if not token_lengths:
                # This is a padding edge case and occurs when we want to pad a ListField of
                # TextFields. In order to pad the list field, we need to be able to have an
                # _empty_ TextField, but if this is the case, token_lengths will be an empty
                # list, so we add the default empty padding dictionary to the list instead.
                token_lengths = [{}]
            # Iterate over the keys and find the maximum token length.
            # It's fine to iterate over the keys of the first token since all tokens have the same keys.
            for key in token_lengths[0]:
                indexer_lengths[key] = max(x[key] if key in x else 0 for x in token_lengths)
            lengths.append(indexer_lengths)

        padding_lengths = {}
        num_tokens = set()
        for indexer_name, token_list in self._indexed_tokens.items():
            padding_lengths[f"{indexer_name}_length"] = len(token_list)
            num_tokens.add(len(token_list))

        # We don't actually use this for padding anywhere, but we used to.  We add this key back in
        # so that older configs still work if they sorted by this key in a BucketIterator.  Taking
        # the max of all of these should be fine for that purpose.
        padding_lengths['num_tokens'] = max(num_tokens)

        # Get all keys which have been used for padding for each indexer and take the max if there are duplicates.
        padding_keys = {key for d in lengths for key in d.keys()}
        for padding_key in padding_keys:
            padding_lengths[padding_key] = max(x[padding_key] if padding_key in x else 0 for x in lengths)
        return padding_lengths
938505
def ic(ctext):
    ''' '''
    counts = ngram_count(ctext,N=1)
    icval = 0
    for k in counts.keys():
        icval += counts[k]*(counts[k]-1)
    icval /= (len(ctext)*(len(ctext)-1))
    return icval
566516
def nucmer_hit_containing_reference_position(nucmer_hits, ref_name, ref_position, qry_name=None):
        ''''''
        for contig_name in nucmer_hits:
            for hit in nucmer_hits[contig_name]:
                if hit.ref_name == ref_name and (qry_name is None or qry_name == hit.qry_name) and hit.ref_coords().distance_to_point(ref_position) == 0:
                    return hit

        return None
883159
def _get_longest_hit_at_qry_start(self, nucmer_hits):
        ''''''
        hits_at_start = [hit for hit in nucmer_hits if self._is_at_qry_start(hit)]
        return self._get_longest_hit_by_ref_length(hits_at_start)
992626
def _containing_contigs(self, hits):
        ''''''
        return {hit.ref_name for hit in hits if self._contains(hit)}
1066199
function longest() {
  var args = slice.call(arguments)
    , len = 0, resp, arg
  for (var i = 0; i < args.length; i++) {
    arg = args[i]
    if (arg.length >= len) {
      len = arg.length
      resp = arg
    }
  }
  return resp
}
1254130
def _get_identical_contigs(self, hits_dict):
        ''''''
        equivalent_contigs = []

        for qry_name, containing in hits_dict.items():
            equivalent = set()
            for containing_name in containing:
                if containing_name in hits_dict and qry_name in hits_dict[containing_name]:
                    equivalent.add(containing_name)
                    equivalent.add(qry_name)

            if len(equivalent):
                equivalent_contigs.append(equivalent)
                equivalent_contigs = self._collapse_list_of_sets(equivalent_contigs)

        return equivalent_contigs
806133
def hit_groups(hits):
    
    groups = []
    current = False
    for hit in sorted(hits, key = itemgetter(0)):
        if current is False:
            current = [hit]
        elif check_overlap(current, hit) is True or check_order(current, hit) is False:
            groups.append(current)
            current = [hit]
        else:
            current.append(hit)
    groups.append(current)
    return groups