Skip to content

Commit

Permalink
Adding GO annotation function based on GO id
Browse files Browse the repository at this point in the history
  • Loading branch information
JuseTiZ committed Aug 27, 2023
1 parent 1049389 commit 654ceb5
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Juse_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,11 +991,11 @@ def setupUi(self, Dialog):
self.enrich_xlab.addItem("")
self.horizontalLayout_38.addWidget(self.enrich_xlab)
self.gtl_dl = QtWidgets.QPushButton(self.groupBox_31)
self.gtl_dl.setEnabled(False)
self.gtl_dl.setEnabled(True)
self.gtl_dl.setObjectName("gtl_dl")
self.horizontalLayout_38.addWidget(self.gtl_dl)
self.gef_c = QtWidgets.QPushButton(self.groupBox_31)
self.gef_c.setEnabled(False)
self.gef_c.setEnabled(True)
self.gef_c.setObjectName("gef_c")
self.horizontalLayout_38.addWidget(self.gef_c)
self.groupBox_32 = QtWidgets.QGroupBox(self.tab_8)
Expand Down
4 changes: 2 additions & 2 deletions Juse_toolkit.ui
Original file line number Diff line number Diff line change
Expand Up @@ -3044,7 +3044,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QPushButton" name="gtl_dl">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="text">
<string>下载 GO term list 文件</string>
Expand All @@ -3054,7 +3054,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QPushButton" name="gef_c">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="text">
<string>对 GO 富集文件进行分类</string>
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,20 @@
教程可见:[Juse's blog](https://jusetiz.github.io/)

若存在报错 Bug 可以联系 Juse 修复。

目前已经实现的功能:

- 提取最长转录本。*(已实现)*
- 根据 id 提取序列。*(已实现)*
- 对序列的 id 进行各种处理。*(已实现)*
- 串联序列并得到分区信息。*(已实现)*
- 批量进行序列格式转换。*(已实现)*
- 批量提取 Orthofinder 的 orthogroup 对应的 CDS 序列。*(已实现)*
- 批量进行序列的物种数和长度过滤。*(已实现)*
- 火山图绘制。*(已实现)*
- 气泡图绘制。*(已实现)*

目前已有的小功能:

- 学习计时器。
- 批量改后缀。
Binary file modified __pycache__/Juse_toolkit.cpython-310.pyc
Binary file not shown.
Binary file modified __pycache__/plot.cpython-310.pyc
Binary file not shown.
Binary file modified __pycache__/ui_1.cpython-310.pyc
Binary file not shown.
Binary file modified __pycache__/wz_ui.cpython-310.pyc
Binary file not shown.
30 changes: 29 additions & 1 deletion plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,32 @@ def plot_GOem(file_path, num = 20, xlab = 'GeneRatio', ylab = 'Description'):
plt.ylabel('GO Description', fontsize=12)

plt.tight_layout()
plt.show()
plt.show()


def read_golist(filepath):

golist = {}
with open(filepath, 'r') as f:

for line in f:
if line.startswith('id:'):
GOid = line.lstrip('id:').strip()
golist[GOid] = {}
if line.startswith('name:'):
GOname = line.lstrip('name:').strip()
golist[GOid]['description'] = GOname
if line.startswith('namespace:'):
GOonto = line.lstrip('namespace:').strip()
golist[GOid]['ontology'] = GOonto

return golist


def assign_go(file_path, golist):

data = pd.read_csv(file_path)
data['Description'] = data['ID'].apply(lambda x: golist.get(x, {}).get('description', 'NA(Obsolete)'))
data['Ontology'] = data['ID'].apply(lambda x: golist.get(x, {}).get('ontology', 'NA(Obsolete)'))
dirpath = os.path.dirname(file_path)
data.to_csv(f'{dirpath}/GOanno.csv', index=False)
2 changes: 1 addition & 1 deletion ui_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def eventFilter(self, source, event):
source.setText(file_path)
return True

if source in [self.cds_input_text, self.vol_file, self.enrich_file]:
elif source in [self.cds_input_text, self.vol_file, self.enrich_file]:
if event.type() == QEvent.DragEnter:
if event.mimeData().hasUrls():
event.acceptProposedAction()
Expand Down
28 changes: 26 additions & 2 deletions ui_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from PyQt5.QtCore import QUrl, QEvent, QTimer
from PyQt5.QtGui import QDesktopServices, QIcon
from ui_1 import MyApp
from plot import plot_GOem, plot_GOem_classify
from plot import plot_GOem, plot_GOem_classify, read_golist, assign_go
import sys
import os
import urllib.request
Expand All @@ -22,12 +22,14 @@ def __init__(self):
self.enrich_file.installEventFilter(self)
self.gtl_dl.clicked.connect(self.gtlfile_dl)
self.plot_bu_2.clicked.connect(self.GOem_plot)
self.gef_c.clicked.connect(self.GOem_anno)


def gtlfile_dl(self):

gtl_url = 'http://current.geneontology.org/ontology/go-basic.obo'
gtl_fn = 'go_term.list'
if os.path.exists(gtl_fn):
if os.path.exists(gtl_fn) or os.path.exists('go-basic.obo'):
self.show_message_dialog("文件已存在,下载终止")
return
try:
Expand Down Expand Up @@ -58,6 +60,28 @@ def GOem_plot(self):
except Exception as e:
self.show_message_dialog(f"发生错误:{e}\n请检查文件")

def GOem_anno(self):

fp = self.enrich_file.toPlainText()
if fp == '':
self.show_message_dialog("请输入文件路径。")
return

if os.path.exists('go_term.list'):
glfile = 'go_term.list'
elif os.path.exists('go-basic.obo'):
glfile = 'go-basic.obo'
else:
self.show_message_dialog("不存在 GO list 文件,请下载。")
return

golist = read_golist(glfile)
if golist == {}:
self.show_message_dialog("GO list 文件存在错误,请检查。")
return

assign_go(fp, golist)
self.show_message_dialog("请完成注释,请见 GOanno.csv。")

if __name__ == "__main__":
app = QApplication(sys.argv)
Expand Down

0 comments on commit 654ceb5

Please sign in to comment.