I am trying to use split in python to iterate through columns but when trying to access columns I get an error that a particular list index is out of range.
This is what my file looks like:
chr1 15585711 . A T 45.7081 . AB=0;ABP=0;AC=2;AF=1;AN=2;AO=3;CIGAR=1X;DP=3;DPB=3;DPRA=0;EPP=9.52472;EPPR=0;GTI=0;LEN=1;MEANALT=1;MQM=60;MQMR=0; NS=1;NUMALT=1;ODDS=8.76405;PAIRED=0;PAIREDR=0;PAO=0;PQA=0;PQR=0;PRO=0;QA=78;QR=0;RO=0;RPP=9.52472;RPPR=0;RUN=1;SAF=0;SAP=9.52472;SAR=3;SRF=0;SRP=0;SRR=0; TYPE=snp GT:DP:RO:QR:AO:QA:GL 1/1:3:0:0:3:78:-7.28,-0.90309,0
And here is my code:
target = open('file', 'r')
for line in target:
line = line.split('\t')
print line[1]
When I print line it looks like a list to me, and line[0] does access chr1 which is the first column. But then when I try to access the other columns i cannot.
line.split()to split on every whitespaceline[0] does access chr1<- you're asking forline[1]in your code, thoughprint line.split('\t')['chr1', '15585711', '.', 'A', 'T', '45.7081', '.', 'AB=0;ABP=0;AC=2;AF=1;AN=2;AO=3;CIGAR=1X;DP=3;DPB=3;DPRA=0;EPP=9.52472;EPPR=0;GTI=0;LEN=1;MEANALT=1;MQM=60;MQMR=0;NS=1;NUMALT=1;ODDS=8.76405;PAIRED=0;PAIREDR=0;PAO=0;PQA=0;PQR=0;PRO=0;QA=78;QR=0;RO=0;RPP=9.52472;RPPR=0;RUN=1;SAF=0;SAP=9.52472;SAR=3;SRF=0;SRP=0;SRR=0;TYPE=snp', 'GT:DP:RO:QR:AO:QA:GL', '1/1:3:0:0:3:78:-7.28,-0.90309,0\n']