Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hello gmargo, I would like to explain my problem in detail as follows. I would like to compare a biological DNA sequence say, Input sequence: GATCAAGAGCCACAATATAGATGGTCCCACCGCACCGCTGGGCGTGCCCCCGGGGATTGTAAACGGGTTCCTTGCAACCCGCTGTCCAGCCCAGCTGATGTTATGGAATCTTCTGGCTCCCCGTATCCCCTCCAGGGACATCCTGCAGTGCAGCCTGGGACCCAGGTTTACAGTTCACTCCCAGCTTCTGCTGTGAGAACCCAGGAACCGGCACCCTGGGGATGG Query sequence with which I am comparing say, CTGAGGGGTGGCTCTCTGAAGAGGTGGGTTGCCCGTGAGCTGTTTTTACTGTCCTTGTTTGCCACTTATAAGGACTGGTTCCCCCCACCCCCAAGAGCAGCACAGATTCATAGCACCTGCTGCCTCCACCGAGCATCCCCCCTGCTCTGGAAAATCCTCCCTGCATCTGCAGCCTCGTACGTGCCTGAAGTCATTTGGTACCTGGGCGAGACCTTGCGGGGGGCC based on certain windowsize and threshold.If windowsize is 5,the sequence gets partitioned into strings of length 5 as follows. Input sequence strings(@inputsubs):-GATCA ATCAA TCAAG CAAGA AAGCG.... Query sequence strings(@querysubs):-CTGAG TGAGG GAGGG AGGGG GGGGT.... Now each string in the @inputsubs is being compared with each and every string in the @querysubs.If there are atleast 3(or more than 3) same bases i.e., three similar characters,then they can be grouped into an array i.e., here 3 is the threshold. So,I want all those strings which can show the similarity >=threshold.When I have used brute force method to compare the strings,by using count method.It was taking more time.So I tried to use the function sort_by_similarity By using this function,I could get the array of strings which are sorted in an ascending order ie., starting from strings that have strings of lowest similarity and ending with the strings that have highest similarity with the querystrings.But I would like to have only those strings which have a similarity >=threshold i.e., If input is abcdef,query is abcefg windowsize is 3,threshold is 2,I would like to have Output:- abc bcd def My code is as follows. use String::Similarity::Group ':all'; #use Smart::Comments '###'; print "Enter the input sequence\n"; chomp($input=<STDIN>); print "Enter the query sequence\n"; chomp($query=<STDIN>); print "Windowsize\n"; $ws=<STDIN>; print "Threshold\n"; $ts=<STDIN>; $ilength=length $input; $qlength=length $query; #print $qlength; for($i=0;$i<=$ilength-$ws;$i++){ #print "in"; push(@inputsubs,substr($input,$i,$ws)); } $r=@inputsubs; for($j=0;$j<=$qlength-$ws;$j++){ push(@querysubs,substr($query,$j,$ws)); } $s=@querysubs; for($t=0;$t<$s;$t++){ @b=sort_by_similarity(\@inputsubs,$querysubs$t); } $v=@b; for($i=0;$i<$v;$i++){ print "$b$i\n"; my($closestname,$match)=similarest(\@b,$querysubs$i); if($match>=0.66){ #print "$closestname\n"; } } Please suggest me in case of any improvements or other less time taking methods to get the desired output. Regards, Roopa.

In reply to Re^2: string similarity by using a function sort_by_similarity() by roopa
in thread string similarity by using a function sort_by_similarity() by roopa

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (3)
    As of 2018-05-23 04:19 GMT
    Find Nodes?
      Voting Booth?