rolandomantilla has asked for the wisdom of the Perl Monks concerning the following question:
I have a FASTA array and I need to make it into a hash in order to look for an specific ID and get that specific sequence, any ideas this is what I have until now and i know im not good with Perl by trying hard
#!/usr/local/bin/perl #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 $sequence= ''; my $query= ''; my %hash= ''; #Read the contents of the file hwk3.seq @file_data=get_file_data("hwk2.seq"); #Extract the sequence data from the content; %hash= map {$_ => 1 } @file_data; if (exists $hash{$query}){ print "This is sequence: $sequence"; }else { print "Not and ID"}; exit; sub get_file_data{ my($filename) = @_; use strict; use warnings; unless ( open (GET_FILE_DATA, $filename) ) { print STDERR "Cannot open file \"$filename\"\n\n"; exit; } @filedata= <GET_FILE_DATA>; close GET_FILE_DATA; return @filedata; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: New to Perl
by Utilitarian (Vicar) on Aug 04, 2011 at 04:38 UTC | |
by chromatic (Archbishop) on Aug 04, 2011 at 05:32 UTC | |
by rolandomantilla (Novice) on Aug 04, 2011 at 20:21 UTC | |
by chromatic (Archbishop) on Aug 04, 2011 at 22:19 UTC | |
by rolandomantilla (Novice) on Aug 06, 2011 at 04:00 UTC | |
| |
|
Re: New to Perl
by Marshall (Canon) on Aug 05, 2011 at 15:08 UTC | |
by rolandomantilla (Novice) on Aug 06, 2011 at 03:42 UTC |