Lefse
最近在折騰lefse分析颂砸,linux下直接用conda安裝LEfSe沒(méi)成功(conda install -c biobakery lefse或conda install -c bioconda lefse)胀屿,基本安裝最后都報(bào)錯(cuò)疹味。因?yàn)閯傞_(kāi)始接觸Linux拟烫,不懂這些錯(cuò)誤列敲,也沒(méi)有深究荚孵。因?yàn)閘efse是調(diào)用R包和python進(jìn)行的分析掷倔,因此參照CSDN吳蘇博文在Ubuntu中手動(dòng)配置R和python環(huán)境较剃,然后調(diào)用函數(shù)進(jìn)行分析
refs:
https://blog.csdn.net/qq_38854576/article/details/86763650
https://cloud.tencent.com/developer/article/1667023
https://zhuanlan.zhihu.com/p/265681612 # 后面兩個(gè)用conda安裝的博主
Method1-Win10 Ubuntu
## win10下子系統(tǒng)請(qǐng)參照劉永鑫老師博客文章進(jìn)行安裝咕别,這里不做贅述
## ref: https://mp.weixin.qq.com/s/0PfA0bqdvrEbo62zPVq4kQ
## 建立一個(gè)環(huán)境
(base) ly@LAPTOP-DHF4UD6Q:~$ conda create --name lefse python=2.7 r=3.6
(base) ly@LAPTOP-DHF4UD6Q:~$ conda activate lefse #激活lefse環(huán)境
(lefse) ly@LAPTOP-DHF4UD6Q:~$ conda env list
# conda environments:
#
base /home/ly/miniconda3
lefse * /home/ly/miniconda3/envs/lefse
## 配置所需R包
## 笨方法,直接進(jìn)入R環(huán)境写穴,install.packages()安裝需要用到的R包
(lefse) ly@LAPTOP-DHF4UD6Q:~$ R
>>> install.packages("MASS")
## 簡(jiǎn)書(shū)—靈木er博主也給出了另一種方法惰拱, 建立一個(gè)R腳本,在Ubuntu里運(yùn)行
## ref: http://www.reibang.com/p/fa554a029c0e
## 后面不再添加 (lefse) ly@LAPTOP-DHF4UD6Q:~$
cat > installr.R << EOF
options("repos" = c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/"))
package_list <- c("splines","stats4","survival", "mvtnorm", "modeltools", "coin", "MASS")
for(p in package_list){
if(!suppressWarnings(suppressMessages(require(p, character.only = TRUE, quietly = TRUE, warn.conflicts = FALSE)))){
install.packages(p)
suppressWarnings(suppressMessages(library(p, character.only = TRUE, quietly = TRUE, warn.conflicts = FALSE)))
}
}
EOF
Rscript installr.R #運(yùn)行R腳本
## 配置python包
## rpy2 (v. 2.1 or higher), numpy, matplotlib (v. 1.0 or higher), argparse
## 因?yàn)槲也恍枰猰atplotlib畫(huà)圖啊送,就沒(méi)裝這個(gè)
conda install numpy
conda install argparse
## rpy2安裝參照上面靈木er博文
## 默認(rèn)下載在/home/ly/目錄下
wget -c https://files.pythonhosted.org/packages/32/54/d102eec14f9cabd0df60682a38bd45c36169a1ec8fb8a690bf436cb6d758/rpy2-2.8.6.tar.gz
tar xzvf rpy2-2.8.6.tar.gz
cd rpy2-2.8.6
python2 setup.py install
## github獲得lefse源代碼文件
## 我下的是2016年的1.0.8版本
wget -c https://github.com/biobakery/lefse/archive/1.0.8.tar.gz
tar xzvf 1.0.8.tar.gz
cd lefse-1.0.8
## 檢驗(yàn)主函數(shù)調(diào)用
## 參數(shù) -c -u見(jiàn)解釋
(lefse) ly@LAPTOP-DHF4UD6Q:~/lefse-1.0.8$ format_input.py -h
usage: format_input.py [-h] [--output_table OUTPUT_TABLE] [-f {c,r}]
[-c [1..n_feats]] [-s [1..n_feats]] [-o float]
[-u [1..n_feats]] [-m {f,s}] [-n int]
[-biom_c BIOM_CLASS] [-biom_s BIOM_SUBCLASS]
INPUT_FILE OUTPUT_FILE
LEfSe formatting modules
positional arguments:
INPUT_FILE the input file, feature hierarchical level can be
specified with | or . and those symbols must not be
present for other reasons in the input file.
OUTPUT_FILE the output file containing the data for LEfSe
optional arguments:
-h, --help show this help message and exit
--output_table OUTPUT_TABLE
the formatted table in txt format
-f {c,r} set whether the features are on rows (default) or on
columns
-c [1..n_feats] set which feature use as class (default 1)
-s [1..n_feats] set which feature use as subclass (default -1 meaning
no subclass)
-o float set the normalization value (default -1.0 meaning no
normalization)
-u [1..n_feats] set which feature use as subject (default -1 meaning
no subject)
-m {f,s} set the policy to adopt with missin values: f removes
the features with missing values, s removes samples
with missing values (default f)
-n int set the minimum cardinality of each subclass
(subclasses with low cardinalities will be grouped
together, if the cardinality is still low, no pairwise
comparison will be performed with them)
-biom_c BIOM_CLASS For biom input files: Set which feature use as class
-biom_s BIOM_SUBCLASS
For biom input files: set which feature use as
subclass
## 檢驗(yàn)主函數(shù)調(diào)用
## 參數(shù)-l 2定義LDA的檢驗(yàn)閾值
(lefse) ly@LAPTOP-DHF4UD6Q:~/lefse-1.0.8$ run_lefse.py -h
usage: run_lefse.py [-h] [-o str] [-a float] [-w float] [-l float]
[--nlogs int] [--verbose int] [--wilc int] [-r str]
[--svm_norm int] [-b int] [-e int] [-c int] [-f float]
[-s {0,1,2}] [--min_c int] [-t str] [-y {0,1}]
INPUT_FILE OUTPUT_FILE
LEfSe 1.0
positional arguments:
INPUT_FILE the input file
OUTPUT_FILE the output file containing the data for the visualization
module
optional arguments:
-h, --help show this help message and exit
-o str set the file for exporting the result (only concise textual
form)
-a float set the alpha value for the Anova test (default 0.05)
-w float set the alpha value for the Wilcoxon test (default 0.05)
-l float set the threshold on the absolute value of the logarithmic
LDA score (default 2.0)
--nlogs int max log ingluence of LDA coeff
--verbose int verbose execution (default 0)
--wilc int wheter to perform the Wicoxon step (default 1)
-r str select LDA or SVM for effect size (default LDA)
--svm_norm int whether to normalize the data in [0,1] for SVM feature
waiting (default 1 strongly suggested)
-b int set the number of bootstrap iteration for LDA (default 30)
-e int set whether perform the wilcoxon test only among the
subclasses with the same name (default 0)
-c int set whether perform the wilcoxon test ing the Curtis's
approach [BETA VERSION] (default 0)
-f float set the subsampling fraction value for each bootstrap
iteration (default 0.66666)
-s {0,1,2} set the multiple testing correction options. 0 no correction
(more strict, default), 1 correction for independent
comparisons, 2 correction for independent comparison
--min_c int minimum number of samples per subclass for performing
wilcoxon test (default 10)
-t str set the title of the analysis (default input file without
extension)
-y {0,1} (for multiclass tasks) set whether the test is performed in
a one-against-one ( 1 - more strict!) or in a one-against-
all setting ( 0 - less strict) (default 0)
## 分析運(yùn)行
## 將win10本地盤(pán)文件copy到 /home/ly/lefse-1.0.8分析
cd /mnt/e/Python/lefse/
cp pathway_sel_lefse_Wagner.txt /home/ly/lefse-1.0.8
cd ~
cd lefse-1.0.8
format_input.py pathway_sel_lefse_Wagner.txt A_lefse_test.in -c 1 -u 2 -o 1000000
run_lefse.py A_lefse_test.in lefse.out.txt -l 3
Method2-Win10 cmd
具體安裝需求參照吳蘇博文
ref: https://blog.csdn.net/qq_38854576/article/details/86763650
E:\Python\lefse>format_input.py pathway_sel_lefse_Wagner.txt A_lefse_test.in -c 1 -u 2 -o 1000000
usage: format_input.py [-h] [--output_table OUTPUT_TABLE] [-f {c,r}]
[-c [1..n_feats]] [-s [1..n_feats]] [-o float]
[-u [1..n_feats]] [-m {f,s}] [-n int]
[-biom_c BIOM_CLASS] [-biom_s BIOM_SUBCLASS]
INPUT_FILE OUTPUT_FILE
format_input.py: error: too few arguments
## 依然出現(xiàn)這個(gè)問(wèn)題偿短,暫時(shí)無(wú)解
Method3-R實(shí)現(xiàn)
此方法主要參照公眾號(hào)微生信生物 文濤老師的代碼
博文題目:把握LEfSe核心算法使用R實(shí)現(xiàn)整套算法
ref:https://mp.weixin.qq.com/s?__biz=MzUzMjYyMDE2OQ==&mid=2247487316&idx=2&sn=0d21754b4c5cdee690a05ff865627037&chksm=fab139b2cdc6b0a4055491e803d67d4dce9b69d2c21098648124a72fcd56dfc6013a98a495e1&mpshare=1&scene=23&srcid=0204YyUGkk7q2tnh6HraCf4Z&sharer_sharetime=1612782715958&sharer_shareid=21a8baa175f8629f0dc4f5b4b45a0f28#rd
## 詳細(xì)代碼不在此貼出,自己搜索
## 此處有個(gè)小疑問(wèn)馋没,此處公式計(jì)算的LDA score, 即從lda函數(shù)計(jì)算的分組均值中用較大的-較小的昔逗,然后去對(duì)數(shù)
## 而Tax4Fun計(jì)算得出的功能基因、通路豐度均是相對(duì)豐度篷朵,值在[0,1]之間勾怒,那么導(dǎo)入此處公式計(jì)算的LDA score均是小于2
## LDA score = 2, 則 abs(ldamean$max-ldamean$min)/2項(xiàng)的值至少為99,而使用相對(duì)豐度肯定不成
ldamean$LDAscore <- signif(log10(1+abs(ldamean$max-ldamean$min)/2),digits=3)
## 而采用PICRUSt得出的功能基因、通路豐度多是絕對(duì)豐度控硼,那么對(duì)于某個(gè)基因或通路泽论,組間均值的差值很容易超過(guò)99吧?卡乾?
## 畢竟這些豐度值都比較大翼悴。那么lefse算法如何處理這個(gè)問(wèn)題。
## format_input.py函數(shù)的參數(shù)-o float定義了標(biāo)準(zhǔn)化值(set the normalization value)
## 不知此處如何處理幔妨,python的源代碼不太熟悉鹦赎,待以后在深挖吧。误堡。古话。。