in reply to Re: Listing of files using glob
in thread Listing of files using glob
Here is the complete code. It basically takes a file...splits it and save the portions of file in separate files by creating a directory. Afterwards I want to list the individual file using glob. The output is still the same. I dont know where am wrong? The folders are being created, files are being created, the complete file name is not being listed only the extension is printed which is ".fasta".
#!/usr/bin/perl use Cwd; use strict; use warnings; my $path_to_fastaSeqs = $ARGV[0]; my $path_to_fragmentScript = $ARGV[1]; my %seqInfo = (); &storeInHash; &createFolderAndFiles; &callFragmentScript; sub storeInHash { open(FILE, "$path_to_fastaSeqs") or die("cannot open file"); { while(<FILE>) { my $line = $_; if ($line =~ />.*/) { #print "$&\n"; } else { #print "$line\n"; } $seqInfo{$&} = $line; } close(FILE); } } sub createFolderAndFiles { my $dir = getcwd; while(my ($key, $value) = each(%seqInfo)) { my $nameWithoutFastaSign = $key; $nameWithoutFastaSign =~ tr/>//d; mkdir $nameWithoutFastaSign, 0777; open(FILEOUT, ">$dir/$nameWithoutFastaSign/$nameWithoutFastaSign.fasta +"); { print FILEOUT "$key\n$value\n"; } } } sub callFragmentScript { while(my $key = each %seqInfo) { my $nameWithoutFastaSign = $key; $nameWithoutFastaSign =~ tr/>//d; my $currentDir = getcwd; chdir "$currentDir/$nameWithoutFastaSign"; my $changedDir = getcwd; print "changed directory is: $changedDir\n"; while(my $fastaFile = glob("*.fasta")) { print "$fastaFile\n"; } chdir "$currentDir"; } }
output is
changed directory is: /home/ammarah/Documents/code/1elwA .fasta changed directory is: /home/ammarah/Documents/code/1ghwA .fasta changed directory is: /home/ammarah/Documents/code/1flwA .fasta
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Listing of files using glob
by Anonymous Monk on Jan 05, 2012 at 08:55 UTC | |
by tobyink (Canon) on Jan 05, 2012 at 09:27 UTC | |
by Corion (Patriarch) on Jan 05, 2012 at 09:41 UTC | |
by choroba (Cardinal) on Jan 05, 2012 at 10:04 UTC | |
by AG87 (Acolyte) on Jan 05, 2012 at 10:25 UTC | |
by choroba (Cardinal) on Jan 05, 2012 at 10:45 UTC | |
by AG87 (Acolyte) on Jan 05, 2012 at 11:02 UTC | |
by choroba (Cardinal) on Jan 05, 2012 at 11:09 UTC | |
by AG87 (Acolyte) on Jan 05, 2012 at 11:14 UTC | |
by choroba (Cardinal) on Jan 05, 2012 at 11:26 UTC | |
by AG87 (Acolyte) on Jan 05, 2012 at 11:46 UTC | |
by choroba (Cardinal) on Jan 05, 2012 at 11:50 UTC | |
by AG87 (Acolyte) on Jan 05, 2012 at 11:56 UTC | |
by MidLifeXis (Monsignor) on Jan 05, 2012 at 13:26 UTC | |
| |
by choroba (Cardinal) on Jan 05, 2012 at 13:22 UTC | |
by choroba (Cardinal) on Jan 05, 2012 at 11:48 UTC | |
by AG87 (Acolyte) on Jan 05, 2012 at 11:52 UTC |
In Section
Seekers of Perl Wisdom