Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
There's more than one way to do things
 
PerlMonks  

Re^2: string similarity by using a function sort_by_similarity()

by roopa (Initiate)
on Nov 09, 2009 at 11:15 UTC ( #805898=note: print w/ replies, xml ) Need Help??


in reply to Re: string similarity by using a function sort_by_similarity()
in thread string similarity by using a function sort_by_similarity()

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.


Comment on Re^2: string similarity by using a function sort_by_similarity()

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://805898]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2014-04-17 11:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (445 votes), past polls