IHWpaper 1.24.0
在这个小图中,我们想在不使用k-fold策略的情况下估计RNASeq和eQTL数据集上的权重~协变量函数。下面的图表主要用于演示。
库("IHW")库("dplyr")库("ggplot2")库("grid")库("tidyr")库("cowplot")库("IHWpaper")
Red_col <- scale::hue_pal(h = c(0,360) + 15, c = 100, l = 65, h.start = 0,direction = 1)(1)
加载Bottomly数据集,应用DESeq2,然后IHW与1折。
Bottomly <- analyze_dataset(" Bottomly ")
##注意:设计中的因素级别包含除##字母、数字、“_”和“。”以外的字符。建议(但不是必须)只使用字母、数字和分隔符“_”或“”。,因为这些是安全字符##表示r中的列名[这是一条消息,而不是警告或错误]
估算尺寸因素
##注意:设计中的因素级别包含除##字母、数字、“_”和“。”以外的字符。建议(但不是必须)只使用字母、数字和分隔符“_”或“”。,因为这些是安全字符##表示r中的列名[这是一条消息,而不是警告或错误]
估算离散度
##基因分散估计
均值-色散关系
##注意:设计中的因素级别包含除##字母、数字、“_”和“。”以外的字符。建议(但不是必须)只使用字母、数字和分隔符“_”或“”。,因为这些是安全字符##表示r中的列名[这是一条消息,而不是警告或错误]
最终的离散度估计
##注意:设计中的因素级别包含除##字母、数字、“_”和“。”以外的字符。建议(但不是必须)只使用字母、数字和分隔符“_”或“”。,因为这些是安全字符##表示r中的列名[这是一条消息,而不是警告或错误]
装配模型和测试
##注意:设计中的因素级别包含除##字母、数字、“_”和“。”以外的字符。建议(但不是必须)只使用字母、数字和分隔符“_”或“”。,因为这些是安全字符##表示r中的列名[这是一条消息,而不是警告或错误]
##——替换异常值,并为4个基因进行改装##——DESeq参数'minReplicatesForReplace' = 7 ##——原始计数保存在计数(dds)中
估算离散度
##注意:设计中的因素级别包含除##字母、数字、“_”和“。”以外的字符。建议(但不是必须)只使用字母、数字和分隔符“_”或“”。,因为这些是安全字符##表示r中的列名[这是一条消息,而不是警告或错误]
装配模型和测试
##注意:设计中的因素级别包含除##字母、数字、“_”和“。”以外的字符。建议(但不是必须)只使用字母、数字和分隔符“_”或“”。,因为这些是安全字符##表示r中的列名[这是一条消息,而不是警告或错误]
ihw_res <- ihw(bottomly$pvalue, bottomly$baseMean, 0.1, nfolds=1, nbins=13, nfolds_internal=4L, nsplits_internal=5L)
##只使用1次折叠!只有当你想要学习权重时才使用这个方法,但千万不要用于测试!
绘图:
breaks <- IHW:::stratification_breaks(ihw_res) break_min = min(bottomly$baseMean) breaks_left <- c(break_min,breaks[-length(breaks)]) step_df <- data.frame(weight=weights(ihw_res,levels_only=TRUE), stratum = 1:nlevels(groups_factor(ihw_res))) %>% mutate(baseMean_left = breaks_left[stratum], baseMean_right = breaks[stratum], baseMean_ratio = baseMean_right/baseMean_left = baseMean_left * baseMean_ratio^。2, baseMean_right = baseMean_right *baseMean_ratio^(-.2)) stratum_fun <- function(df){ stratum <- df$stratum weight <- df$weight stratum_left <- stratum[stratum != length(stratum)] weight_left <- weight[stratum_left] baseMean_left <- df$baseMean_right[stratum_left] stratum_right <- stratum[stratum != 1] weight_right <- weight[stratum_right] baseMean_right <- df$baseMean_left[stratum_right] data.frame(stratum_left= stratum_left, weight_left= weight_left, stratum_right = stratum_right, weight_right = weight_right, baseMean_left = baseMean_left, baseMean_right = baseMean_right) } connect_df <- step_df %>% do(stratum_fun(.)) %>% mutate(dashed = factor(ifelse(abs(weight_left - weight_right) > 10^(-4) , TRUE, FALSE), levels=c(FALSE,TRUE))) panel_b <- ggplot(step_df, aes(x=baseMean_left, xend=baseMean_right, y=weight, yend=weight)) + geom_segment(size=0.8, color=red_col)+ geom_segment(data= connect_df, aes(x=baseMean_left, xend=baseMean_right, y=weight_left, yend=weight_right, linetype=dashed), size=0.8, color=red_col)+ scale_x_log10(breaks=c(1,10,100,1000,10000))+ xlab("Mean of normalized counts")+ theme(legend.position=c(0.8,0.4)) + theme(plot.margin = unit(c(1, 1, 2, 1), "lines")) + guides(linetype=FALSE) + theme(axis.title = element_text(face="bold") )
##警告:' guides( = FALSE) '已弃用。请使用' guides( = ## "none") '代替。
panel_b
Ggsave (panel_b, filename="bottomly_1fold_weight_function.pdf", width=7, height=5)
接下来我们加载hQTL示例的数据。在这里,我们用snps、基因和pvalue信息加载数据帧。注意,由于内存问题(完整的数据帧是3 GB),它只包含0.005以下的p值。然而,在做这个缩减之前,我们计算了假设的数量m_groups
在每个地层(地层以组柱定义)中。因此我们可以应用IHW
到缩减的数据集,请参见IHW小插图的高级部分(“高级用法:使用不完整的p值列表”)。
Hqtl_filt <- system. txt。文件(“extdata / real_data”、“hqtl_pvalue_filtered。Rds", package = "IHWpaper") hqtl_filt <- readRDS(hqtl_filt) m_groups <- attr(hqtl_filt, "m_groups") ihw_qtl_res <- ihw(hqtl_filt$pvalue, as.factor(hqtl_filt$group), 0.1, m_groups = m_groups, nfolds=1L, lambda=Inf)
##只使用1次折叠!只有当你想要学习权重时才使用这个方法,但千万不要用于测试!
breaks <- attr(hqtl_filt, "breaks") breaks <- breaks[-1] break_min <- 5000 breaks_left <- c(break_min,breaks[-length(breaks)]) step_df_qtl <- data.frame(weight=weights(ihw_qtl_res,levels_only=TRUE), stratum = 1:nlevels(groups_factor(ihw_qtl_res))) %>% mutate(break_left = breaks_left[stratum], break_right = breaks[stratum], break_ratio = break_right/break_left, break_left =break_left * break_ratio^。2, break_right = break_right *break_ratio^(-.2)) stratum_fun <- function(df){ stratum <- df$stratum weight <- df$weight stratum_left <- stratum[stratum != length(stratum)] weight_left <- weight[stratum_left] break_left <- df$break_right[stratum_left] stratum_right <- stratum[stratum != 1] weight_right <- weight[stratum_right] break_right <- df$break_left[stratum_right] data.frame(stratum_left= stratum_left, weight_left= weight_left, stratum_right = stratum_right, weight_right = weight_right, break_left = break_left, break_right = break_right) } connecting_df_qtl <- step_df_qtl %>% do(stratum_fun(.)) %>% mutate(dashed = factor(ifelse(abs(weight_left - weight_right) > 5, TRUE, FALSE), levels=c(FALSE,TRUE))) panel_f <- ggplot(step_df_qtl, aes(x=break_left, xend=break_right,y=weight, yend=weight)) + geom_segment(size=0.8, color=red_col)+ geom_segment(data= connecting_df_qtl, aes(x=break_left, xend=break_right, y=weight_left, yend=weight_right, linetype=dashed), size=0.8, color=red_col) + scale_x_log10(breaks=c(10^4, 10^5,10^6,10^7)) + xlab("Genomic distance (bp)")+ theme(legend.position=c(0.8,0.4)) + theme(plot.margin = unit(c(1, 1, 2, 1), "lines"))+ guides(linetype=FALSE) + theme(axis.title = element_text(face="bold") )
##警告:' guides( = FALSE) '已弃用。请使用' guides( = ## "none") '代替。
panel_f
Ggsave (panel_f, filename="hqtl_1fold_weight_function.pdf", width=7, height=5)