Skip to content

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

Open
wants to merge 43 commits into
base: master
Choose a base branch
from

Conversation

Hinna0818
Copy link

@Hinna0818 Hinna0818 commented May 15, 2025

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.

@GuangchuangYu GuangchuangYu requested a review from xiangpin May 16, 2025 01:25
@GuangchuangYu
Copy link
Member

不要到处copy-paste代码,像最新的这个upsetplot,调用aplotExtra即可。

@GuangchuangYu
Copy link
Member

其它代码,也检查确认,尽量调用,不要copy。

如果是没有export的函数,可以用getFromNamespace()

R/PPI_utils.R Outdated

ppi_subset <- function(ppi_obj, n = NULL, score_cutoff = 0.7) {

library(igraph)
Copy link
Member

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

Copy link
Member

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)
Copy link
Member

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) %>%
Copy link
Member

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)
Copy link
Member

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)) +
Copy link
Member

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) %>%
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个str_wrapyulab.utils::str_wrap代替,stringr软件包太多依赖,有些平台很难安装下载,开发时尽量考虑不调用它,而是用base一些函数自己写一些基础功能

R/gglollipop.R Outdated

p <- ggplot(
df,
aes(RichFactor, stats::reorder(Description, RichFactor))
Copy link
Member

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

@GuangchuangYu
Copy link
Member

lollipop图,用enrichplot::dotplot()就可以了,再加上一层geom_segment(),再用p$layers <- rev(p$layers),把线图搞成底层,需要调颜色等细节再+scale_()去弄。

代码尽量简单,能调用我们已有代码的尽量调用,这样方便维护。

@Hinna0818
Copy link
Author

lollipop已进一步使用enrichplot完善

@GuangchuangYu
Copy link
Member

其它的代码也要查一下,不要到处copy。你看我公众号,也知道以前有个人,到处copy了,要建立良好的习惯。

Hinna0818 and others added 5 commits June 6, 2025 12:20
use 'aplotExtra:::get_all_subsets_items' as default for getting the intersection result
@Hinna0818
Copy link
Author

其它的代码也要查一下,不要到处copy。你看我公众号,也知道以前有个人,到处copy了,要建立良好的习惯。

老师好,目前函数能调用的都调用了。之前是因为upset_plot还没有merge,所以就先source()源码拿来测试了,现已删除,并在新示例中改为aplotExtra::upset_plot()进行调用。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants