-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateClusteredReference.py
More file actions
61 lines (44 loc) · 1.47 KB
/
Copy pathgenerateClusteredReference.py
File metadata and controls
61 lines (44 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'''
@auther: Samaneh
The whole planned algorithm is implemented here:
'''
from Bio import SeqIO
import pandas as pd
import numpy as np
#import xlsxwriter
import re
import csv
import os
import json
#########################################################################
##@sam## Extracts all the uniprot IDs and corresponding clusters from eggNOG tsv file into a dictionary
def uniprotIdsExtraction(uniprotIdsFile):
idsList = []
idDesDic = dict()
for line in uniprotIdsFile.readlines():
if ">>" in line:
ids = line.split("|")[0]
ids = re.sub(">>","",ids).strip(" ")
desc = line.split("|")[1].lstrip(" ")
if ids not in idDesDic.keys():
idDesDic.update({ids:desc})
else:
newDesc = idDesDic[ids] + " / " + desc
idDesDic.update({ids:newDesc})
return idDesDic
def referenceGenerator(idDesDic, sprotFile):
reference = open("/home/samaneh/eggNOG/output/clstrd_ref_eggNOG_descs.fasta", "w")
for record in SeqIO.parse(sprotFile, "fasta"):
spId = record.id.split("|")[1]
if spId in idDesDic.keys():
newRecord = record
newRecord.description = idDesDic[spId]
SeqIO.write(newRecord, reference, "fasta")
reference.close()
def handler():
uniprotIdsFile = open("/home/samaneh/eggNOG/output/eggnogClusterDescriptions_onEggNOG.txt", "r")
sprotFile = open("/home/samaneh/AHRD/data/db/uniprot_sprot.fasta", "r")
idDesDic = uniprotIdsExtraction(uniprotIdsFile)
referenceGenerator(idDesDic, sprotFile)
if __name__ == "__main__":
handler()