Good day,
I am working on a script that outputs a file summarizing the Gene Onthology terms of multiple species. It should display the following columns: Species Name | Gene ID | GO ID. The code itself is pretty easy and I am mostly done already. The only problem I face is that the input files list the gene multiple times if they have multiple GOterms. e.g.:
Znev_18624 GO:0009987
Znev_18624 GO:0008150
Znev_18620 GO:0008150
Znev_18620 GO:0009987
Znev_18721 GO:0009987
Znev_18721 GO:0008150
I basically just want to summarize the same keys so it just outputs the key once and multiple values in the next column. I found multiple questions asking how to merge two dictionaries but never spefically how to solve my problem. The code looks like this, again pretty simple as it just rewrites the colums but I would like to emphasise that I do not decleare a dictionary first but just write out the values:
for line in ref:
if 'Protein GO term Score' in line:
continue
GeneID = line.split('\t')[0]
GOID = line.split('\t')[1]
results.write('Znev' + '\t' + GeneID + '\t' + GOID + '\n')
The outputfile looks just like above. May help would be much appreciated. Thank you in advance.