-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGet_accession_name.py
More file actions
40 lines (33 loc) · 1.02 KB
/
Get_accession_name.py
File metadata and controls
40 lines (33 loc) · 1.02 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
import pandas as pd
import numpy as np
import csv
import re
gofile = open("data/go.txt", "r")
# print gofile.read()
ans = pd.DataFrame(columns = ['id', 'name','index'])
list_goterm=[]
list_goterm_name=[]
for line in gofile:
txt = "id:"
list_=line.split()
name="name:"
if not list_:
continue
else:
if(str(list_[0])==txt):
list_goterm.append(list_[1])
if(str(list_[0])==name):
gene_name=""
for i in range(1,len(list_)):
gene_name=gene_name+" "+list_[i]
list_goterm_name.append(gene_name)
df_goterm = pd.DataFrame(list_goterm)
df_name = pd.DataFrame(list_goterm_name)
for i in range(0,len(list_goterm)):
ans = ans.append({'id': list_goterm[i], 'name': list_goterm_name[i],'index':list_goterm[i]},ignore_index=True)
ans=ans.set_index('index')
print ans
# ans = pd.DataFrame(columns = ['id', 'name'])
# res_df = pd.DataFrame({'id':df_goterm,'name':df_name})
# print res_df
ans.to_pickle('data/Goterm_Database.pkl')