in reply to Re^4: New to Perl
in thread New to Perl

no ok it can't be. Ok let me see if I can explain it a different way and tell you what the program needs to do. First ask me to enter the clone ID. After i enter the ID using something like $id=<STDIN>; search thru my FASTA file and give me as an answer the sequence from the ID I put in, do you get me? by the way I can't thank you enough for helping me

Replies are listed 'Best First'.
Re^6: New to Perl
by rolandomantilla (Novice) on Aug 06, 2011 at 05:40 UTC
    This is the code I have until now, it is telling me Odd number of elements in hahs assigment at line 17, any ideas
    #the file name $filename= hwk2.seq; use strict; use warnings; use lib '/class/bi617a/share/textbook'; use BeginPerlBioinfo; #Declare initialize the variables my @file_data=(); my %seqs= ''; my $query= ''; my $dna= ''; #Read the contents of the file hwk3.seq @file_data=get_file_data("hwk2.seq"); print "Please enter the clone ID:\n"; $query=<STDIN>; chomp $query; my $seqs= &get_fasta(@file_data); if (exists $seqs{$query}) { print " This is the sequence: $seqs{$query +}, \n"; } else{ print "Not an ID\n\n;";} exit; sub get_fasta{ my $header; my $first = 0; for my $file_data(@file_data){ if ($file_data =~ /^>/) { $query = $file_data; $query=~ s/^>//; $query=~ s/\s,*//; if ($first == 0) { $first =1; } next; } if ($first == 0) {die("Not a standard FASTA file.\n"); } $seqs{$query} = $file_data; return \%seqs; } } return \%seqs; } }

      I'm not sure where line 17 is but my %seqs= ''; is wrong because a hash is not a string. I think you meant to say my %seqs = (); Also, there's no reason to assign empty values to newly declared variables so you can simply say my %seqs; instead. Actually, I'd just pull all those forward declarations together in one line like so...

      my (@file_data, %seqs, $query, $dna);

      Of course, this is Perl, so you can declare variables when you use them, but I don't want to overwhelm you so I'll leave it here for now.

      When you get errors like that, look at the line the error message says and try to see what's wrong. When you show code, please mark which line is 17 (well, the line with the error) because many of us can spot errors without downloading and running the code.