File: sbo2cpp.py

package info (click to toggle)
libsbml 5.19.7%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 115,608 kB
  • sloc: cpp: 460,814; xml: 340,122; ansic: 53,825; python: 12,463; makefile: 9,744; sh: 8,893; cs: 8,586; java: 8,151; perl: 6,133; ruby: 4,760; javascript: 1,605; php: 202; csh: 3
file content (32 lines) | stat: -rw-r--r-- 838 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python

import sys

def convertOboFile(oboFile, outputFile): 
  term   = -1
  parent = -1
  stream = open(oboFile)
  output = open(outputFile, "w")
  
  for line in stream.readlines():
    try:
      if line.startswith("id:"):
        term = int( line[8:15] )
      elif line.startswith("is_a:"):
        parent = int( line[10:17] )
        output.write( "  mParent.insert( pair<const int, int>(%3d, %3d) );\n" % (term, parent))
      elif line.startswith("is_obsolete:"):
        parent = 1000
        output.write( "  mParent.insert( pair<const int, int>(%3d, %4d) );\n" % (term, parent))
    except ValueError:
      pass
  
  stream.close()
  output.close()


if __name__ == '__main__':
  if len(sys.argv) != 3:
    convertOboFile('sbo-obo-flat.txt', 'output.txt')
  else: 
    convertOboFile(sys.argv[1], sys.argv[2])