简体   繁体   English

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

[英]Perl Shell Wrapper for piping scripts and commands

I'm working on a bioinformatics project that involves piping together different scripts and input parameters for the analysis of Next-Gen Sequencing Illumina data. 我正在从事一个生物信息学项目,该项目涉及将不同的脚本和输入参数汇总在一起,用于分析下一代测序Illumina数据。 I need help with the wrapper script. 我需要有关包装脚本的帮助。 Recall that a wrapper is a shell script that embeds a system command or utility, that accepts and passes a set of parameters to that command. 回想一下包装器是一个嵌入了系统命令或实用程序的外壳程序脚本,该脚本接受或传递一组参数到该命令。 Wrapping a script around a complex command-line simplifies invoking it. 将脚本包装在复杂的命令行中可以简化调用。

Here's a minimal representation of the code: 这是代码的最小表示形式:

#!/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);

Basically the wrapper reads the barcode.txt file and loops through each line (sample name) of the file. 基本上,包装程序将读取条形码.txt文件,并在文件的每一行(样本名称)之间循环。 For each sample name, it generates the input parameters for each script in the the piped run. 对于每个样本名称,它为管道运行中的每个脚本生成输入参数。 If the sample is paired data, then we do a piped run. 如果样本是配对数据,那么我们将进行管道运行。 The piping scheme goes like this: 管道方案如下所示:

# 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) executes the piped run in the terminal. system($piped_cmd)在终端中执行管道运行。

Here's where I'm getting trouble, when I try to run the wrapper script from the terminal: 当我尝试从终端运行包装器脚本时,这就是我遇到麻烦的地方:

./wrapper_example.pl barcode.txt

It returns the following error message: 它返回以下错误消息:

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

Does anyone know what's wrong or how to fix this? 有谁知道怎么了或如何解决这个问题? thanks. 谢谢。 Any suggestions are greatly appreciated. 任何建议,不胜感激。

Well, system() syntax is system("$command","$args1","$args2") OR system(@command) where @command=("$command","$arg1","$arg2") . 嗯, system()语法是system("$command","$args1","$args2")system(@command) ,其中@command=("$command","$arg1","$arg2") I would rather use back ticks to run the whole chain of commands like- 我宁愿使用反跳号来运行整个命令链,例如-

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`;
}

Most likely, /home/user/read_cleanup/script01.pl is not an executable, OR its shebang (first line starting with #! ) points to the wrong Perl. /home/user/read_cleanup/script01.pl很可能不是可执行文件,或者它的shebang(以#!开头的第一行)指向错误的Perl。 It's kind of difficult to troubleshoot further without a bit more details. 如果没有更多细节,很难进行进一步的故障排除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM