last updte: 2014-08-27
Install guides
This situation comes from soralind, and it is an extension of this post.
(Minor update 2014-08-16: fix the bug of subroutine weight_sum )
The aim is to sort strings lexicographically NOT alphabetically. For example, an alphabet with predetermined order: T A G C
. For a set of strings: AT AC TG TC
, to list them alphabetically:
AC
AT
TC
TG
lexicographical order:
TG
TC
AT
AC
Similarly, Schwartzian transform by weight is used.
前几天帮别人做了细菌的基因组结构变异分析,有一些体会,特记录于此。
last update: 2015-11-09
Count FASTA record (everyone knows)
grep -c '^>' file.fasta
Remove empty FASTA records
perl -ne ' if (/^>/) { $h = $_; $s =~ s/\s+//g; print "$h$s\n" if length($s) > 0; $s = ""; } else { $s .= $_ } END{$s =~ s/\s+//g; print "$h$s\n" if length($s) > 0;}' t.fa > t2.fa
Easier solution (fasta2tab and tab2fasta are availabe on github):
fasta2tab t.fa -l | awk -F'\t' '$3 > 0' | tab2fasta -l 70 > t2.fa
Here are some recommended wordpress plugins. Plugins in Bold are highly recommended.
last update: 2014-08-28
Security
Basic plugin
Optimization
本文指导初学者在Windows中运行命令行程序。
运行系统命令:
第三方命令行工具的运行方法:
很多问题,特别是编程方面,都能通过搜索引擎快速地获取答案。
首先,选择优秀的搜索引擎:Google。如果无法访问,可临时用必应(Bing)。不建议使用百度、360等搜索引擎。
如果Google不稳定,请不要说Google太差,那是其它的原因(×××),请修改hosts文件,或者翻墙。
对大多数人来讲,并不需要用到很高级的用法,只需要输入几个以空格隔开的关键字即可。不要把搜索引擎当人而输入口语化的疑问句,而要输入关键字来陈述你的问题。
通过设置环境变量,可在无root权限的情况下,用CPAN安装Perl模块到个人目录。
last update: 2015-09-09
编辑~/.bashrc文件,末尾添加如下设置。第一个变量$LOCAL_APP根据自己情况修改,后面可不修改直接复制。
# local app path
LOCAL_APP=$HOME/local/app
# local perl edition
LOCAL_PERL_EDITION=$LOCAL_APP/perl
export PERL5LIB=$LOCAL_PERL_EDITION/lib
export PATH=$LOCAL_PERL_EDITION/bin:$PATH
# local perl lib
LOCAL_PERL_LIB=$LOCAL_APP/perl5
export PERL_LOCAL_LIB_ROOT="$PERL_LOCAL_LIB_ROOT:$LOCAL_PERL_LIB"
export PERL_MB_OPT="--install_base $LOCAL_PERL_LIB"
export PERL_MM_OPT="INSTALL_BASE=$LOCAL_PERL_LIB"
export PERL5LIB=$LOCAL_PERL_LIB/lib/perl5:$PERL5LIB
export PATH=$LOCAL_PERL_LIB/bin:$PATH
偶尔翻翻书Perl,记录一些平时用的少的东西。
last update: 2014-12-10
wantarray(),函数返回上下文判断参考,Perldoc。
sub context_sensitive {
my $context = wantarray();
return qw( List context ) if $context;
say 'Void context' unless defined $context;
return 'Scalar context' unless $context;
}
use integer
临时变量通常情况下能提高性能
use Memoize – Make functions faster by trading space for time。也可自己用临时变量、甚至数据库存储。
print性能: print "$_\n" < print $_. "\n" < print $_, "\n"
Array slices: @cats[-1, -2]; @cats[0 .. 2];
Hash Slices
# %cats already contains elements
@cats{qw( Jack Brad Mars Grumpy )} = (1) x 4;
# equivalent to the initialization:
my %cats = map { $_ => 1 } qw( Jack Brad Mars Grumpy );
# Hash slices make it easy to merge two hashes:
my %addresses = ( ... );
my %canada_addresses = ( ... );
@addresses{ keys %canada_addresses } = values %canada_addresses;
Hash::Util can make hashes safer using lock.