1 import sys, os
2 extraPath = os.path.dirname(os.path.abspath(__file__))+"/../.."
3
4 extraPath = os.path.dirname(os.path.abspath(__file__))+"/../../JariSandbox/ComplexPPI/Source"
5
6 sys.path.append(extraPath)
7 from Utils.ProgressCounter import ProgressCounter
8 try:
9 import xml.etree.cElementTree as ET
10 except ImportError:
11 import cElementTree as ET
12 import Utils.ElementTreeUtils as ETUtils
13
15 print attrs
16 print >> sys.stderr, "Loading corpus file", input
17 corpusRoot = ETUtils.ETFromObj(input).getroot()
18
19 documents = corpusRoot.findall("document")
20 counter = ProgressCounter(len(documents), "Documents")
21 countsByType = {}
22 interactors = {}
23 for document in documents:
24 entDict = {}
25 for entity in document.getiterator("entity"):
26 entDict[entity.get("id")] = entity
27 for interaction in document.getiterator("interaction"):
28 e1 = entDict[interaction.get("e1")]
29 e2 = entDict[interaction.get("e2")]
30
31 e1Tuple = []
32 for attr in attrs: e1Tuple.append(e1.get(attr))
33 e1Tuple = tuple(e1Tuple)
34 e2Tuple = []
35 for attr in attrs: e2Tuple.append(e2.get(attr))
36 e2Tuple = tuple(e2Tuple)
37 interactors = [e1Tuple, e2Tuple]
38
39 print interactors
40
41
42
43
44
45
46
47
48 if __name__=="__main__":
49 import sys
50 print >> sys.stderr, "##### Split elements with merged types #####"
51
52 from optparse import OptionParser
53
54 try:
55 import psyco
56 psyco.full()
57 print >> sys.stderr, "Found Psyco, using"
58 except ImportError:
59 print >> sys.stderr, "Psyco not installed"
60
61 optparser = OptionParser(usage="%prog [options]\nPath generator.")
62 optparser.add_option("-i", "--input", default=None, dest="input", help="Corpus in interaction xml format", metavar="FILE")
63 optparser.add_option("-a", "--attr", default=None, dest="attr", help="Output file in interaction xml format.")
64 (options, args) = optparser.parse_args()
65
66 if options.input == None:
67 print >> sys.stderr, "Error, input file not defined."
68 optparser.print_help()
69 sys.exit(1)
70
71 processCorpus(options.input, eval(options.attr))
72