bam.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:cellranger 作者: 10XGenomics 项目源码 文件源码
def qname_cmp_func(qname1, qname2):

    def update_char(qname, index):
        index += 1
        if index < len(qname):
            c = qname[index]
        else:
            c = ''
        return c, index

    def get_ord(c):
        if c:
            return ord(c)
        return 0

    i, j = 0, 0
    c1 = qname1[0] if qname1 else None
    c2 = qname2[0] if qname2 else None
    while c1 and c2:
        if c1.isdigit() and c2.isdigit():
            while c1 == '0':
                c1, i = update_char(qname1, i)
            while c2 == '0':
                c2, j = update_char(qname2, j)
            while c1.isdigit() and c2.isdigit() and c1 == c2:
                c1, i = update_char(qname1, i)
                c2, j = update_char(qname2, j)
            if c1.isdigit() and c2.isdigit():
                k, l = i, j
                while c1.isdigit() and c2.isdigit():
                    c1, k = update_char(qname1, k)
                    c2, l = update_char(qname2, l)
                return 1 if c1.isdigit() else (-1 if c2.isdigit() else get_ord(qname1[i]) - get_ord(qname2[j]))
            elif c1.isdigit():
                return 1
            elif c2.isdigit():
                return -1
            elif i != j:
                return 1 if i < j else -1
        else:
            if c1 != c2:
                return get_ord(c1) - get_ord(c2)
            c1, i = update_char(qname1, i)
            c2, j = update_char(qname2, j)
    return 1 if c1 else (-1 if c2 else 0)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号