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

  • Home
  • SEARCH
  • 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 8963709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:25:03+00:00 2026-06-15T16:25:03+00:00

I’m trying to perform a GOs annotation using the SIMAP database which is Blast2GO

  • 0

I’m trying to perform a GOs annotation using the SIMAP database which is
Blast2GO annotated. Everything is fine, but I have problems when I try
to find the accession number in the file where entry numbers are
associated with their GOs. The problem is that the script does not find
the number in the input file when really there is. I tried several things
without good results (re.match, insert in a list and then extract the element, etc)
File where the GOs are associated with entry numbers has this structure (accession number, GO term, blats2go score):

1f0ba1d119f52ff28e907d2b5ea450db GO:0007154 79

1f0ba1d119f52ff28e907d2b5ea450db GO:0005605 99

The python code:

import re
from Bio.Blast import NCBIXML
from Bio import SeqIO

input_file = open('/home/fpiston/Desktop/test_go/test2.fasta', 'rU')
result_handle = open('/home/fpiston/Desktop/test_go/test2.xml', 'rU')
save_file = open('/home/fpiston/Desktop/test_go/test2.out', 'w')

fh = open('/home/fpiston/Desktop/test_go/Os_Bd_Ta_blat2go_fake', 'rU')
q_dict =  SeqIO.to_dict(SeqIO.parse(input_file, "fasta"))
blast_records = NCBIXML.parse(result_handle)

hits = []

for blast_record in blast_records:
    if blast_record.alignments:
        list = (blast_record.query).split()
        if re.match('ENA|\w*|\w*', list[0]) != None:
            list2 = list[0].split("|")
            save_file.write('%s\t' % list2[1])
        else:
            save_file.write('%s\t' % list[0])
        for alignment in blast_record.alignments:
            for hsp in alignment.hsps:
                h = alignment.hit_def    
                for l in fh:             
                    ls = l.split()       #at this point all right
                    if h in ls:          #here, 'h' in not found in 'fh'
                        print h
                        print 'ok'
                        save_file.write('%s\t' % ls[1])
                save_file.write('\n')
        hits.append(blast_record.query.split()[0])
misses =set(q_dict.keys()) - set(hits)

for i in misses:
    list = i.split("|")
    if len(list) > 1:
        save_file.write('%s\t' % list[1])
    else:
        save_file.write('%s\t' % list)
    save_file.write('%s\n' % 'no_match')

save_file.close() 

This is the code with the correction of martineau (fh.seek(0)):

#!/usr/bin/env python
import sys
import re
from Bio.Blast import NCBIXML
from Bio import SeqIO

input_file = sys.argv[1] #queries sequences in fasta format
out_blast_file = sys.argv[2] #name of the blast results file
output_file = sys.argv[3] #name of the output file

result_handle = open(out_blast_file, 'rU')
fh = open('/home/fpiston/Desktop/test_go/Os_Bd_Ta_blat2go', 'rU')
q_dict =  SeqIO.to_dict(SeqIO.parse(open(input_file), "fasta"))
blast_records = NCBIXML.parse(result_handle)
save_file = open(output_file, 'w')
hits = []

for blast_record in blast_records:
    if blast_record.alignments:
        list = (blast_record.query).split()
        if re.match('ENA|\w*|\w*', list[0]) != None:
            list2 = list[0].split("|")
            save_file.write('\n%s\t' % list2[1])
        else:
            save_file.write('\n%s\t' % list[0])
        for alignment in blast_record.alignments:
            for hsp in alignment.hsps:
                hit = alignment.hit_def
                save_file.write('%s\t' % hit)
                fh.seek(0)
                for l in fh:
                    ls = l.split()
                    if ls[0] in  hit:
                        save_file.write('%s\t' % ls[1])          
        hits.append(blast_record.query.split()[0])

misses =set(q_dict.keys()) - set(hits)

for i in misses:
    list = i.split("|")
    if len(list) > 1:
        save_file.write('\n%s\t' % list[1])
    else:
        save_file.write('\n%s\t' % list)
    save_file.write('%s' % 'no_match')

save_file.close() 
  • 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-15T16:25:05+00:00Added an answer on June 15, 2026 at 4:25 pm

    I really have no idea what you’re talking about here, but noticed that within the outer for blast_record in blast_records: and for alignment in blast_record.alignments: loops you have a for l in fh: but never rewind the file with a fh.seek(0) anywhere, which means it only reads the lines in the file the first time it’s executed — which seems illogical.

    You could fix this by adding the fh.seek(0) just before the inner loop. Although unnecessary the very first time the inner loop executes, it’s need all the following times and doing it one extra time won’t hurt anything.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I have an autohotkey script which looks up a word in a bilingual dictionary
This could be a duplicate question, but I have no idea what search terms
I'm trying to select an H1 element which is the second-child in its group
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have thousands of HTML files to process using Groovy/Java and I need to

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.