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 8088417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:04:58+00:00 2026-06-05T19:04:58+00:00

I’m working on a matching algorithm for protein sequences. I’m starting with an aligned

  • 0

I’m working on a matching algorithm for protein sequences. I’m starting with an aligned protein sequence, and I am attempting to convert a mis-aligned sequence into the correctly aligned one. Here is an example:

original aligned sequence: —-AB–C-D—–

mis-aligned sequence: –A–BC—D-

The expected output should look like this:

original aligned sequence: —-AB–C-D—–

mis-aligned sequence: —-AB–C-D—– (both are now the same)

I’m told to be very specific about my problem, but the sequences I’m trying to match are >4000 characters long, and look ridiculous when pasted here. I’ll post two sequences representative of my problem, though, and that should do.

seq="---A-A--AA---A--"
newseq="AA---A--A-----A-----"
seq=list(seq) #changing maaster sequence from string to list
newseq=list(newseq) #changing new sequence from string to list
n=len(seq) #obtaining length of master sequence
newseq.extend('.') #adding a tag to end of new sequence to account for terminal gaps

print(seq, newseq,n) #verification of sequences in list form and length

for i in range(n)
    if seq[i]!=newseq[i]:
        if seq[i] != '-': #gap deletion
            del newseq[i]

        elif newseq[i] != '-':
            newseq.insert(i,'-') #gap insertion


        elif newseq[i] == '-':
            del newseq[i]


old=''.join(seq) #changing list to string
new=''.join(newseq) #changing list to string
new=new.strip('.') #removing tag

print(old) #verification of master-sequence fidelity
print(new) #verification of matching sequence

The output I get from this particular code and set of sequences is:

—A-A–AA—A–

—A-A–A—-A—–A—–

I can’t seem to get the loop to correctly delete unwanted dashes in between the letters more than once, because the rest of the loop iterations are used in an add dash/delete dash pair.
This is a good start to the problems here.

How can I write this loop successfully to obtain my desired output (two identical sequences)

  • 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-06-05T19:05:00+00:00Added an answer on June 5, 2026 at 7:05 pm

    I edited your code and it is giving correct output now:

    seq="----AB--C-D-----"
    newseq="--A--BC---D-"
    seq=list(seq) #changing maaster sequence from string to list
    newseq=list(newseq) #changing new sequence from string to list
    n=len(seq) #obtaining length of master sequence
    newseq.extend('.') #adding a tag to end of new sequence to account for terminal gaps
    
    print(seq, newseq,n) #verification of sequences in list form and length
    for i in range(len(seq)):
        if seq[i]!=newseq[i]:
           if seq[i]=='-':
               newseq.insert(i,'-')
    
           elif newseq[i]=='-':
               newseq.insert(i,seq[i])
           else:
               newseq.insert(i,seq[i])
    
    else:
        newseq=newseq[0:len(seq)]
    
    old=''.join(seq) #changing list to string
    new=''.join(newseq) #changing list to string
    new=new.strip('.') #removing tag
    
    print(old) #verification of master-sequence fidelity
    print(new) #verification of matching sequence
    

    output:

    ----AB--C-D-----
    ----AB--C-D-----
    

    and for AA---A--A-----A-----:

    ---A-A--AA---A--
    ---A-A--AA---A--
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm making a simple page using Google Maps API 3. My first. One marker
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.