InfoSeeker has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I am quite new to perl...I have written code to read in protein entries and save each in a seperate Fasta (.fa) file..I manage to save the header correctly in each .fa but I am unable to save the string! What am I doing wrong? Is the $pdbString variable out of scope? Or is there an error with the I/O?
This is the input: >d1dlwa_ a.1.1.1 slfeqlggqaavqavtaqfyangidmpnqtnktaaflcaalggpnawtgrnlkevhanmgvsnaqfttvi +ghlrsaltgagvaaalveqtvavaetvrgdvvtvniqadatvatff >d1uvyc1 b.1.1.1 niqadatvatffngidmpnqtnktaaflcaalggpnawtgrnlkevhanmgvsnaqfttvighlrsaltg +agvaaalveqtvavaetvrgdvvtvslfeqlggqaavqavtaqfya
My expected output (each in a .fa file): >1dl_a_ slfeqlggqaavqavtaqfyangidmpnqtnktaaflcaalggpnawtgrnlkevhanmgvsnaqfttvi +ghlrsaltgagvaaalveqtvavaetvrgdvvtvniqadatvatff >1uvy_c1 niqadatvatffngidmpnqtnktaaflcaalggpnawtgrnlkevhanmgvsnaqfttvighlrsaltg +agvaaalveqtvavaetvrgdvvtvslfeqlggqaavqavtaqfya
THIS IS MY CODE (if there is anyway to make this more compact, I appreciate it!)
#!/usr/bin/perl -w @PDBchain; @PDBcode; @pdbString; @SCOPclass; $count =0; #SET A COUNTER FOR NUMBER OF ENTRIES open (IN, "$ARGV[0]"); my @array; while (<IN>) { my $pdbId = $_; chomp($pdbId); push @array, $pdbId; print $pdbId; print "\n\n"; if ($pdbId =~/>d(\d\w\w\w)(\w[_\d])\s(\w)/) { $pdbString[$count] = ""; $PDBcode[$count]=$1; #SAVE PDB CODE print $PDBcode[$count]; print "\n"; $PDBchain[$count]=$2; #SAVE PDB CHAIN $SCOPclass[$count]=$3; #SAVE SCOP CLASS (A,B,C,D,E,F,G +) $count++; next; } else { $pdbString[$count].=$pdbId; next; } print $pdbString[$count]; #this prints the complete fasta sequ +ence per entry! print "\n\n"; } close IN; print "Total number of entries: ".$count. "\n"; #COUNT TOTAL NUMBER OF + PDBS REPRESENTED for(my $i=0;$i<$count;$i++) { open (OUT, ">>$PDBcode[$i]_$PDBchain[$i].fa"); print OUT ">",$PDBcode[$i], "_", $PDBchain[$i], "\n"; print OUT $pdbString[$i]; #WHY AM I UNABLE TO PRINT THE SEQUENCE HERE? close OUT; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problems with Variable Scope in Perl
by graff (Chancellor) on Nov 02, 2008 at 18:45 UTC | |
by Anonymous Monk on Nov 03, 2008 at 01:12 UTC | |
by ruzam (Curate) on Nov 03, 2008 at 02:34 UTC | |
by ig (Vicar) on Nov 03, 2008 at 02:16 UTC | |
by graff (Chancellor) on Nov 03, 2008 at 03:20 UTC | |
by Anonymous Monk on Nov 05, 2008 at 15:53 UTC | |
|
Re: Problems with Variable Scope in Perl
by MadraghRua (Vicar) on Nov 03, 2008 at 19:00 UTC | |
by Anonymous Monk on Nov 05, 2008 at 15:56 UTC |