引用另一模板的宏_生信人值得拥有的编程模板Shell
前言
“工欲善其事必先利其器”,生信工程師每天寫代碼、搭流程,而且要使用至少三門編程語言,沒有個好集成開發(fā)環(huán)境(IDE,Integrated Development Environment)那怎么行?
本人使用過vim, editplus, ultraedit, notepad++, sublime。感覺在多語言支持、直接遠(yuǎn)程編輯腳本、啟動速度等方面還是editplus用著比較舒服,適合我的個人習(xí)慣。
Editplus 下載和安裝
最好官網(wǎng)下載最新版4.3,喜歡的話正版才30$,關(guān)鍵是不注冊也不影響使用。
https://www.editplus.com/download.html
有32/64位版,建議安裝64位版epp430_64bit.exe,還有中文版(不建議,全是老版本),英語拼寫檢查(安裝了沒看到效果);
先安裝完成后,打開,會出現(xiàn)配置設(shè)置、語法文件位置選擇,如下圖
建議修改到自己的目錄,方便管理和備份,如改為C:\Users\woodc\Desktop\home\soft\editplus
如果不想看到試用字樣,百度可以找到很多注冊機/注冊碼,很容易激活。
添加Perl語言模板
該程序?qū)erl語法默認(rèn)支持已經(jīng)非常好了,只是缺少個生信專用模板,參考我的上篇文章
生信人寫程序1. Perl語言模板及配置
右鍵另存下載perl模板文件直接單擊可能會報錯,因為Perl的pl文件是也屬于網(wǎng)頁的一種,會被運行,而內(nèi)容又不是網(wǎng)頁,所以報錯。
主要操作如下:將《Perl語言模板》原文中代碼復(fù)制到editplus中新建的空白文件,點保存;
第一種情況:如果剛才設(shè)置了新的模板目錄,請選擇你自己設(shè)置的目錄,替換template.pl。
第二種情況:沒有更改配件文件目錄,默認(rèn)的保存位置可替換template.pl即可。
如果下次使用新建Perl不能自動加載模板,可以嘗試將模板代碼保存為template.pl在任何位置,選擇Tools - Preference - template — Perl,更改template.pl文件位置為剛才保存的模板template.pl文件即可。
以后點新建- perl會自己加載我們配置的模板開使寫新程序;其實我們更多是找寫過相近的程序再修改,這個過程是逐漸積累的,領(lǐng)域和用途不同,自己的常用功能也是很個性化的。
添加Shell語言支持
https://www.editplus.com/others.html
選擇* Shell stx - 肖俊斌 (2011-06-21)下載,解壓后有shell.stx語法文件放在之前設(shè)置的目錄;也可直接右鍵點我下載shell語法
再選擇
Tools — Preference — Setting & syntax, Add - 輸入 “Shell” — OK, 文件擴展添”sh”,語法文件選擇下載的shell.stx;點OK;
Shell寫作模板
主要包括命令行參數(shù)解析、默認(rèn)參數(shù)設(shè)置、程序功能描述及幫助文檔等
右鍵另存下載Shell模板文件
#!/bin/bash set -e# 設(shè)置程序參數(shù)的缺省值,少用參數(shù)即可運行 # Default parameter input=input.txt output=output.txt database=database.txt execute='TRUE'# 程序功能描述,每次必改程序名、版本、時間等;版本更新要記錄清楚,一般可用-h/-?來顯示這部分 # Function for script description and usage usage() { cat <&2 Usage: ------------------------------------------------------------------------------- Filename: ? ?template.sh Revision: ? ?1.0 Date: ? ? ? ?2017/6/24 Author: ? ? ?Yong-Xin Liu Email: ? ? ? yxliu@genetics.ac.cn Website: ? ? http://bailab.genetics.ac.cn/ Description: This script is solve parameter read and default Notes: ? ? ? Function of this script ------------------------------------------------------------------------------- Copyright: ? 2017 (c) Yong-Xin Liu License: ? ? GPL This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. If any changes are made to this script, please mail me a copy of the changes ------------------------------------------------------------------------------- Version 1.0 2017/6/24# 輸入輸出文件格式和示例,非常有用,不知道格式怎么準(zhǔn)備文件呀 # Input files: input.txt, can inclue many file# 1. input.txt, design of expriment SampleID ? ?BarcodeSequence ? ?group WT.1 ? ?TAGCTT ? ?WT ? ? WT.2 ? ?GGCTAC ? ?WT WT.3 ? ?CGCGCG ? ?WT# 2. database.txt, annotation of gene ID ? ?description AT3G48300 ? ?Transcript factor# Output file 1. Annotated samples & DE genes Samples ? ?ID ? ?description Wt ? ?AT3G48300 ? ?Transcript factor2. Volcano plot: vol_otu_SampleAvsSampleB.pdf# 參數(shù)描述,寫清功能的缺省值 OPTIONS:-d database file, default database.txt-i input file, recommend must give-o output file or output directory, default output.txt-h/? show help of script Example:template.sh -i input.txt -d database.txt -o result.txt EOF }# 解釋命令行參數(shù),是不是很面熟,其實是調(diào)用了perl語言的getopts包, # Analysis parameter while getopts "d:h:i:o:" OPTION docase $OPTION ind)database=$OPTARG;;h)usageexit 1;;i)input=$OPTARG;;o)output=$OPTARG;;?)usageexit 1;;esac done# for 循環(huán)批量調(diào)用程序,如批量繪制熱圖
# 有多種批量輸入文件的方式,以下N種任選其一,其它用#注釋掉for i in a.txt b.txt n.txt; do # 文件不多,手動放在in后用空格分開
for i in `seq 1 9`; do # 文字名為數(shù)字順序,用seq命令生成連續(xù)數(shù)據(jù),引用命令需反引for i in `ls data/*.txt`; do # 匹配某類文件作為輸入for i in `cat list.txt`; do # 使用文本原為輸入列表for i in `cat list.txt|cut -f 1`; do # 指定某列作為輸入文件名
? ?plot_heatmap.sh -i data/${i} -o heatmap/${i}.pdf
done
將以上代碼保存為template.sh,點擊Tools — Preference — Template — Add 命名為Shell,選擇template.sh文件,OK。
以后點New file, 選擇shell即自動加載模板;
想要寫好程序,多讀多寫代碼才會有提高,只看不操作效果最差。
猜你喜歡
10000+:菌群分析?寶寶與貓狗?梅毒狂想曲 提DNA發(fā)Nature?Cell專刊?腸道指揮大腦
系列教程:微生物組入門 Biostar 微生物組 ?宏基因組
專業(yè)技能:學(xué)術(shù)圖表?高分文章?生信寶典 不可或缺的人
一文讀懂:宏基因組 寄生蟲益處 進(jìn)化樹
必備技能:提問 搜索 ?Endnote
文獻(xiàn)閱讀 熱心腸 SemanticScholar Geenmedical
擴增子分析:圖表解讀 分析流程 統(tǒng)計繪圖
16S功能預(yù)測 ? PICRUSt ?FAPROTAX ?Bugbase Tax4Fun
在線工具:16S預(yù)測培養(yǎng)基 生信繪圖
科研經(jīng)驗:云筆記 ?云協(xié)作 公眾號
編程模板:?Shell ?R Perl
生物科普:??腸道細(xì)菌?人體上的生命?生命大躍進(jìn) ?細(xì)胞暗戰(zhàn) 人體奧秘 ?
寫在后面
為鼓勵讀者交流、快速解決科研困難,我們建立了“宏基因組”專業(yè)討論群,目前己有國內(nèi)外3000+ 一線科研人員加入。參與討論,獲得專業(yè)解答,歡迎分享此文至朋友圈,并掃碼加主編好友帶你入群,務(wù)必備注“姓名-單位-研究方向-職稱/年級”。PI請明示身份,另有海內(nèi)外微生物相關(guān)PI群供大佬合作交流。技術(shù)問題尋求幫助,首先閱讀《如何優(yōu)雅的提問》學(xué)習(xí)解決問題思路,仍末解決群內(nèi)討論,問題不私聊,幫助同行。
學(xué)習(xí)16S擴增子、宏基因組科研思路和分析實戰(zhàn),關(guān)注“宏基因組”
總結(jié)
以上是生活随笔為你收集整理的引用另一模板的宏_生信人值得拥有的编程模板Shell的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 中国到底需要多少博士点?
- 下一篇: 甘蔗是怎么变成白糖的?