Advertisement
TankorSmash

bio

Sep 13th, 2012
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.34 KB | None | 0 0
  1. from collections import OrderedDict
  2.  
  3. headers_string = '''LOCUS       pNEBR                   4287 bp ds-DNA     circular     16-JUL-2012
  4. DEFINITION  Cloning vector pNEBR-X1, complete sequence.
  5. ACCESSION   urn.local...1328823972725.496
  6. KEYWORDS    .
  7. SOURCE      Cloning vector pNEBR-X1
  8.  ORGANISM  Cloning vector pNEBR-X1 other sequences; artificial sequences;
  9.            vectors.
  10. REFERENCE   1  (bases 1 to 4287)
  11.  AUTHORS   Maina,C.V.
  12.  TITLE     Direct Submission
  13.  JOURNAL   Submitted (19-OCT-2007) Research Department, New England Biolabs,
  14.            240 County Road, Ipswich, MA 01938, USA
  15. COMMENT    
  16. COMMENT     ApEinfo:methylated:1'''
  17.  
  18. features_string = '''FEATURES             Location/Qualifiers
  19.     TATA_signal     3873..3879
  20.                     /gene="lacZalpha"
  21.                     /note="minimal TATA box for 5XRE"
  22.                     /label=lacZalpha TATA signal
  23.                     /ApEinfo_fwdcolor=pink
  24.                     /ApEinfo_revcolor=pink
  25.                     /ApEinfo_graphicformat=arrow_data {{0 1 2 0 0 -1} {} 0}
  26.                     width 5 offset 0
  27.     polyA_signal    4..855
  28.                     /note="SV40 polyA"
  29.                     /label=SV40 polyA polyA signal
  30.                     /ApEinfo_fwdcolor=pink
  31.                     /ApEinfo_revcolor=pink
  32.                     /ApEinfo_graphicformat=arrow_data {{0 1 2 0 0 -1} {} 0}
  33.                     width 5 offset 0
  34.     misc_feature    3910..4068
  35.                     /gene="lacZalpha"
  36.                     /note="multiple cloning site (ApaI-StuI)"
  37.                     /note="Geneious type: polylinker"
  38.                     /label=multiple cloning site (ApaI-StuI)
  39.                     /ApEinfo_fwdcolor=pink
  40.                     /ApEinfo_revcolor=pink
  41.                     /ApEinfo_graphicformat=arrow_data {{0 1 2 0 0 -1} {} 0}
  42.                     width 5 offset 0
  43.     promoter        3762..3854
  44.                     /gene="lacZalpha"
  45.                     /note="5X GAL4 response element (5XRE) (approx. transcript
  46.                     start 3908 clockwise)"
  47.                     /label=lacZalpha promoter
  48.                     /ApEinfo_fwdcolor=pink
  49.                     /ApEinfo_revcolor=pink
  50.                     /ApEinfo_graphicformat=arrow_data {{0 1 2 0 0 -1} {} 0}
  51.                     width 5 offset 0
  52.     terminator      3167..3625
  53.                     /note="SV40 transcription terminator; prevents
  54.                     read-through transcription of the expression cassette from
  55.                     sources upstream of 5XRE"
  56.                     /label=terminator
  57.                     /ApEinfo_fwdcolor=pink
  58.                     /ApEinfo_revcolor=pink
  59.                     /ApEinfo_graphicformat=arrow_data {{0 1 2 0 0 -1} {} 0}
  60.                     width 5 offset 0
  61.     gene            995..1855
  62.                     /gene="bla"
  63.                     /label=bla gene
  64.                     /ApEinfo_fwdcolor=pink
  65.                     /ApEinfo_revcolor=pink
  66.                     /ApEinfo_graphicformat=arrow_data {{0 1 2 0 0 -1} {} 0}
  67.                     width 5 offset 0
  68.     gene            3735..4259
  69.                     /gene="lacZalpha"
  70.                     /label=lacZalpha gene
  71.                     /ApEinfo_fwdcolor=pink
  72.                     /ApEinfo_revcolor=pink
  73.                     /ApEinfo_graphicformat=arrow_data {{0 1 2 0 0 -1} {} 0}
  74.                     width 5 offset 0
  75.     rep_origin      2517..3105
  76.                     /note="pUC19 origin of replication (clockwise) (RNAII -35
  77.                     to RNA/DNA switch point)"
  78.                     /label=rep origin
  79.                     /ApEinfo_fwdcolor=pink
  80.                     /ApEinfo_revcolor=pink
  81.                     /ApEinfo_graphicformat=arrow_data {{0 1 2 0 0 -1} {} 0}
  82.                     width 5 offset 0
  83.     rep_origin      complement(1897..2406)
  84.                     /note="M13 origin of replication (+ -)"
  85.                     /label=M13 origin of replication (+ -) rep origin
  86.                     /ApEinfo_fwdcolor=pink
  87.                     /ApEinfo_revcolor=pink
  88.                     /ApEinfo_graphicformat=arrow_data {{0 1 2 0 0 -1} {} 0}
  89.                     width 5 offset 0
  90. '''
  91.  
  92.      
  93.  
  94.  
  95. #----------------------------------------------------------------------
  96. def getHeaders(lines):
  97.     """"""
  98.    
  99.     headers_keywords = ['LOCUS',
  100.                 'DEFINITION',
  101.                 'ACCESSION',
  102.                 'KEYWORDS',
  103.                 'SOURCE',
  104.                 '  ORGANISM',
  105.                 'REFERENCE',
  106.                 '  AUTHORS',
  107.                 '  TITLE',
  108.                 '  JOURNAL',
  109.                 'COMMENT']          
  110.    
  111.     #a dict to hold all the headers
  112.     #headers = OrderedDict() # switch to this, if order is important.
  113.     headers = {}
  114.    
  115.     #last valid header keyword
  116.     last_keyword = None
  117.     #loop over all the lines, putting them in a dict with
  118.     # the appropriate keyword as the key
  119.     for line in lines:
  120.         #if this variable doesn't change to true by the end of the for loop,
  121.         # it means that no keywords were found, meaning that it probably was a second
  122.         # line of the previous keyword, like COMMENT or JOURNAL
  123.         matched = False
  124.        
  125.         for kw in headers_keywords:
  126.             if line.startswith(kw):
  127.                 headers[kw] = [line.lstrip(kw).lstrip()]
  128.                 last_keyword = kw
  129.                 matched = True
  130.         if not matched:
  131.             headers[last_keyword].append(line)
  132.            
  133.     return headers
  134.  
  135. #----------------------------------------------------------------------
  136. def getFeatures(lines):
  137.     """"""
  138.     features_keywords = ['FEATURES',
  139.                         '     TATA_signal',
  140.                         '     polyA_signal',
  141.                         '     misc_feature',
  142.                         '     promoter',
  143.                         '     terminator',
  144.                         '     gene',
  145.                         '     gene',
  146.                         '     rep_origin',
  147.                         '     rep_origin',
  148.                         ]
  149.  
  150. #list of all the lines in the header section (up to FEATURES)
  151. headers_lines = headers_string.splitlines()
  152. headers = getHeaders(headers_lines)
  153.  
  154. ## this isn't done. Lost steam from here on, sorry.
  155. features_lines = features_string.splitlines()
  156. features = getFeatures(features_lines)
  157.  
  158.  
  159. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement