Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • umnklang
    Member
    • Oct 2011
    • 16

    #1

    Biopython - want to get a batch of amino acid fastas from list of entrez gene_ids

    I have a list of Entrez Gene IDs (~100) and I would like to obtain the amino acid fastas of each and create a multi-fasta file.

    I'm trying to do this using the Entrez.efetch function in biopython but I'm not sure how to retrieve the amino acid sequence from the gene file.

    Any ideas?
  • LeightonP
    Member
    • Feb 2011
    • 29

    #2
    An easy way to get the sequence is to ask entrez.efetch() to return a FASTA formatted sequence, as described in the Biopython tutorial at http://biopython.org/DIST/docs/tutor...al.html#htoc55 - note the rettype="fasta" argument. You can then treat this as any other FASTA stream (i.e. as if it were a file).

    Comment

    • umnklang
      Member
      • Oct 2011
      • 16

      #3
      That should work perfectly.

      Can biopython convert ids? For example from entrez GeneIDs to protein accession numbers?

      Comment

      • maubp
        Peter (Biopython etc)
        • Jul 2009
        • 1544

        #4
        The NCBI can convert the gene IDs to protein IDs, try Entrez link (elink). See also:

        Comment

        • umnklang
          Member
          • Oct 2011
          • 16

          #5
          Ok so using the tutorial, I developed the following code (using trial and error):

          from Bio import Entrez
          from Bio import SeqIO
          Entrez.email = "my_name@my_website.com"
          id_list = set(open('pids_test.csv', 'rU'))
          handle = Entrez.efetch(db="protein", rettype="fasta", retmode="text", \
          id=id_list)
          for seq_record in SeqIO.parse(handle, "fasta"):
          print ">" + seq_record.id, seq_record.description
          print seq_record.seq
          handle.close()

          this prints exactly what I want. I have two questions:

          1) how can I get the results into a text file, rather than printing them in my output?

          2) how can I let the user specify the input file (command line is fine)?

          K

          Comment

          • maubp
            Peter (Biopython etc)
            • Jul 2009
            • 1544

            #6
            To save the NCBI FASTA formatted data to a file, try something like this:

            Code:
            from Bio import Entrez
            from Bio import SeqIO
            Entrez.email = "my_name@my_website.com"
            id_list = set(open('pids_test.csv', 'rU'))
            handle = Entrez.efetch(db="protein", rettype="fasta", retmode="text", \
            id=id_list)	
            out_handle = open("saved.fasta", "w")
            for line in handle:
                out_handle.write(line)
            out_handle.close()
            handle.close()
            P.S. There a very similar example in the Biopython Tutorial in the section "EFetch: Downloading full records from Entrez"


            If you want to take the filename from the command line, learn about sys.argv, while to prompt the user try the input function or similar. Any good introduction to Python should cover this.
            Last edited by maubp; 01-08-2013, 09:34 AM. Reason: Added link

            Comment

            • umnklang
              Member
              • Oct 2011
              • 16

              #7
              Worked great, added sys.argv to allow user to specify file input and output:


              import sys
              from Bio import Entrez
              from Bio import SeqIO
              Entrez.email = "xxxxxXXXXXxxxxx"
              id_list = set(open(sys.argv[1], 'rU'))
              handle = Entrez.efetch(db="protein", rettype="fasta", retmode="text", \
              id=id_list)
              out_handle = open(sys.argv[2], 'w')

              for line in handle :
              out_handle.write(line)
              out_handle.close()

              handle.close()

              Comment

              Latest Articles

              Collapse

              • SEQadmin2
                Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
                by SEQadmin2



                Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

                Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
                ...
                10-14-2026, 09:55 AM
              • SEQadmin2
                New Genomics Technologies Take Aim at Long-Standing Limits
                by SEQadmin2


                Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

                We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
                ...
                09-28-2026, 10:25 AM

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by SEQadmin2, Yesterday, 11:13 AM
              0 responses
              16 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, Yesterday, 10:48 AM
              0 responses
              17 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 10-15-2026, 10:52 AM
              0 responses
              35 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 10-14-2026, 05:39 AM
              0 responses
              42 views
              0 reactions
              Last Post SEQadmin2  
              Working...