[Tutor] R:reformatting data and traspose dictionary
jarod_v6 at libero.it
jarod_v6 at libero.it
Wed Apr 20 08:51:29 EDT 2016
Dear All,
sorry for my not good presentation of the code.
I read a txt file and I prepare a ditionary
files = os.listdir(".")
tutto={}
annotatemerge = {}
for i in files:
with open(i,"r") as f:
for it in f:
lines = it.rstrip("\n").split("\t")
if len(lines) >2 and lines[0] != '#CHROM':
conte = [lines[0],lines[1],lines[3],lines[4]]
tutto.setdefault(i+"::"+"-".join(conte)+"::"+str(lines),[]).append(1)
annotatemerge.setdefault("-".join(conte),set()).add(i)
I create two dictionary one
annotatemerge with use as key some coordinate ( chr3-195710967-C-CG) and
connect with a set container with the name of file names
'chr3-195710967-C-CG': {'M8.vcf'},
'chr17-29550645-T-C': {'M8.vcf'},
'chr7-140434541-G-A': {'M8.vcf'},
'chr14-62211578-CGTGT-C': {'M8.vcf', 'R76.vcf'},
'chr3-197346770-GA-G': {'M8.vcf', 'R76.vcf'},
'chr17-29683975-C-T': {'M8.vcf'},
'chr13-48955585-T-A': {'R76.vcf'},
the other dictionary report more information with as key a list of separated
using this symbol "::"
{["M8.vcf::chr17-29665680-A-G::['chr17', '29665680', '.', 'A', 'G', '70.00',
'PASS', 'DP=647;TI=NM_001042492,NM_000267;GI=NF1,NF1;FC=Silent,Silent', 'GT:GQ:
AD:VF:NL:SB:GQX', '0/1:70:623,24:0.
0371:20:-38.2744:70']": [1],...}
What I want to obtaine is a list whith this format:
coordinate\tM8.vcf\tR76.vcf\n
chr3-195710967-C-CG\t1\t0\n
chr17-29550645-T-C\t1\t0\n
chr3-197346770-GA-G\t\1\t1\n
chr13-48955585-T-A\t0\t1\n
When I have that file I want to traspose that table so have the coordinate on
columns and names of samples on rows
More information about the Tutor
mailing list