#!/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() { 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"; } } #### 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