reebee3 has asked for the wisdom of the Perl Monks concerning the following question:
I have a text file in fasta format, which looks like...
>SequenceID|1234_Gene1
ATGTGTGTGTGTGTGT (DNA Sequence)>SequenceID|9876_Gene2
CTGTCGCTCGGAAAG (DNA Sequence)I am trying to write a script that will pull this data from a txt file in the command line into a hash and then sort it by length. The hash would be set up as the SequenceID has the key and DNA sequence as the value.
This is what I have so far and it works, except I set up the hash inside the script and not from a txt file added in the command line, I am not sure how to do this. I do not want to use BioPerl.
Thank youmy %sequences = ( "SequenceID|1234_Gene1" => 'CTTTTAAGCTGATTAGGCTTTTATACCATTAGATTTA +GTAACTATTGTCTTTTAA', "SequenceID|9876_Gene2" => 'GTGCTGTCTTAAGTTGAACAGAGTGTGGGAGGAAATA +TAAGCAAAGTTATTCCGTAGAATT', "SequenceID|4567_Gene3" => 'CATCCTCCTTTACACCCCACAAACATTTGGCAACCCCT +GATAGGTTTCTTTCTTGTGGA', ); foreach my $key (keys %sequences) { my $len = length ($sequences{$key}); print "$key:$len\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Creating hash from data extracted from text file in fasta format
by Athanasius (Archbishop) on Oct 14, 2015 at 06:09 UTC | |
|
Re: Creating hash from data extracted from text file in fasta format
by kcott (Archbishop) on Oct 14, 2015 at 06:10 UTC | |
|
Re: Creating hash from data extracted from text file in fasta format (QUIBBLE)
by ww (Archbishop) on Oct 14, 2015 at 12:25 UTC |