-1
我試圖通過啓動子程序將幾個腳本合併到1個腳本中。問題在於我無法將輸入從1個下標指向另一個下標。這需要爲多個腳本完成。這些是他們整個列表中的前兩個腳本。使用子程序perl將腳本組合成1個腳本
代碼1生成的數據需要提交給代碼2等。但是在代碼2中,還有一個將生成的文件與原始文件進行比較的額外步驟。
Code 1:
subst_head_1($infile);
sub subst_head_1
{
##this code helps organise the file in a way that it makes it more convenient for the file to be pushed into a hash for later analysis
##opening file
my $i = $_[0];
open(IN, "<$i") || die "\n Error: Cannot open the infile: $infile\n";
# open(OUT, ">op.fa");
##giving all the headers in the original file line numbers
my $lineno = 1;
while(<IN>)
{
chomp;
if ($_ =~ />/)
{
$_ = $lineno++,"\t", $_ ,"\n";
subst_head_2($_);
}
}
}
##file organised in the following format; eg., "2>CBB_deg7180000000601_1100_2101_3"
sub subst_head_2
{
##opening files with header information(result of head-subs-1) and the original sequence(submitted query file) file for further info
my $i = $_[0];
#print $i;
my $i_1 = $_[1];
##pushing file(headerinfo.txt) with the header information into a hash
open(IN, "<$i");
my @file = <IN>;
my $file2 = join('', @file);
my %hash = split(/[\t\n]/, $file2);
##opening the original file with the sequence information into an array
open(IN1, "<$i_1");
my @fila = <IN1>;
##foreach of the sequnces in the sequence file
foreach my $fila(@fila)
{
##Substituting any "*" in the file, if any, especially at the end of some of sequnces which were present in the file
$fila =~ s/\*//g;
##regex for matching with the header information in the file with all the query information
if($fila =~ /^\>(\S+).*/)
{
##putting info(eg., CBB_deg7180000000601_1100_2101_3) into a variable $user
my $user = $1;
foreach my $has(sort keys %hash)
{
##regex for the values in the key-value relationship in the headerinfo file
if($hash{$has} =~ /^\>(\S+).*/)
{
##putting info(eg., CBB_deg7180000000601_1100_2101_3) into a variable $user1
my $user1 = $1;
##is the info the same?; if it is, then substitute it in the original with key from headerinfo.txt
if($user eq $user1)
{
##substitute header in the original file with the unique number;
$fila =~ s/^\>(\S+).*\n/>$has\n/;
}
}
}
}
}
print @fila;
}
全局變量呢?或者將結果從一個子傳遞給另一個? – Robert
嗨,這是問題..我無法弄清楚如何將結果從一個子節點傳遞到另一個子節點。 –
你有沒有試過'''subst_head_2(subst_head_1(file))''' – tomc