soh-i / Ivy

Detection method for RNA editng sites based on high-throughput sequencing data
GNU General Public License v2.0
1 stars 0 forks source link

Bug for `AlignmentReadsStats.define_allele(base, ref=None)` #69

Closed soh-i closed 10 years ago

soh-i commented 10 years ago
base = ['T', 'T', 'T', 'T', 'T', 'G', 'G', 'G', 'G']
allele = AlignmentReadsStats.define_allele(base, ref='T')
print allele

=> ('G', 4) はOK

ところが、先頭の要素をAにしてみると、

base = ['A', 'T', 'T', 'T', 'T', 'G', 'G', 'G', 'G']
allele = AlignmentReadsStats.define_allele(base, ref='T')
print allele

=> ('A', 1) バグ。

正しくは、('G', 4)

soh-i commented 10 years ago
from  collections import Counter

def define_allele(base, ref=None):
    data = Counter(base)
    common = data.most_common()

    found_allele = {}
    for i in common:
        b_type = i[0]
        count = i[1]
        if b_type != ref:
            found_allele.update({b_type: count})

    if len(found_allele):
        # Mismatch is found
        max_val= max(found_allele.values())
    else:
        # Mismatch base is not found
        return '.'

    result = []
    for value in found_allele.values():
        if value == max_val:
            for itm in found_allele.items():
                if itm[1] == value:
                    result.append(itm)
            break
    return result

でどうでしょう。

soh-i commented 10 years ago
if __name__ == '__main__':
    base = ['A', 'A', 'A', 'T', 'T', 'G', 'G', 'G', 'C', 'C', 'C']
    print "base: {0}".format(base)

    for r in ['A', 'T', 'G', 'C']:
        print "ref: {0}".format(r),
        print define_allele(base, ref=r)

    base = ['A', 'A', 'A', 'A']
    print define_allele(base, ref='A')
base: ['A', 'A', 'A', 'T', 'T', 'G', 'G', 'G', 'C', 'C', 'C']
ref: A [('C', 3), ('G', 3)]
ref: T [('A', 3), ('C', 3), ('G', 3)]
ref: G [('A', 3), ('C', 3)]
ref: C [('A', 3), ('G', 3)]
.
soh-i commented 10 years ago

新年あけましておめでとうございます。今年も宜しくお願いします。2014年、初仕事は、最も高いアレル頻度を持つ塩基の種類を決定するメソッドのバグ修正になっております。pileup branchにpushさせて頂きましたので、masterへ順次mergeして頂ければ幸いに思います。卒論まで残り19日です、、、、