-
Notifications
You must be signed in to change notification settings - Fork 2
Add utility functions for PPI analysis and functional enrichment visualization #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
不要到处copy-paste代码,像最新的这个upsetplot,调用aplotExtra即可。 |
其它代码,也检查确认,尽量调用,不要copy。 如果是没有export的函数,可以用 |
R/PPI_utils.R
Outdated
|
||
ppi_subset <- function(ppi_obj, n = NULL, score_cutoff = 0.7) { | ||
|
||
library(igraph) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在R包中的函数里不要library,而是相应的在上面的Rd中用#'@importFrom igraph degree induced_subgraph
这种写法,然后在DESCRIPITION
文件中的import
里去声明igraph
等相应你要导入的包
R/PPI_utils.R
Outdated
#' @param score_cutoff Minimum edge score to keep. Default is 0.7. | ||
#' | ||
#' @return A subgraph of the original PPI network | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果函数是要公开被调用的,需要加#'@export
R/PPI_utils.R
Outdated
stop("Edges must have a 'score' attribute.") | ||
} | ||
|
||
ppi_filtered <- subgraph.edges(ppi_obj, eids = E(ppi_obj)[score >= score_cutoff], delete.vertices = TRUE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个score是哪个向量?前面的E(ppi_obj)$score
?没有定义的话会报错的
R/PPI_utils.R
Outdated
|
||
# 1. extract top n pathways | ||
enrich_df <- enrich_obj@result %>% | ||
dplyr::arrange(p.adjust) %>% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同样的,用.data$p.adjust
去写
R/gglollipop.R
Outdated
plot_title = NULL) | ||
{ | ||
|
||
library(ggplot2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
也是一样的,不用用library
R/gglollipop.R
Outdated
df, | ||
aes(RichFactor, stats::reorder(Description, RichFactor)) | ||
) + | ||
geom_segment(aes(xend = 0, yend = Description)) + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ggplot2语法封装进函数里,也是不能直接用交互式的语法,参考https://github.com/YuLab-SMU/SVP/blob/main/R/methods-plot.R#L155
R/gglollipop.R
Outdated
} | ||
|
||
df <- df %>% | ||
arrange(p.adjust) %>% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tidyverse框架,在函数内部的使用.data$p.adjust
,其他地方我没有发现的也得自己调整
R/gglollipop.R
Outdated
|
||
df$RichFactor <- df$RichFactor %>% round(digits = 2) | ||
|
||
label_wrap <- function(labels) str_wrap(labels, width = text.width) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个str_wrap
用yulab.utils::str_wrap
代替,stringr
软件包太多依赖,有些平台很难安装下载,开发时尽量考虑不调用它,而是用base
一些函数自己写一些基础功能
R/gglollipop.R
Outdated
|
||
p <- ggplot( | ||
df, | ||
aes(RichFactor, stats::reorder(Description, RichFactor)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个写法也是不行的,RichFactor
参考下面的,stats::reorder(Description, RichFactor)参考
https://github.com/YuLab-SMU/ggtree/blob/devel/R/geom_tiplab.R#L162-L170
lollipop图,用 代码尽量简单,能调用我们已有代码的尽量调用,这样方便维护。 |
lollipop已进一步使用enrichplot完善 |
其它的代码也要查一下,不要到处copy。你看我公众号,也知道以前有个人,到处copy了,要建立良好的习惯。 |
use 'aplotExtra:::get_all_subsets_items' as default for getting the intersection result
老师好,目前函数能调用的都调用了。之前是因为upset_plot还没有merge,所以就先source()源码拿来测试了,现已删除,并在新示例中改为aplotExtra::upset_plot()进行调用。 |
PPI_utils.R now includes 'PPI_subset()' and 'getPieData()' functions:
'PPI_subset()' : Subsets STRING PPI network data based on a selected gene list and confidence score.
'getpiedata()': Generates summary data for pie chart visualization based on PPI results.
gglollipop.R now includes 'gglollipop()':
'gglollipop()' : Generates lollipop plots for enrichment results.