R里面有平滑样条函数,一条命令就好了smooth.spline()
比如我们做基因组测序数据时需要将dosage对GC进行校正,那么
在R中做GC校正就相当简单:
d <- read.table(flex, colClasses = c("numeric", rep("NULL",4), "numeric", "numeric"))#其中设定为numeric的三列为纯数字染色体号、覆盖度、和该bin中的GC含量
select_data$depth_cor <- select_data$depth_scale - smoother(select_data$depth_scale, select_data$GC)
得到的就是校正之后的depth,
重点来关注smoother函数
smoother <- function(depth, gc){
ord = order(gc)
reord = (1 : length(gc))[order(ord)]
result = smooth.spline(depth[ord])
print(result)
return(result$y[reord])
}
其中depth=f(gc)的拟合只用smooth.spline就可以实现。
但是到了python中却很难找到对应的函数,仅仅名字相近的interpolate 函数是
from scipy.interpolate import UnivariateSpline as spline
这个函数,但是其实和R做的还是不同,python相对更加粗一些吧,TM scipy里面那么多细分的函数谁能搞清楚,这点远不如R一个平滑样条用的方便
详细可执行代码参考:https://download.csdn.net/download/abcba101/11941821

本文对比了R和Python中平滑样条函数的使用,重点介绍了R中的smooth.spline()函数在基因组测序数据校正中的应用,并讨论了Python中对应函数的差异。

1万+

被折叠的 条评论
为什么被折叠?



