0

Given a certain sequence A stored in an array, I have to find if a larger sequence B contains sequence A.

I am stuck at the index part... and i'm getting an error that argument "TGACCA" isn't numeric in array element in line 69 which is:

if (index($record_r1[1], $r2_seq[$check]) != -1)


The code is:

foreach my $check (@r2_seq)
{
  if (index($record_r1[1], $r2_seq[$check]) != -1)
  {
     $matches= $matches + 1;
     print "Matched";
  }
  else
  {
  }
}

2 Answers 2

3
foreach my $check (@r2_seq)

$check takes on the value of each element in @r2_seq. It is not the index.

$r2_seq[$check]

This is attempting to use an element of @r2_seq as the index into @r2_seq. It is unlikely what you want. More probably, you want to use

$check

as in

if (index($record_r1[1], $check) != -1)

.

Sign up to request clarification or add additional context in comments.

Comments

0

I believe you wanted $check to be index, so then use the following code:

foreach my $index (0..$#r2_seq)
{
  if (index($record_r1[1], $r2_seq[$index]) != -1)
  {
     $matches= $matches + 1;
     print "Matched";
  }
  else
  {
  }
}

1 Comment

It doesn't go to the match even though the substring is there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.