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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:14:07+00:00 2026-06-07T07:14:07+00:00

I would like to calculate the number of pairwise differences between a long list

  • 0

I would like to calculate the number of pairwise differences between a long list of sequences, and put it back into a matrix form.

I have a few hundred genetic sequences, and each sequence is already aligned and has the same length (about 300 characters). I’m not looking for one of the edit distance algorithms (hamming’s, leveinstein’s, etc) but instead would like to get the number of absolute differences between two sequences. The sequences would have to be compared at each character position.

For example,

Sequence 1: "GAT-ACA"
Sequence 2: "AT-GCGA"
Number of differences: 6

(The dash is there to allow the sequences to be aligned, and my sequences may also include dashes).

Would there be any efficient way to do this using python (or other language), with a short computing time? I also asked this question in R, initially intending to do it that way, but it turned out too slow to be feasible to apply to several hundred sequences.

Thank you!

  • 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-07T07:14:08+00:00Added an answer on June 7, 2026 at 7:14 am

    If you want to calculate the matrix that displays the differences between the pairs you can do it like this:

    import numpy as np
    
    def get_difference(x,y):
        return sum(ele_x != ele_y for ele_x, ele_y in zip(x,y))
    
    my_list = ['abcde','abcwe','zbfwe']
    n = len(my_list)
    
    my_array = np.zeros((n,n))
    #
    for i, ele_1 in enumerate(my_list):
        for j, ele_2 in enumerate(my_list):
            if j >= i:
                break # Since the matrix is symmetrical we don't need to
                      # calculate everything
            difference = get_difference(ele_1, ele_2)  
            my_array[i, j] = difference
            my_array[j, i] = difference
    

    Result:

    >>> my_array
    array([[ 0.,  1.,  3.],
           [ 1.,  0.,  2.],
           [ 3.,  2.,  0.]])
    

    The resulting matrix (OK array) shows the differences between the pairs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to calculate the number of months and days between two NSDates.
I would like to calculate the similarity between users, which is reciprocal. similarity[:user1][:user2] ==
I have a matrix mat and would like to calculate the mean of the
I would like to be able to calculate the family relationship between two individuals
I would like to be able to calculate the amount of time a number
I would like to be able to calculate the total number of bytes a
I would like to calculate the number of periods that have elapsed since the
I would like to calculate, in PHP, the percentage of a number. For example:
I would like to calculate total order amount in the previous month. I got
I would like to calculate my total order amount in the previous week. I

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.