Hey,

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:

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"; }
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).

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)


In reply to splitting a string by rkenshin09

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.