微生物lefse分析


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

未標(biāo)題-1.jpg

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的源代碼不太熟悉鹦赎,待以后在深挖吧。误堡。古话。。


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末锁施,一起剝皮案震驚了整個(gè)濱河市陪踩,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌悉抵,老刑警劉巖肩狂,帶你破解...
    沈念sama閱讀 206,214評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異姥饰,居然都是意外死亡傻谁,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,307評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門(mén)列粪,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)审磁,“玉大人,你說(shuō)我怎么就攤上這事岂座√伲” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 152,543評(píng)論 0 341
  • 文/不壞的土叔 我叫張陵掺逼,是天一觀的道長(zhǎng)吃媒。 經(jīng)常有香客問(wèn)我,道長(zhǎng)吕喘,這世上最難降的妖魔是什么赘那? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 55,221評(píng)論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮氯质,結(jié)果婚禮上募舟,老公的妹妹穿的比我還像新娘。我一直安慰自己闻察,他們只是感情好拱礁,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,224評(píng)論 5 371
  • 文/花漫 我一把揭開(kāi)白布琢锋。 她就那樣靜靜地躺著,像睡著了一般呢灶。 火紅的嫁衣襯著肌膚如雪吴超。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 49,007評(píng)論 1 284
  • 那天鸯乃,我揣著相機(jī)與錄音鲸阻,去河邊找鬼。 笑死缨睡,一個(gè)胖子當(dāng)著我的面吹牛鸟悴,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播奖年,決...
    沈念sama閱讀 38,313評(píng)論 3 399
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼细诸,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了陋守?” 一聲冷哼從身側(cè)響起震贵,我...
    開(kāi)封第一講書(shū)人閱讀 36,956評(píng)論 0 259
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎嗅义,沒(méi)想到半個(gè)月后屏歹,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體隐砸,經(jīng)...
    沈念sama閱讀 43,441評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡之碗,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,925評(píng)論 2 323
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了季希。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片褪那。...
    茶點(diǎn)故事閱讀 38,018評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖式塌,靈堂內(nèi)的尸體忽然破棺而出博敬,到底是詐尸還是另有隱情,我是刑警寧澤峰尝,帶...
    沈念sama閱讀 33,685評(píng)論 4 322
  • 正文 年R本政府宣布偏窝,位于F島的核電站,受9級(jí)特大地震影響武学,放射性物質(zhì)發(fā)生泄漏祭往。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,234評(píng)論 3 307
  • 文/蒙蒙 一火窒、第九天 我趴在偏房一處隱蔽的房頂上張望硼补。 院中可真熱鬧,春花似錦熏矿、人聲如沸已骇。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,240評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)褪储。三九已至卵渴,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間鲤竹,已是汗流浹背奖恰。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,464評(píng)論 1 261
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留宛裕,地道東北人瑟啃。 一個(gè)月前我還...
    沈念sama閱讀 45,467評(píng)論 2 352
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像揩尸,于是被迫代替她去往敵國(guó)和親蛹屿。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,762評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容