Off topic:Python IndexError: list index out of range
1
0
Entering edit mode
6.4 years ago

Hi all I am supposed to use a Python script to identify possible SNPs at specified positions  from a csv file in vcf files. Sadly I always get followig Error :

Traceback (most recent call last):
  File "getSNPs.py", line 20, in <module>
    oo = line[2] + "_" + line[3]
IndexError: list index out of range from the following script :
# !/bin/python
# usage: python getSNPs.py your.vcf PhenoSNPs.csv
# uses a lot of RAM  
 
import sys
import gzip
 
SNPs = {}
 
for i in gzip.open(sys.argv[1], "r"):
    if '#' not in i:
        line = i.split("\t")
        oo = line[0] + "_" + line[1]
        SNPs[oo] = i
pp = sys.argv[1] + ".captureSNPs"
out = open(pp, "w")
 
for i in open(sys.argv[2], "r"):
    line = i.split(";")
    oo = line[2] + "_" + line[3]
    try:
        out.write(SNPs[oo])
    except KeyError:
        ow = line[2] + "\t" + line[3] + "\t" + "not covered" + "\n"
        out.write(ow)   


 

SNP Python Error gzip • 13k views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 2067 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6