Hi all,
I'm having sequences stored in two arrays @seq1
and @seq2
and I have to compare sequence @seq2
with all the indexes in the @seq1
and print the mismatched bases in each position.
These are my sequences:
@seq1 = "UAUGUACCGACCUUAUUCUCCU AUGUACCGACCUUAUUCUCCUG UGUACCGACCUUAUUCUCCUGU GUACCGACCUUAUUCUCCUGUG UACCGACCUUAUUCUCCUGUGA ACCGACCUUAUUCUCCUGUGAU CCGACCUUAUUCUCCUGUGAUC CGACCUUAUUCUCCUGUGAUCU GACCUUAUUCUCCUGUGAUCUA ACCUUAUUCUCCUGUGAUCUAC CCUUAUUCUCCUGUGAUCUACU CUUAUUCUCCUGUGAUCUACUA UUAUUCUCCUGUGAUCUACUAU UAUUCUCCUGUGAUCUACUAUA "
@seq2 = " UGGAGUGUGACAAUGGUGUUUG"
and this is my code:
foreach (0..length(@seq1))
{
my $char = substr($seq2,$_,1);
if($char ne substr($seq1, @_,1))
{
$result .="$char";
}
else
{
$result .="";
}
}
print $result, "\n";
I'm getting errors. I would be grateful if anyone help me to complete this and to rectify my error. Thank you
Why is there a
@_
inif($char ne substr($seq1, @_,1)).
And also, storing a single sequence string in an array (@seq1
) does not make sense. Your code has a couple of problemsIt's not clear, but it's actually a white space quoted list
Yeah, I figured as much, but it took me some time ;). This also means that @landesfeind's solutions won't work...
Sorry, I didn't got that, in particular because there is also a white space when initializing
@seq2
and because both@seq1
and@seq2
are later accessed using$
andsubstr()
. I assumed the white spaces to be mistakes or formatting errors.As I was bitching around, I would gladly adjust my code in the answer to match the desired output - if one can specify how it should look like. Probably more like the following?
which prints
thanks a lot @landesfeind