0

我是python的初学者,目前正在执行一段代码,但它会引发以下错误。我尽力解决但无法解决。请帮我。代码如下。

    continue
    num_snps_skipped += 1
    samp_id = sline[id_index]
    ref_allele = sline[ref_allele_index]
    tum_allele = sline[tum_allele_index]
    snp = ref_allele + tum_allele
    if not snp in transitions:
        snp = nucleotide_complement[ref_allele] + nucleotide_complement[tum_allele]
    ref_trinuc = sline[ref_tri_index]
    if ref_trinuc == "NA":
        print "Warning: Reference allele not available on "+\
                "line %d; skipping line"%line_number
        continue
    if not ref_trinuc[1] == snp[0]:
        print "Warning: Reference allele does not match reference "+\
                "trinucleotide; skipping line %d"%line_number**
        continue
    snp_with_ctx = ref_trinuc[0] + snp + ref_trinuc[2]
    if not samp_id in signatures:
        signatures[samp_id] = [0 for i in substitution_order]
    if snp_with_ctx not in substitution_order:
        print "Warning: substitution on line " + \
                "%d is %s, not "%(line_number,snp_with_ctx) + \
                "found among possible substitutions. Skipping line."

我收到如下错误

    Traceback (most recent call last):
  File "main.py", line 59, in <module>
    signatures = signature.make(args.in_file, substitution_order=stratton['substitution_order'], out_path = args.spectrum_output)
  File "/home/ateeqanees/Mutation/centos/mutation-signatures-master/signature.py", line 73, in make
    if not ref_trinuc[1] == snp[0]:
IndexError: string index out of range

请帮我。这会有很大帮助。

非常感谢 !!!达夫

4

1 回答 1

0

您的字符串很可能ref_trinuc有一个或零个字符。这if not ref_trinuc[1] == snp[0]:就是给出索引错误的原因,因为它试图获取第二个字符。

在该行之前尝试打印 ref_trinuc 以查看它的内容。

如果 ref_trinuc 有时少于 2 个字符是正常的,请尝试以下 if 语句:

if (len(ref_trinuc) > 1) and (not ref_trinuc[1] == snp[0]):

因为如果长度为 1 或 0,在这种情况下将不会尝试后半部分并且不会引发索引错误。

于 2017-07-28T02:38:58.960 回答