[Bioperl-l] string comparision mismatches and matches
Mark A. Jensen
maj at fortinbras.us
Wed Feb 3 14:50:05 UTC 2010
try this:
$in = 'ACCTCCTCCTCGAGTATGTG';
$tgt = 'TATCTTGCGCCGGAGATAAT';
$mask = pack("A*",$in)^pack("A*",$tgt);
$matches = $mask =~ tr/"\x0"/"\x0"/;
----- Original Message -----
From: "Roopa Raghuveer" <rtbio.2009 at gmail.com>
To: <bioperl-l at lists.open-bio.org>
Cc: "Chris Fields" <cjfields at illinois.edu>; "Mark A. Jensen" <maj at fortinbras.us>
Sent: Wednesday, February 03, 2010 8:50 AM
Subject: [Bioperl-l] string comparision mismatches and matches
> Hello all,
>
> I have a problem. I would like to compare two strings of equal length using
> Perl and trying to count the number of matches. I have used an algorithm to
> count the matches,but I found them to be time consuming in counting the
> mismatches. Could any one suggest a better algorithm for this?
>
> Ex:- Let the two sequences be
>
> input:- ACCTCCTCCTCGAGTATGTG
>
> target:- TATCTTGCGCCGGAGATAAT
>
> The no of matches are 5.
>
> In my program, I have used two indices which run along the string in the
> forward direction and reverse direction and extracting two characters at a
> time and comparing them with the respective characters in the output
> sequence. i.e.,
>
> i/p:- ACCTCCTCCTCGAGTATGTG
>
> I have extracted 'A' in the forward direction and 'G' in the reverse
> direction from the i/p.
>
> target:- TATCTTGCGCCGGAGATAAT
>
> I have extracted 'T' in the forward direction and 'T' in the reverse
> direction from the target and compared 'A' with 'T' and 'G' with 'T'. In
> this way, I have proceeded along the complete length of the string and
> counting the matches . But it seems to be time consuming though its working.
> Can anybody suggest a better way?
>
> Regards,
> Roopa.
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l
>
>
More information about the Bioperl-l
mailing list