Perl Shell Wrapper用于管道脚本和命令

时间:2012-07-17 21:41:30

标签: perl shell command bioinformatics pipeline

我正在开展一项生物信息学项目,该项目涉及将不同的脚本和输入参数组合在一起,以分析下一代测序Illumina数据。我需要有关包装器脚本的帮助。回想一下,包装器是嵌入系统命令或实用程序的shell脚本,它接受并将一组参数传递给该命令。围绕复杂的命令行包装脚本简化了调用它。

这是代码的最小代表:

#!/usr/bin/perl
use strict; use warnings;

my $barcode_file= shift;
unless($barcode_file){
    die "missing barcode file location, aborting.\n";
}

my $raw_data_location = '/data/local/samples/';
my $components_location= '~/read_cleanup/';
my $tmp_dir= '/tmp/';

open (FILEIN, $barcode_file) or die "couldn't open $barcode_file for read: $!\n";

while(<FILEIN>){
# input file format (tab delimited):
# Sample_Name    barcode    enzyme    size    paired    seq_file

    /^$/ and next; chomp;

    my ($sample, $barcode, $enzyme, $size, $pe, $seq_file)= split;

    $raw_file_data = "${raw_data_location}$seq_file"; #/data/local/samples/301.fq for instance

    # final output file
    my $final_output_file = "${tmp_dir}${sample}_reconciled_ends.fq"; # /tmp/D1_reconciled_ends.fq for instance

    # if the sample is paired ( 1 - paired, 0 - unpaired)
    if ($pe) {
        my $pipe_cmd= "${components_location}script01.pl $raw_data_file $barcode | ${components_location}script02.pl $enzyme | ${components_location}script03.pl  $size > $final_output_file";
    }
    system($pipe_cmd);

# at this point, $final_output_file should be saved in the
# tmp folder and contain the paired fastq data output

}
close (FILEIN);

基本上,包装器读取barcode.txt文件并循环遍历文件的每一行(样本名称)。对于每个样本名称,它会为管道运行中的每个脚本生成输入参数。如果样本是配对数据,那么我们进行管道运行。管道方案如下:

# the input parameters are "fed" into the script and the output is piped
# as STDIN to the next script.
script01.pl [input parameters] | script02.pl [input parameters] | script03.pl [input parameters] > file.txt

system($piped_cmd)在终端中执行管道运行。

当我尝试从终端运行包装脚本时,我遇到了麻烦:

./wrapper_example.pl barcode.txt

它返回以下错误消息:

sh: 1: /home/user/read_cleanup/script01.pl: not found

有谁知道什么是错的或如何解决这个问题?谢谢。任何建议都非常感谢。

2 个答案:

答案 0 :(得分:1)

好吧,system()语法为system("$command","$args1","$args2")system(@command)其中@command=("$command","$arg1","$arg2")。我宁愿使用后退滴答来运行整个命令链,如 -

if ($pe) {
    `perl ${components_location}script01.pl $raw_data_file $barcode | perl ${components_location}script02.pl $enzyme | perl ${components_location}script03.pl  $size > $final_output_file`;
}

答案 1 :(得分:0)

最有可能的是/home/user/read_cleanup/script01.pl不是可执行文件,或者它的shebang(以#!开头的第一行)指向错误的Perl。如果没有更多细节,就很难进一步排除故障。