in reply to Re: remove part of string (DNA)
in thread remove part of string (DNA)

oh and I forgot to mention: I wouldn't worry too much about memory and efficiency of the algorithm unless you plan to implement this on a web server or something where it will run all the time. It's more likely to be a one-off and, especially as a beginner, you can easily spend much more time optimising it than you will ever save. If it takes a bit longer, use the time to brew a nice cup of coffee or go home and find the shiny new results waiting on your disk for you in the morning... :-)

Replies are listed 'Best First'.
Re^3: remove part of string (DNA)
by Furor (Novice) on Apr 13, 2011 at 08:00 UTC
    Thanks to all for the replies! I'll check them out under close scrutiny. I'm sure it'll give me a boost.
    (to be continued ;) )
      Hi Furor, good luck with your research!
      As a fellow biologist working with Perl, I highly recommend having a few ready modules for reading and writing Fasta files. It makes everything so much easier
      You can find some great stuff in CPAN, but also if you need simple things it is good exercise to write it yourself.
      Here is a short module that reads Fasta files into a hash that might come in handy:
      package fasta_utils; use Exporter 'import'; @EXPORT_OK = qw(fasta2hash); use strict; use warnings; use lib '/cs/prt/mrguy/lib'; ##Reading the fasta formats of the file into hash sub fasta2hash { my ($file) = @_; print "file = $file\n"; my $seq_ref = {}; open IN, $file; my ($sequence,$id); while (my $line = <IN>){ if ($line =~/^\s*$/){ next; } if ($line =~ /^>(.*?)$/){ if ($id){ $seq_ref->{$id} = $sequence; } $id = $1; $sequence = ""; } else { chomp $line; $line =~ s/\s//g; $sequence .= $line; } } ##Putting in the last sequence if ($id){ $seq_ref->{$id} = $sequence; } return $seq_ref; } 1;
      Hopes this helps in the future
      Mr Guy