生信人值得拥有的编程模板-Shell

前言

“工欲善其事必先利其器”,生信工程师每天写代码、搭流程,而且要使用至少三门编程语言,没有个好集成开发环境(IDE,Integrated Development Environment)那怎么行?

本人使用过vim, editplus, ultraedit, notepad++, sublime。感觉在多语言支持、直接远程编辑脚本、启动速度等方面还是editplus用着比较舒服,适合我的个人习惯。

Editplus 下载和安装

最好官网下载最新版4.3,喜欢的话正版才30$,关键是不注册也不影响使用。
https://www.editplus.com/download.html
有32/64位版,建议安装64位版epp430_64bit.exe,还有中文版(不建议,全是老版本),英语拼写检查(安装了没看到效果);

先安装完成后,打开,会出现配置设置、语法文件位置选择,如下图
建议修改到自己的目录,方便管理和备份,如改为C:\Users\woodc\Desktop\home\soft\editplus

生信人值得拥有的编程模板-Shell_第1张图片

如果不想看到试用字样,百度可以找到很多注册机/注册码,很容易激活。

添加Perl语言模板

该程序对Perl语法默认支持已经非常好了,只是缺少个生信专用模板,参考我的上篇文章
生信人写程序1. Perl语言模板及配置

右键另存下载perl模板文件直接单击可能会报错,因为Perl的pl文件是也属于网页的一种,会被运行,而内容又不是网页,所以报错。

主要操作如下:将《Perl语言模板》原文中代码复制到editplus中新建的空白文件,点保存;
第一种情况:如果刚才设置了新的模板目录,请选择你自己设置的目录,替换template.pl。
第二种情况:没有更改配件文件目录,默认的保存位置可替换template.pl即可。
如果下次使用新建Perl不能自动加载模板,可以尝试将模板代码保存为template.pl在任何位置,选择Tools - Preference - template — Perl,更改template.pl文件位置为刚才保存的模板template.pl文件即可。

生信人值得拥有的编程模板-Shell_第2张图片

以后点新建- perl会自己加载我们配置的模板开使写新程序;其实我们更多是找写过相近的程序再修改,这个过程是逐渐积累的,领域和用途不同,自己的常用功能也是很个性化的。

添加Shell语言支持

https://www.editplus.com/others.html
选择* Shell stx - 肖俊斌 (2011-06-21)下载,解压后有shell.stx语法文件放在之前设置的目录;也可直接右键点我下载shell语法
再选择
Tools — Preference — Setting & syntax, Add - 输入 “Shell” — OK, 文件扩展添”sh”,语法文件选择下载的shell.stx;点OK;

生信人值得拥有的编程模板-Shell_第3张图片

Shell写作模板

主要包括命令行参数解析、默认参数设置、程序功能描述及帮助文档等

右键另存下载Shell模板文件

#!/bin/bash
set -e

# 设置程序参数的缺省值,少用参数即可运行
# 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:       [email protected]
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

# 输入输出文件格式和示例,非常有用,不知道格式怎么准备文件呀
# 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 factor

2. Volcano plot: vol_otu_SampleAvsSampleB.pdf

# 参数描述,写清功能的缺省值
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
}

# 解释命令行参数,是不是很面熟,其实是调用了perl语言的getopts包,
# Analysis parameter
while getopts "d:h:i:o:" OPTION
do
    case $OPTION in
        d)
            database=$OPTARG
            ;;
        h)
            usage
            exit 1
            ;;
        i)
            input=$OPTARG
            ;;
        o)
            output=$OPTARG
            ;;
        ?)
            usage
            exit 1
            ;;
    esac
done

# for 循环批量调用程序,如批量绘制热图
# 有多种批量输入文件的方式,以下N种任选其一,其它用#注释掉
for i in a.txt b.txt n.txt; do # 文件不多,手动放在in后用空格分开
for i in `seq 1 9`; do # 文字名为数字顺序,用seq命令生成连续数据,引用命令需反引
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发Nature Cell专刊 肠道指挥大脑

系列教程:微生物组入门 Biostar 微生物组  宏基因组

专业技能:学术图表 高分文章 生信宝典 不可或缺的人

一文读懂:宏基因组 寄生虫益处 进化树

必备技能:提问 搜索  Endnote

文献阅读 热心肠 SemanticScholar Geenmedical

扩增子分析:图表解读 分析流程 统计绘图

16S功能预测   PICRUSt  FAPROTAX  Bugbase Tax4Fun

在线工具:16S预测培养基 生信绘图

科研经验:云笔记  云协作 公众号

编程模板: Shell  R Perl

生物科普:  肠道细菌 人体上的生命 生命大跃进  细胞暗战 人体奥秘  

写在后面

为鼓励读者交流、快速解决科研困难,我们建立了“宏基因组”专业讨论群,目前己有国内外5000+ 一线科研人员加入。参与讨论,获得专业解答,欢迎分享此文至朋友圈,并扫码加主编好友带你入群,务必备注“姓名-单位-研究方向-职称/年级”。技术问题寻求帮助,首先阅读《如何优雅的提问》学习解决问题思路,仍末解决群内讨论,问题不私聊,帮助同行。

学习16S扩增子、宏基因组科研思路和分析实战,关注“宏基因组”

点击阅读原文,跳转最新文章目录阅读

你可能感兴趣的:(生信人值得拥有的编程模板-Shell)