File: sbo2cpp.py

package info (click to toggle)
libsbml 5.20.5%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 117,108 kB
  • sloc: cpp: 469,781; xml: 364,270; ansic: 54,078; python: 12,540; makefile: 9,759; sh: 9,245; 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-- 839 bytes parent folder | download | duplicates (3)
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 python3

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])