#!/usr/bin/perl -w
#use Parallel::ForkManager;
use Data::Dumper;
my $parent='/source';
my $destdir='/destination';
#open parent directory
opendir(DIR, $parent) or die "Can't open the current directory: $!\n";
# read directory names in that directory into @names
my @dirs = grep {-d "$parent/$_" && ! /^\.{1,2}$/} readdir(DIR);
#my $pm=new Parallel::ForkManager();
foreach (@dirs)
{
#$pm -> start and next;
#do only if a folder contains .fastq.gz files
my @txt = <$parent/$_/*.fastq.gz>;
if(@txt)
{
system("zcat $parent/$_/*R1*.fastq.gz | gzip > $destdir/$_.R1.fastq.gz");
system("zcat $parent/$_/*R2*.fastq.gz | gzip > $destdir/$_.R2.fastq.gz");
print "Inside $_ folder \n";
}
#$pm -> finish;
}
みなさん、こんにちは。ソースの「$parent/」ディレクトリがあります。その中には 32 のサブディレクトリがあります。各ディレクトリには、いくつかのR1 .fastq.gz ファイルとR2 .fastq.gz ファイルが含まれています。R1 .fastq.gz ファイルを 1 つの R1.fastq.gz ファイルにマージする必要があり、 R2 .fastq.gz ファイルについても同様です。マージされた fastq.gz ファイルは、宛先ディレクトリ "$destdir/" に保存されます。また、マージされた fastq.gz ファイルの名前が、マージされて作成されたサブディレクトリの名前と一致するようにします (23 行目と 24 行目)。コードを実行すると、次のエラーが発生します。
sh: 1: cannot create /destination/Fastqc.R1.fastq.gz: Directory nonexistent
sh: 1: cannot create /destination/Fastqc.R2.fastq.gz: Directory nonexistent
たとえば、ここで Fastqc は、マージされたファイルを作成しているディレクトリの名前に由来します。試してみましたが、コードの何が問題なのかわかりません。誰か助けてくれませんか?
私が使うとき
system("zcat $parent/$_/*R1*.fastq.gz | gzip > $_.R1.fastq.gz"); instead of
system("zcat $parent/$_/*R1*.fastq.gz | gzip > $destdir/$_.R1.fastq.gz");
それは正常に動作します。