Regex 在perl中制作一个将Fastas拆分为工作的gawk comand
您好,我正在使用此gawk命令拆分Fasta文件:Regex 在perl中制作一个将Fastas拆分为工作的gawk comand,regex,perl,awk,system,Regex,Perl,Awk,System,您好,我正在使用此gawk命令拆分Fasta文件: gawk '/^>c/ {OUT=substr($0,2) ".fa";print " ">OUT}; OUT{print >OUT}' your_input 它在终端上工作得非常好。我只想在使用系统的perl脚本中使用它,并使用字符串作为输入文件,但我不知道如何做 我试过这个: my $string = "secuence.fa"; #this is the file I wanna split . my $cmd= (
gawk '/^>c/ {OUT=substr($0,2) ".fa";print " ">OUT}; OUT{print >OUT}' your_input
它在终端上工作得非常好。我只想在使用系统的perl脚本中使用它,并使用字符串作为输入文件,但我不知道如何做
我试过这个:
my $string = "secuence.fa"; #this is the file I wanna split .
my $cmd= (gawk '/^>c/ {OUT=substr($0,2) ".fa";print " ">OUT}; OUT{print >OUT}' $string);
system $command;
当我运行脚本时,它说我在$cmd中有一些语法错误,但我找不到它
谢谢。在perl中拆分FASTA非常简单。Perl支持在读取文件时更改记录分隔符。如果将其更改为\n>,那么perl将为您完成所有工作 下面是一个例子:
use strict;
# Set the input record separator to the FASTA record separator
local $/ = "\n>";
while (<DATA>) {
print "---- New sequence ---\n";
# perl will put the separator at the end of the record,
# so we need to remove the separator from the end,
# and add it back at the beginning
s/[\n>]+$//;
s/^(?!>)/>/;
print $_, "\n";
}
__DATA__
>seq1
ACGTACCTA
>seq2
TTCACTTAC
>seq3
ACCTTATTA
您需要从perl脚本运行awk脚本有什么好的理由吗?我的意思是,直接用Perl做同样的简单操作不是更好吗?很可能是因为我的老师想:systemgawk,'/^>c/{OUT=substr$0,2.fa;print>OUT};OUT{print>OUT},$stringThis使脚本运行,但我没有获得任何输出。它应该提供1个或多个fasta文件。它应该提供输出。。它在Ubuntu 14.04,Perl版本5.18上对我有效。