Hi,

I have a following problem which try to score the substrings distance.
The score is basically the number of positions of substrings that occur (dotted count)

And these are the three instances:
Instance 1 (score 21)
....... ....... ...... GATTACGAGTGGCGCTCGTGTAACGGCA GATTACG GCGCTCG AACGGCA
Instance 2 (score 16)
......... ....... GATTACGAGTGGCGCTCGTGTAACGGCA GATTACG TTACGAG CGTGTAA
Instance 3 (score 17)
GCTCGTG .................. GATTACGAGTGGCGCTCGTGTAACGGCA TACGAGT GTGGCGC
UPDATE: Instance 4 (score 4)
.. .. GATTACGAGTGGCGCTCGTGTAACGGCA GG GG
I wonder if there is a way to solve this.
Currently, what I have is:
#!/usr/bin/perl -w use strict; use Data::Dumper; my $s1 = 'GATTACGAGTGGCGCTCGTGTAACGGCA'; # Here are the array of the substrings, note that the number of # substrings may differ from array to array # and length of the substring may vary (defined as a parameter) my @ar = ('GATTACG','GCGCTCG','AACGGCA'); #21 (0,11,21) my @ar2 = ('GATTACG','TTACGAG','CGTGTAA'); #16 my @ar3 = ('TACGAGT','GTGGCGC','GCTCGTG'); #17 my @ar4 = ('GG','GG'); #4 score($s1,\@ar2); sub score{ my ($str,$array) = @_; my @pos; my $sub_len = length @$array[1]; foreach (@$array){ my $idx = index $s1, $_; push @pos, $idx; print "$idx\n"; } # I'm not sure where to go from here for (0..$#pos){ my $sum = $pos[$_]+$sub_len; } }
UPDATE 2: Renamed title.
Regards,
Edward

In reply to Measuring Substrings Problem by monkfan

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.