determines number of included tail checks in best fit segment
324079
def get_n_tail(tmax, tail_temps):
    """"""
    #print "tail_temps: {0}, tmax: {0}".format(tail_temps, tmax)
    t_index = 0
    adj_tmax = 0
    if tmax < tail_temps[0]:
        return 0
    try:
        t_index = list(tail_temps).index(tmax)
    except: # finds correct tmax if there was no tail check performed at tmax
        for temp in tail_temps:
            if temp <= tmax:
                adj_tmax = temp
        t_index = list(tail_temps).index(adj_tmax)
    incl_temps = tail_temps[0:t_index+1] # b/c not inclusive
    return len(incl_temps)
212628
long getSequenceSize(SegmentKelp segment)
  {
    int tailPid = _tailPid.get();
    
    long size = 0;
    
    for (int i = 0; i <= tailPid; i++) {
      Page page = _pages.get(i);
      
      if (page != null && page.getSegment() == segment) {
        size += page.size();
      }
    }
    
    return size;
  }
559858
def verts_in_common(self, segments):
        
        verts_by_segm = self.verts_by_segm
        return sorted(reduce(lambda s0, s1: s0.intersection(s1),
                             [set(verts_by_segm[segm]) for segm in segments]))
652340
def get_proteome_correct_percentages(prots_filtered_feathers, outpath, length_filter_pid=None,
                                     copynum_scale=False, copynum_df=None,
                                     force_rerun=False):
    """"""
    if ssbio.utils.force_rerun(flag=force_rerun, outfile=outpath):
        prot_tracker = defaultdict(int)
        big_strain_counts_df = pd.DataFrame()
        first = True
        for feather in prots_filtered_feathers:
            loaded = load_feather(protein_feather=feather, length_filter_pid=length_filter_pid,
                                  copynum_scale=copynum_scale,
                                  copynum_df=copynum_df)

            if first:
                big_strain_counts_df = pd.DataFrame(columns=loaded.columns)
                first = False
            tmp_df = pd.DataFrame(columns=loaded.columns)
            for strain in loaded.columns:
                prot_tracker[strain] += 1
                totals = list(filter(lambda x: x.endswith('total'), loaded[strain].index))
                for t in totals:
                    counts = t.rsplit('_', 1)[0]
                    aa_counts = list(
                        filter(lambda x: (x.startswith(counts) and x not in totals), loaded[strain].index))
                    for aa_count in aa_counts:
                        tmp_df.at[aa_count.replace('count', '%'), strain] = loaded[strain][aa_count] / \
                                                                            loaded[strain][t]
            big_strain_counts_df = big_strain_counts_df.add(tmp_df, fill_value=0)

        for c, total in prot_tracker.items():
            big_strain_counts_df.loc[:, c] /= total

        if len(big_strain_counts_df) > 0:
            big_strain_counts_df.astype(float).reset_index().to_feather(outpath)
        return big_strain_counts_df
    else:
        return pd.read_feather(outpath).set_index('index')
1108225
def find_all_output_in_range(self, ifo, currSeg, useSplitLists=False):
        
        if not useSplitLists:
            # Slower, but simpler method
            outFiles = [i for i in self if ifo in i.ifo_list]
            outFiles = [i for i in outFiles \
                                      if i.segment_list.intersects_segment(currSeg)]
        else:
            # Faster, but more complicated
            # Basically only check if a subset of files intersects_segment by
            # using a presorted list. Sorting only happens once.
            if not self._check_split_list_validity():
                # FIXME: DO NOT hard code this.
                self._temporal_split_list(100)
            startIdx = int( (currSeg[0] - self._splitListsStart) / \
                                                          self._splitListsStep )
            # Add some small rounding here
            endIdx = (currSeg[1] - self._splitListsStart) / self._splitListsStep
            endIdx = int(endIdx - 0.000001)

            outFiles = []
            for idx in range(startIdx, endIdx + 1):
                if idx < 0 or idx >= self._splitListsNum:
                    continue
                outFilesTemp = [i for i in self._splitLists[idx] \
                                                            if ifo in i.ifo_list]
                outFiles.extend([i for i in outFilesTemp \
                                      if i.segment_list.intersects_segment(currSeg)])
                # Remove duplicates
                outFiles = list(set(outFiles))

        return self.__class__(outFiles)
607817
def dir_tails_top(self, rr_id) -> str:
        

        return join(self.dir_tails_hopper, rr_id) if self.external else self.dir_tails
1054962
def get_SCAT_points(x_Arai_segment, y_Arai_segment, tmin, tmax, ptrm_checks_temperatures,
                    ptrm_checks_starting_temperatures, x_ptrm_check, y_ptrm_check,
                    tail_checks_temperatures, tail_checks_starting_temperatures,
                    x_tail_check, y_tail_check):
    """"""
    points = []
    points_arai = []
    points_ptrm = []
    points_tail = []
    for i in range(len(x_Arai_segment)): # uses only the best_fit segment, so no need for further selection
        x = x_Arai_segment[i]
        y = y_Arai_segment[i]
        points.append((x, y))
        points_arai.append((x,y))

    for num, temp in enumerate(ptrm_checks_temperatures): #
        if temp >= tmin and temp <= tmax: # if temp is within selected range
            if (ptrm_checks_starting_temperatures[num] >= tmin and
                    ptrm_checks_starting_temperatures[num] <= tmax): # and also if it was not done after an out-of-range temp
                x = x_ptrm_check[num]
                y = y_ptrm_check[num]
                points.append((x, y))
                points_ptrm.append((x,y))

    for num, temp in enumerate(tail_checks_temperatures):
        if temp >= tmin and temp <= tmax:
            if (tail_checks_starting_temperatures[num] >= tmin and
                    tail_checks_starting_temperatures[num] <= tmax):
                x = x_tail_check[num]
                y = y_tail_check[num]
                points.append((x, y))
                points_tail.append((x,y))
           # print "points (tail checks added)", points
    fancy_points = {'points_arai': points_arai, 'points_ptrm': points_ptrm, 'points_tail': points_tail}
    return points, fancy_points
1329265
protected int determineElementsPerPart(int numberOfPartitions) {
        double numberOfElementsWithinFile = sourceFile.getFilledUpFromContentStart() / sourceFile.getElementSize();
        double elementsPerPart = numberOfElementsWithinFile / numberOfPartitions;
        int roundNumber = (int) Math.ceil(elementsPerPart);
        return roundNumber;
    }
4933
private int matchTail(int base, int index, String key) {
        int positionInTailArr = base - TAIL_OFFSET;

        int keyLength = key.length();
        for (int i = 0; i < keyLength; i++) {
            if (key.charAt(i) != tailBuffer.get(positionInTailArr + i)) {
                return -1;
            }
        }
        return tailBuffer.get(positionInTailArr + keyLength) == TERMINATING_CHARACTER ? index : 0;
    }
1137469
def get_fragment_lengths(fastafile):
    
    fraglengths = {}
    for seq in SeqIO.parse(fastafile, "fasta"):
        fraglengths[seq.id] = len(seq)
    return fraglengths
1159989
def top_and_tail(a):
    
    if np.all(np.isnan(a)):
        return np.array([])
    nans = np.where(~np.isnan(a))[0]
    last = None if nans[-1]+1 == a.size else nans[-1]+1
    return a[nans[0]:last]
194720
def bestscanseq(self,seq):
        
        matches,endpoints,scores = self.scan(seq,-100)
        t = zip(scores,matches)
        t.sort()
        bestseq   = t[-1][1]
        bestscore = t[-1][0]
        return bestscore, bestseq
226771
def common_segment_count(path, value):
    """"""
    i = 0
    if len(path) <= len(value):
        for x1, x2 in zip(path, value):
            if x1 == x2:
                i += 1
            else:
                return 0
    return i
646553
static Matcher tail(Matcher matcher) {
    if (matcher instanceof SeqMatcher) {
      List<Matcher> ms = matcher.<SeqMatcher>as().matchers();
      return SeqMatcher.create(ms.subList(1, ms.size()));
    } else {
      return TrueMatcher.INSTANCE;
    }
  }
1041134
def tail(self, lines=10):
        
        self.seek_end()
        end_pos = self.file.tell()

        for i in range(lines):
            if not self.seek_line():
                break

        data = self.file.read(end_pos - self.file.tell() - 1)
        if data:
            return self.splitlines(data)
        else:
            return []
645505
def tail(self) -> 'List':
        """"""

        lambda_list = self._get_value()
        return List(lambda_list(lambda _, tail: tail))
343120
def fit_traptransit(ts,fs,p0):
    
    pfit,success = leastsq(traptransit_resid,p0,args=(ts,fs))
    if success not in [1,2,3,4]:
        raise NoFitError
    #logging.debug('success = {}'.format(success))
    return pfit