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; }
In reply to Problems with Variable Scope in Perl by InfoSeeker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |