Take a list of BlastLines (or a BlastSlow instance), and returns a list of
    BlastLines.
321223
def chain_HSPs(blast, xdist=100, ydist=100):
    
    key = lambda x: (x.query, x.subject)
    blast.sort(key=key)

    clusters = Grouper()
    for qs, points in groupby(blast, key=key):
        points = sorted(list(points), \
                key=lambda x: (x.qstart, x.qstop, x.sstart, x.sstop))

        n = len(points)
        for i in xrange(n):
            a = points[i]
            clusters.join(a)
            for j in xrange(i + 1, n):
                b = points[j]

                # x-axis distance
                del_x = get_distance(a, b)
                if del_x > xdist:
                    break
                # y-axis distance
                del_y = get_distance(a, b, xaxis=False)
                if del_y > ydist:
                    continue
                # otherwise join
                clusters.join(a, b)

    chained_hsps = [combine_HSPs(x) for x in clusters]
    key = lambda x: (x.query, -x.score if x.has_score else 0)
    chained_hsps = sorted(chained_hsps, key=key)

    return chained_hsps
962471
def get_frames(tback, is_breakpoint):
    """"""

    frames = []

    while tback is not None:
        if tback.tb_next is None and is_breakpoint:
            break

        filename = tback.tb_frame.f_code.co_filename
        function = tback.tb_frame.f_code.co_name
        context = tback.tb_frame.f_locals
        lineno = tback.tb_lineno - 1
        tback_id = id(tback)
        pre_context_lineno, pre_context, context_line, post_context = get_lines_from_file(filename, lineno + 1, 7)
        frames.append(ErrorFrame(tback, filename, function, lineno, context, tback_id, pre_context, context_line, post_context, pre_context_lineno))
        tback = tback.tb_next

    return frames
1278502
def readlines(self, timeout=1):
        
        lines = []
        while 1:
            line = self.readline(timeout=timeout)
            if line:
                lines.append(line)
            if not line or line[-1:] != '\n':
                break
        return lines
1215033
def list_():
    '''
    
    '''
    cmd = 'pkgutil --pkgs'
    ret = salt.utils.mac_utils.execute_return_result(cmd)
    return ret.splitlines()
183676
def inspect(lines):
    
    labels = set()
    count = 0
    exp = re.compile(r">.*?<([\w ]+)>")  # Space should be accepted
    valid = False
    for line in lines:
        if line.startswith("M  END\n"):
            valid = True
        elif line.startswith("$$$$"):
            count += 1
            valid = False
        else:
            result = exp.match(line)
            if result:
                labels.add(result.group(1))
    if valid:
        count += 1
    return list(labels), count
687631
def readlines(self, *args, **kwargs):
        """"""
        return list(iter(partial(self.readline, *args, **kwargs), u''))
594713
def get_breakpoints(self, lineno):
        """"""
        try:
            firstlineno, actual_lno = self.bdb_module.get_actual_bp(lineno)
        except BdbSourceError:
            return []
        if firstlineno not in self:
            return []
        code_bps = self[firstlineno]
        if actual_lno not in code_bps:
            return []
        return [bp for bp in sorted(code_bps[actual_lno],
                    key=attrgetter('number')) if bp.line == lineno]
303928
def _output_to_list(cmdoutput):
    '''
    
    '''
    return [item for line in cmdoutput.splitlines() if _safe_output(line) for item in line.split()]
249534
def maximum_hline_bundle(self, y0, x0, x1):
        
        x_range = range(x0, x1 + 1) if x0 < x1 else range(x0, x1 - 1, -1)
        hlines = [[(x, y0, 0, k) for x in x_range] for k in range(self.L)]
        return list(filter(self._contains_line, hlines))
698394
def parse_blocks(lines):  # type: (List[str]) -> List[List[str]]
    
    blocks = []

    while lines:
        if lines[0] == '':
            lines.pop(0)
        else:
            blocks.append(parse_block(lines))

    return blocks
74139
def build_list(self):
        """"""
        ret = []
        for p in self.args.stdout.split(','):
            if '.' in p:
                p, a = p.split('.')
            else:
                a = None
            ret.append((p, a))
        return ret
520953
def shapeRecords(self):
        """"""
        shapeRecords = []
        return [_ShapeRecord(shape=rec[0], record=rec[1]) \
                                for rec in zip(self.shapes(), self.records())]
283549
def _split_vlines_hlines(lines):
    """"""
    vlines, hlines = [], []
    for line in lines:
        (vlines if line.x1 - line.x0 < 0.1 else hlines).append(line)
    return vlines, hlines
806055
def zs(inlist):
    
    zscores = []
    for item in inlist:
        zscores.append(z(inlist, item))
    return zscores
424640
def buildFileList(input, output=None, ivmlist=None,
                wcskey=None, updatewcs=True, **workinplace):
    
    newfilelist, ivmlist, output, oldasndict, filelist = \
        buildFileListOrig(input=input, output=output, ivmlist=ivmlist,
                    wcskey=wcskey, updatewcs=updatewcs, **workinplace)
    return newfilelist, ivmlist, output, oldasndict
52532
def greplines(lines, regexpr_list, reflags=0):
    
    found_lines = []
    found_lxs = []
    # Ensure a list
    islist = isinstance(regexpr_list, (list, tuple))
    islist2 = isinstance(reflags, (list, tuple))
    regexpr_list_ = regexpr_list if islist else [regexpr_list]
    reflags_list = reflags if islist2 else [reflags] * len(regexpr_list_)
    re_list = [re.compile(pat, flags=_flags)
               for pat, _flags in  zip(regexpr_list_, reflags_list)]
    #print('regexpr_list_ = %r' % (regexpr_list_,))
    #print('re_list = %r' % (re_list,))

    import numpy as np
    #import utool as ut
    #cumsum = ut.cumsum(map(len, lines))
    cumsum = np.cumsum(list(map(len, lines)))
    text = ''.join(lines)

    # Search each line for each pattern
    for re_ in re_list:
        # FIXME: multiline mode doesnt work
        for match_object in re_.finditer(text):
            lxs = np.where(match_object.start() < cumsum)[0][0:1]
            if len(lxs) == 1:
                lx = lxs[0]
                if lx > 0:
                    line_start = cumsum[lx - 1]
                else:
                    line_start = 0
                line_end = cumsum[lx]
                line = text[line_start:line_end]
                found_lines.append(line)
                found_lxs.append(lx)
    return found_lines, found_lxs
661978
def run(self, lines):
        """"""
        ret = []

        for block in self.blocks(lines):
            ret.extend(self.convert_table(block))

        return ret