Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6468923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:56:07+00:00 2026-05-25T05:56:07+00:00

Write a function that compares two DNA sequences based on the following scoring scheme:

  • 0

Write a function that compares two DNA sequences based on the following scoring scheme: +1 for a match, +3 for each consecutive match and -1 for each mismatch.

MY CODE:

def pairwiseScore(seqA, seqB): 
  '''1+1+3-1-1+1+3+1-1-1+1-1-1-1'''
  print 
  signed = ''
  score = 0
  for i in range(len(seqA)):
    if(seqA[i] == seqB[i]):         
        signed += '|'
        score += 1
        if signed=='||':
            score=0
            score += 3
        else:
            score += 1

    else:
        signed += ' '
        score -=1
  return seqA+"\n"+signed+"\n"+seqB+"\n"+'score:'+ str(score)

print pairwiseScore("ATTCGT", "ATCTAT")  
print pairwiseScore("GATAAATCTGGTCT", "CATTCATCATGCAA")
print pairwiseScore('ATCG', 'ATCG')
print pairwiseScore('CATTCATCATGCAA', 'GATAAATCTGGTCT')

OUPUT:

ATTCGT
||   |
ATCTAT
score:2

GATAAATCTGGTCT
 ||  |||  |   
CATTCATCATGCAA
score:4

ATCG
||||
ATCG
score:7  // this should be 10 because +3 for each consecutive match` 1 + 3 +3 +3 =10

CATTCATCATGCAA
 ||  |||  |   
GATAAATCTGGTCT
score:4

Could anyone give me the tips?

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T05:56:07+00:00Added an answer on May 25, 2026 at 5:56 am
    if signed=='||':
    

    This code only matches if signed is exactly equal to '||'.

    You want to look at the last two chars, so try:

    if signed[-2:] == '||':
    

    I think you also have a calculation error in the score calculation.

    Here’s a fixed and cleaned up version for your function:

    def pairwiseScore(seqA, seqB): 
        signed = ''
        score = 0
        for i in range(len(seqA)):
          if seqA[i] == seqB[i]:
              signed += '|'
              if signed[-2:] == '||':
                  score += 3
              else:
                  score += 1
          else:
              signed += ' '
              score -= 1
        return '%s\n%s\n%s\nscore:%d' % (seqA, signed, seqB, score)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a cmp -like function that compares two version numbers and
So, the idea was a write a recursive function that compares two strings to
I am looking to write a function in Jquery that compares two strings and
I want to write a function that accepts two objects as parameters and compare
In Programming in Scala the authors write that Scala's == function compares value equality
I'm trying to write a simple function == compareGPA that compares between the GPA
I'm trying to write a function in three classes that will compare two lists
I want to write a function that takes an array of letters as an
I want to write a function that returns the nearest next power of 2
I need to write a function that takes 4 bytes as input, performs a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.