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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:13:07+00:00 2026-05-27T16:13:07+00:00

I am a beginner in Python (I am a biologist) and I have a

  • 0

I am a beginner in Python (I am a biologist) and I have a file with the results from a particular software and i would like to parse the result using python. From the following output I would like to get just the score and would like to split the sequence into individual amino acids.

no. score Sequence

1   0.273778    FFHH-YYFLHRRRKKCCNNN-CCCK---HQQ---HHKKHV-FGGGE-EDDEDEEEEEEEE-EE--
2   0.394647    IIVVIVVVVIVVVVVVVVVV-CCCVA-IVVI--LIIIIIIIIYYYA-AVVVVVVVAAAAV-AST-
3   0.456667        FIVVIVVVVIXXXXIGGGGT-CCCCAV -------------IVBBB-AAAAAA--------AAAA-  
4   0.407581    MMLMILLLLMVVAIILLIII-LLLIVLLAVVVVVAAAVAAVAIIII-ILIIIIIILVIMKKMLA-
5   0.331761    AANSRQSNAAQRRQCSNNNR-RALERGGMFFRRKQNNQKQKKHHHY-FYFYYSNNWWFFFFFFR-
6   0.452381    EEEEDEEEEEEEEEEEEEEE-EEEEESSTSTTTAEEEEEEEEEEEE-EEEEEEEEEEEEEEEEE-
7   0.460385    LLLLLLLLMMIIILLLIIII-IIILLVILMMEEFLLLLILIVLLLM-LLLLLLLLLLVILLLVL-
8   0.438680    ILILLVVVVILVVVLQLLMM-QKQLIVVLLVIIMLLLLMLLSIIIS-SMMMILFFLLILIIVVL-
9   0.393291    QQQDEEEQAAEEEDEKGSSD-QQEQDDQDEEAAAHQLESSATVVQR-QQQQQVVYTHSTVTTTE-

From the above table,I would like to get a table with the same number,score but the sequences separated individually (columnwise)
so it should look like

no.      score         amino acid(1st column)

1      0.273778         F

2      0.395657         I

3      0.456667         F

another table representing the second column of amino acids

no       score       amino acid (2nd column)

1       0.273778         F

2       0.395657         I

3       0.456667         I  

third table representing the third column of amino acids and fourth table for 4th column of amino acids and so on

Thanks in advance for the help

  • 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-27T16:13:07+00:00Added an answer on May 27, 2026 at 4:13 pm

    From your example I guess that:

    • you want to save each table to a different results file.
    • each sequence is 65 characters long
    • some sequences contains meaningless white-spaces which has to be removed (line 3 in your example)

    Here is my code sample, it reads data from input.dat and writes results to result-column-<number>.dat:

    import re
    import sys
    
    # I will write each table to different results-file.
    # dictionary to map columns (numbers) to opened file objects:
    resultfiles = {}
    
    
    def get_result_file(column):
        # helper to easily access results file.
        if column not in resultfiles:
            resultfiles[column] = open('result-column-%d.dat' % column, 'w')
        return resultfiles[column]
    
    
    # iterate over data:
    for line in open('input.dat'):
        try:
            # str.split(separator, maxsplit)
            # with `maxsplit`=2 it is more fail-proof:
            no, score, seq = line.split(None, 2)
    
            # from your example I guess that white-spaces in sequence are meaningless,
            # however in your example one sequence contains white-space, so I remove it:
            seq = re.sub('\s+', '', seq)
    
            # data validation will help to spot problems early:
            assert int(no), no          
            assert float(score), score
            assert len(seq) == 65, seq
    
        except Exception, e:
            # print the error and continue to process data:
            print >> sys.stderr, 'Error %s in line: %s.' % (e, line)
            continue  # jump to next iteration of for loop.
    
        # int(), float() will rise ValueError if no or score aren't numbers
        # assert <condition> will rise AssertionError if condition is False.
    
        # iterate over each character in amino sequance:
        for column, char in enumerate(seq, 1):
            f = get_result_file(column)
            f.write('%s    %s    %s\n' % (no, score, char))
    
    
    # close all opened result files:
    for f in resultfiles.values():
        f.close()
    

    Notable functions used in this example:

    • enumerate
    • str.split
    • re.sub
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following XML document that I have to parse using python's minidom:
I'm a beginner with both Python and RegEx, and I would like to know
I am a beginner with Python and trying few programs. I have something like
I'm a beginner using python 3.2 and i have a book whos code is
I'm a beginner in Python and have a file i've read in that has
Python beginner here. I am using the matplotlib library to make graphs from tab
As part of the last assignment in a beginner python programing class, I have
I am a beginner of python and have a question, very confusing for me.
I am a beginner programmer, using python on Mac. I created a function as
Python beginner >>> import oauth2 Traceback (most recent call last): File , line 1,

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.