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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:13:49+00:00 2026-06-12T21:13:49+00:00

I’m trying to write a Python script which takes a special type of file

  • 0

I’m trying to write a Python script which takes a special type of file as input.
This file contains information about multiple genes, and the information about one gene is written over multiple lines, where the number of lines is not the same for every gene. An example would be:

 gene            join(373616..374161,1..174)
                 /locus_tag="AM1_A0001"
                 /db_xref="GeneID:5685236"
 CDS             join(373616..374161,1..174)
                 /locus_tag="AM1_A0001"
                 /codon_start=1
                 /transl_table=11
                 /product="glutathione S-transferase, putative"
                 /protein_id="YP_001520660.1"
                 /db_xref="GI:158339653"
                 /db_xref="GeneID:5685236"
                 /translation="MKIVSFKICPFVQRVTALLEAKGIDYDIEYIDLSHKPQWFLDLS
                 PNAQVPILITDDDDVLFESDAIVEFLDEVVGTPLSSDNAVKKAQDRAWSYLATKHYLV
                 QCSAQRSPDAKTLEERSKKLSKAFGKIKVQLGESRYINGDDLSMVDIAWLPLLHRAAI
                 IEQYSGYDFLEEFPKVKQWQQHLLSTGIAEKSVPEDFEERFTAFYLAESTCLGQLAKS
                 KNGEACCGTAECTVDDLGCCA"
 gene            241..381
                 /locus_tag="AM1_A0002"
                 /db_xref="GeneID:5685411"
 CDS             241..381
                 /locus_tag="AM1_A0002"
                 /codon_start=1
                 /transl_table=11
                 /product="hypothetical protein"
                 /protein_id="YP_001520661.1"
                 /db_xref="GI:158339654"
                 /db_xref="GeneID:5685411"
                 /translation="MLINPEDKQVEIYRPGQDVELLQSPSTISGADVLPEFSLNLEWI
                 WR"
 gene            388..525
                 /locus_tag="AM1_A0003"
                 /db_xref="GeneID:5685412"
 CDS             388..525
                 /locus_tag="AM1_A0003"
                 /codon_start=1
                 /transl_table=11
                 /product="hypothetical protein"
                 /protein_id="YP_001520662.1"
                 /db_xref="GI:158339655"
                 /db_xref="GeneID:5685412"
                 /translation="MKEAGFSENSRSREGQPKLAKDAAIAKPYLVAMTAELQIMATET
                 L"

What I want, now, is to create a list of dictionaries, where every dictionary contains the information about one gene, like this:

gene_1 = {"locus": /locus_tag, "product": /product, ...}
gene_2 = {"locus": /locus_tag, "product": /product, ...}

I have absolutely no idea how I could make Python know when one gene/dictionary is finished and the next should start.
Can someone please help me? Is there a way to do this?

For clarification: I know how to extract the information I want, save it in variables and get it into the dictionary. I just don’t know how to tell Python to create one dictionary per gene.

  • 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-12T21:13:52+00:00Added an answer on June 12, 2026 at 9:13 pm

    In case someone is interested in the beginner’s solution I found with the help of the comments I received, here it is:

    import sys, re
    
    annot = file("example.embl", "r")
    embl = ""
    annotation = []
    
    for line in annot:
        embl += line
    
    embl_list = embl.split("FT   gen")
    
    for item in embl_list:
        if "e            " in item:
            split_item = item.split("\n")
            for l in split_item:
                if "e            " in l:
                    if not "complement" in l:
                        coordinates = l[13:len(l)]
                        C = coordinates.split("..")
                        genestart = C[0]
                        geneend = C[1]
                        strand = "+"
                    if "complement" in l:
                        coordinates = l[24:len(l)-1]
                        C = coordinates.split("..")
                        genestart = C[0]
                        geneend = C[1]
                        strand = "-"
    
                if "/locus_tag" in l:
                    L = l.split('"')
                    locus = L[1]
    
                if "/product" in l:
                    P = l.split('"')
                    product = P[1]
    
            annotation.append({
                "locus": locus,
                "genestart": genestart,
                "geneend": geneend,
                "product": product,
            })
        else:
            print "Finished!"
    
    • 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 am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I'm trying to select an H1 element which is the second-child in its group
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) 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.