-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclusterDescriptions.py
More file actions
67 lines (52 loc) · 1.59 KB
/
Copy pathclusterDescriptions.py
File metadata and controls
67 lines (52 loc) · 1.59 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
61
62
63
64
65
66
67
'''
@auther: Samaneh
This module extract the descriptions of each sequence of clusters containing more than two members
into a text file
'''
from Bio import SeqIO
import pandas as pd
import numpy as np
import xlsxwriter
import re
import multiprocessing
from multiprocessing.dummy import Pool
import time
###########################################
class cluster():
namesList = []
selDesList = []
### generate a list whose each item is a list of all names in a cluster>1
def prepareName(self, clusterFile):
lines = clusterFile.readlines()
for line in lines:
words = line.split()
if len(words)>1:
self.namesList.append(words)
### extract the descriptions related to each name of cluster from sprot database file
def writingNames(self,idnx):
self.selDesList = []
sprotFile = "/home/samaneh/AHRD/data/db/uniprot_sprot_filteredForClustering.fasta"
for name in self.namesList[idnx]:
selDes = ""
selDes += name
selDes += " "
selDes += "| "
for record in SeqIO.parse(sprotFile, "fasta"):
if name in record.name:
des = record.description.strip(record.name).strip(" ")
des = re.sub("OS=.*","",des)
selDes += des
selDes += "\n"
self.selDesList.append(selDes)
def handler():
n = cluster()
clusterFile = open("/home/samaneh/AHRD/clustering/clusters.txt","r")
n.prepareName(clusterFile)
with open("/home/samaneh/AHRD/clustering/clusteredDescriptions_final.txt","w") as f:
for i in range(0, len(n.namesList)):
n.writingNames(i)
for item in n.selDesList:
f.write(item)
f.write("\n############\n")
if __name__ == "__main__":
handler()