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

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