I would like to make a file with 3 main columns but my current file has different number of columns per row. an example of my file is like this:
BPIFB3,chr20;ENST00000375494.3
PXDN,chr2,ENST00000252804.4;ENST00000483018.1
RP11,chr2,ENST00000607956.1
RNF19B,chr1,ENST00000373456.7;ENST00000356990.5;ENST00000235150.4
and here is what I want to make:
BPIFB3 chr20 ENST00000375494.3
PXDN chr2 ENST00000252804.4
PXDN chr2 ENST00000483018.1
RP11 chr2 ENST00000607956.1
RNF19B chr1 ENST00000373456.7
RNF19B chr1 ENST00000356990.5
RNF19B chr1 ENST00000235150.4
in fact if in the 3rd row we have more than 3 columns, per any extra column, I want to make a new row in which the first two columns are the same but the 3rd column is different(which is the extra column in original file).
I tried the following code in python but did not get what I am looking for:
from collections import defaultdict
with open('data.tbl') as f, open('out.tbl', 'w') as out:
for line in f.split('\t'):
if len(line) > 2:
d[line[0]] = line[3]
out.write(d.items)