rkenshin09 has asked for the wisdom of the Perl Monks concerning the following question:
So, I'm basically trying to write a script that cuts a DNA sequence at specific points. I'm able to find the correct sequence within the string, but I can't for the life of me figure out how to split the string at the right site. Here's my code so far:
Right now, it prints the locations of where to split the sequence, but I'm not exactly sure how to split the string at these specific location into fragments. For instance, if the string is 6000 characters, and the search string is found at 500, 1000, 2000, 4000, 5000, I want to store/print: (500, 500, 1000, 2000, 1000, 1000).use strict; use Getopt::Std; #Invokes Get options package our ($opt_c,$opt_e); getopts('ce:'); my @seq = <>; chomp(@seq); my $seq = join("", @seq); our %re = ( 'BamHI' => 'GGATCC 1', # G | GATCC 'EcoRI' => 'GAATTC 1', # G | AATTC 'EcoRII' => 'CCWGG 0', # | CCWGG ); my @enz = split(/\b(\s+)\b/,$re{$opt_e}); my $enzseq = $enz[0]; my $cut = $enz[2]; print "The restriction site is: $enzseq\n\n"; while($seq =~ /($enzseq)/ig) { my $site = pos($seq),"\n"; print "$site\n"; }
Any help would be greatly appreciated, Thanks.
~~~~~~~~~~
the current code prints:The input sequence length is 48502 The restriction site is: GAATTC 21231 26109 31752 39173 44977
So, basically, I want to cut at each of those sites, so the fragments should have a length of 21231, (26109-21231), etc, where you subtract each shorter one from the longer one, where the last one is (48502-44977)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: splitting a string
by GrandFather (Saint) on Sep 26, 2008 at 03:09 UTC | |
|
Re: splitting a string
by kyle (Abbot) on Sep 26, 2008 at 02:53 UTC | |
|
Re: splitting a string
by johngg (Canon) on Sep 26, 2008 at 11:05 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |