-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcacao_dcnt.py
152 lines (128 loc) · 3.43 KB
/
cacao_dcnt.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import datetime as dt
"""
NOTE:
This file is derived from a jupyter notebook, and was converted to a script to generate the designated figure.
"""
### CACAO expanded GPAD
cacao_gpad_fh = "data/cacao_expanded_info.dat"
cols = [
"database",
"uniprot_id",
"qualifier",
"go_id",
"reference",
"evidence",
"with_from",
"interacting_taxon_id",
"date",
"assigned_by",
"annotation_extension",
"annotation_properties",
"go_name",
"aspect",
"taxon",
"domain",
"query_taxid",
"superkingdom",
"kingdom",
"phylum",
"class",
"order",
"family",
"genus",
"organism",
"species",
"user_id",
"url",
"notes",
]
cacao = pd.read_csv(
cacao_gpad_fh, sep="\t", names=cols, comment="!", parse_dates=["date"]
)
### UniProt GAF
uniprot_gaf_fh = "data/goa_uniprot_all_noiea_20200101.gaf"
names = [
"DB",
"DB Object ID",
"DB Object Symbol",
"Qualifier",
"GO ID",
"DB:Reference",
"Evidence Code",
"With/From",
"Aspect",
"DB Object Name",
"DB Object Synonym",
"DB Object Type",
"Taxon",
"Date",
"Assigned By",
"Annotation Extension",
"GeneProductID",
]
uniprot = pd.read_csv(
uniprot_gaf_fh, sep="\t", header=None, names=names, parse_dates=["Date"]
)
uniprot = uniprot[(uniprot["Date"] < "2019-01-01")]
uniprot = uniprot.loc[uniprot["Assigned By"] != "CACAO"]
### dcnt analysis
cacao_stats = "data/cacao_dcnt-tinfo.txt"
uniprot_stats = "data/uniprot_dcnt-tinfo.txt"
cols = [
"aspect",
"go_id",
"dcnt",
"tinfo",
"depth",
"go_name",
]
cacao_stat_frame = pd.read_csv(cacao_stats, sep="\t", comment="!", names=cols)
uniprot_stat_frame = pd.read_csv(uniprot_stats, sep="\t", comment="!", names=cols)
uniprot_stat_frame["assigned_by"] = "UniProtKB"
cacao_stat_frame["assigned_by"] = "CACAO"
uniprot_stat_frame["depth"] = "D0" + uniprot_stat_frame["depth"].astype(str)
cacao_stat_frame["logged_dcnt"] = np.log(cacao_stat_frame["dcnt"] + 1)
uniprot_stat_frame["logged_dcnt"] = np.log(uniprot_stat_frame["dcnt"] + 1)
all_data = [cacao_stat_frame, uniprot_stat_frame]
combined_stats = pd.concat(all_data).reset_index(drop=True)
uniprot_subset = uniprot[["DB Object ID", "GO ID", "Evidence Code"]]
uniprot_subset = uniprot_subset.rename(
{
"DB Object ID": "uniprot_id",
"GO ID": "go_id",
"Evidence Code": "evidence",
},
axis=1,
)
cacao_subset = cacao[["uniprot_id", "go_id", "evidence"]]
uniprot_combined = uniprot_subset.merge(
uniprot_stat_frame, left_on=["go_id"], right_on=["go_id"], how="left"
)
cacao_combined = cacao_subset.merge(
cacao_stat_frame, left_on=["go_id"], right_on=["go_id"], how="left"
)
the_final_data = [cacao_combined, uniprot_combined]
combined_all = pd.concat(the_final_data).reset_index(drop=True)
### Graph
sns.set()
sns.set_style("whitegrid")
# sns.set_context("talk") # Used in the paper.
ax = sns.boxplot(
data=combined_all,
x="aspect",
y="logged_dcnt",
hue="assigned_by",
palette="Greys",
whis=[5, 95],
)
# plt.legend(bbox_to_anchor=(1.05, 1), loc=2) # Used in paper
plt.legend(bbox_to_anchor=(1.05, 1), loc=1) # Used in paper
ax.set(xlabel="Aspect", ylabel="log(descendant count)")
labels = ["Cellular\nComponent", "Biological\nProcess", "Molecular\nFunction"]
ax.set_xticklabels(labels)
ax.xaxis.labelpad = 20
plt.show()