1 package uk.ac.ebi.intenz.biopax.level2;
2
3 import java.util.Collection;
4 import java.util.HashSet;
5 import java.util.Set;
6
7 import org.biopax.paxtools.model.Model;
8 import org.biopax.paxtools.model.level2.biochemicalReaction;
9 import org.biopax.paxtools.model.level2.catalysis;
10 import org.biopax.paxtools.model.level2.dataSource;
11 import org.biopax.paxtools.model.level2.physicalEntity;
12 import org.biopax.paxtools.model.level2.physicalEntityParticipant;
13 import org.biopax.paxtools.model.level2.protein;
14 import org.biopax.paxtools.model.level2.publicationXref;
15 import org.biopax.paxtools.model.level2.relationshipXref;
16 import org.biopax.paxtools.model.level2.unificationXref;
17 import org.biopax.paxtools.model.level2.xref;
18
19 import uk.ac.ebi.biobabel.util.StringUtil;
20 import uk.ac.ebi.biobabel.util.collections.OperatorSet;
21 import uk.ac.ebi.intenz.domain.enzyme.Cofactor;
22 import uk.ac.ebi.intenz.domain.enzyme.EnzymaticReactions;
23 import uk.ac.ebi.intenz.domain.enzyme.EnzymaticReactions.VisibleReaction;
24 import uk.ac.ebi.intenz.domain.enzyme.EnzymeComment;
25 import uk.ac.ebi.intenz.domain.enzyme.EnzymeEntry;
26 import uk.ac.ebi.intenz.domain.enzyme.EnzymeLink;
27 import uk.ac.ebi.intenz.domain.enzyme.EnzymeName;
28 import uk.ac.ebi.intenz.domain.constants.View;
29 import uk.ac.ebi.intenz.domain.constants.XrefDatabaseConstant;
30 import uk.ac.ebi.intenz.domain.reference.Journal;
31 import uk.ac.ebi.intenz.domain.reference.Patent;
32 import uk.ac.ebi.intenz.domain.reference.Reference;
33 import uk.ac.ebi.rhea.domain.Database;
34 import uk.ac.ebi.rhea.domain.Reaction;
35 import uk.ac.ebi.rhea.biopax.level2.BiopaxBiochemicalReaction;
36 import uk.ac.ebi.rhea.biopax.level2.BiopaxPhysicalEntity;
37 import uk.ac.ebi.xchars.SpecialCharacters;
38 import uk.ac.ebi.xchars.domain.EncodingType;
39
40
41
42
43
44
45
46
47 public class BiopaxCatalysis {
48
49 private EnzymeEntry enzymeEntry;
50
51 private Collection<catalysis> cat;
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 public BiopaxCatalysis(EnzymeEntry enzymeEntry, Model model){
84 this.enzymeEntry = enzymeEntry;
85 cat = new HashSet<catalysis>();
86
87
88 String ec = enzymeEntry.getEc().toString();
89 protein enzyme = model.addNew(protein.class, ec);
90
91 enzyme.setNAME(SpecialCharacters.getInstance(null)
92 .xml2Display(enzymeEntry.getSystematicName().getName(), EncodingType.CHEBI_CODE));
93
94 enzyme.setSHORT_NAME(SpecialCharacters.getInstance(null)
95 .xml2Display(enzymeEntry.getCommonName().getName(), EncodingType.CHEBI_CODE));
96
97 for (EnzymeName synonym : enzymeEntry.getSynonyms(View.INTENZ)){
98 enzyme.addSYNONYMS(SpecialCharacters.getInstance(null)
99 .xml2Display(synonym.getName(), EncodingType.CHEBI_CODE));
100 }
101 enzyme.addSYNONYMS(SpecialCharacters.getInstance(null)
102 .xml2Display(enzymeEntry.getSystematicName().getName(), EncodingType.CHEBI_CODE));
103 enzyme.addSYNONYMS(SpecialCharacters.getInstance(null)
104 .xml2Display(enzymeEntry.getCommonName().getName(), EncodingType.CHEBI_CODE));
105
106
107 Set<String> bpComments = new HashSet<String>();
108 for (EnzymeComment comment : enzymeEntry.getComments(View.INTENZ)){
109 bpComments.add(SpecialCharacters.getInstance(null)
110 .xml2Display(comment.getCommentText(), EncodingType.CHEBI_CODE));
111 }
112
113
114 Set<xref> catXrefs = new HashSet<xref>();
115 for (EnzymeLink link: enzymeEntry.getLinks()){
116 if (link.getXrefDatabaseConstant().equals(XrefDatabaseConstant.GO)){
117 catXrefs.add(getBpXref(link.getXrefDatabaseConstant().toString(),
118 link.getAccession(), model, null));
119 } else if (link.getXrefDatabaseConstant().equals(XrefDatabaseConstant.PROSITE)){
120 enzyme.addXREF(getBpXref(link.getXrefDatabaseConstant().toString(),
121 link.getAccession(), model, "Domains, families, functional sites"));
122 } else if (link.getXrefDatabaseConstant().equals(XrefDatabaseConstant.SWISSPROT)){
123 enzyme.addXREF(getBpXref(link.getXrefDatabaseConstant().toString(),
124 link.getAccession(), model, null));
125 } else if (link.getXrefDatabaseConstant().equals(XrefDatabaseConstant.CAS)){
126 enzyme.addXREF(getBpXref(link.getXrefDatabaseConstant().toString(),
127 link.getAccession(), model, null));
128 } else if (link.getXrefDatabaseConstant().equals(XrefDatabaseConstant.MEROPS)){
129 String meropsId = link.getSpecificUrl().substring(link.getSpecificUrl().indexOf("id=")+3);
130 enzyme.addXREF(getBpXref(link.getXrefDatabaseConstant().toString(),
131 meropsId, model, null));
132 }
133 }
134
135
136 Set<publicationXref> pubXrefs = new HashSet<publicationXref>();
137 for (Reference citation : enzymeEntry.getReferences()){
138 String pubXrefId = null;
139 String xrefDb = null;
140 String xrefAcc = null;
141 if (citation instanceof Journal){
142 xrefAcc = ((Journal) citation).getPubMedId();
143 if (!StringUtil.isNullOrEmpty(xrefAcc)) xrefDb = "PUBMED";
144 } else if (citation instanceof Patent){
145 xrefAcc = ((Patent) citation).getPatentNumber();
146 if (!StringUtil.isNullOrEmpty(xrefAcc)) xrefDb = "PATENT";
147 }
148 if (!StringUtil.isNullOrEmpty(xrefDb)){
149 pubXrefId = xrefDb + "_" + xrefAcc;
150 } else {
151 pubXrefId = "PUB_" + citation.getPubId();
152 }
153 pubXrefId = Biopax.fixId(null, pubXrefId, false);
154 publicationXref pubXref = null;
155 if (model.containsID(pubXrefId)){
156 pubXref = (publicationXref) model.getByID(pubXrefId);
157 } else {
158 pubXref = model.addNew(publicationXref.class, pubXrefId);
159 if (!StringUtil.isNullOrEmpty(xrefDb)){
160 pubXref.setDB(xrefDb);
161 pubXref.setID(xrefAcc);
162 }
163 if (!StringUtil.isNullOrEmpty(citation.getAuthors())){
164 pubXref.addAUTHORS(SpecialCharacters.getInstance(null)
165 .xml2Display(citation.getAuthors(), EncodingType.CHEBI_CODE));
166 }
167 pubXref.addSOURCE(citation.getSource().toString());
168 if (!StringUtil.isNullOrEmpty(citation.getTitle())){
169 pubXref.setTITLE(SpecialCharacters.getInstance(null)
170 .xml2Display(citation.getTitle(), EncodingType.CHEBI_CODE));
171 }
172 pubXref.setYEAR(Integer.valueOf(citation.getYear()));
173 }
174 pubXrefs.add(pubXref);
175 }
176
177
178 dataSource bpDataSource =
179 Biopax.getBpDataSource(Database.valueOf(enzymeEntry.getSource().toString()), model);
180
181
182 EnzymaticReactions intenzReactions =
183 enzymeEntry.getEnzymaticReactions().forView(View.INTENZ);
184 for (VisibleReaction vr : intenzReactions){
185 String catalysisId = getBiopaxId(enzymeEntry, vr.getReaction());
186 catalysis c = model.addNew(catalysis.class, catalysisId);
187
188 physicalEntityParticipant controller = model.addNew(
189 physicalEntityParticipant.class, Biopax.fixId(
190 null, catalysisId +"/controller", false));
191 controller.setPHYSICAL_ENTITY(enzyme);
192 c.addCONTROLLER(controller);
193
194 for (Object o : enzymeEntry.getCofactors()){
195 if (o instanceof Cofactor){
196 c.addCOFACTOR(getBiopaxCofactor((Cofactor) o, catalysisId, model));
197 } else {
198 for (Object o2 : (OperatorSet) o){
199 c.addCOFACTOR(getBiopaxCofactor((Cofactor) o2, catalysisId, model));
200 }
201 }
202 }
203
204 c.addDATA_SOURCE(bpDataSource);
205
206 biochemicalReaction controlled = (biochemicalReaction)
207 new BiopaxBiochemicalReaction(vr.getReaction(), model, null
208 Biopax.RHEA_PREFIX).getBiopaxConversion();
209 controlled.addEC_NUMBER(ec);
210 c.addCONTROLLED(controlled);
211
212 switch(vr.getReaction().getDirection()){
213 case LR:
214 c.setDIRECTION(org.biopax.paxtools.model.level2.Direction.PHYSIOL_LEFT_TO_RIGHT);
215 break;
216 case RL:
217 c.setDIRECTION(org.biopax.paxtools.model.level2.Direction.PHYSIOL_RIGHT_TO_LEFT);
218 break;
219 case BI:
220 c.setDIRECTION(org.biopax.paxtools.model.level2.Direction.REVERSIBLE);
221 break;
222 case UN:
223
224 break;
225 }
226
227 c.setCOMMENT(bpComments);
228
229 c.addCOMMENT("INTENZ:IUBMB=" + vr.isIubmb());
230
231 for (xref catXref: catXrefs){
232 c.addXREF(catXref);
233 }
234
235 for (publicationXref pubXref: pubXrefs){
236 c.addXREF(pubXref);
237 }
238 cat.add(c);
239 }
240 }
241
242
243
244
245
246 public BiopaxCatalysis(catalysis cat){
247 throw new RuntimeException("Not yet implemented");
248
249 }
250
251
252
253
254 public EnzymeEntry getIntEnzEnzyme(){
255 return enzymeEntry;
256 }
257
258
259
260
261 public Collection<catalysis> getBiopaxCatalysis(){
262 return cat;
263 }
264
265 private static String getBiopaxId(EnzymeEntry enzymeEntry, Reaction reaction){
266 return enzymeEntry.getEc()
267 + "/" + BiopaxBiochemicalReaction.getBiopaxId(reaction);
268 }
269
270 private physicalEntityParticipant getBiopaxCofactor(Cofactor cofactor,
271 String catId, Model model){
272 String cofactorId =
273 Biopax.fixId(null, catId + "/cofactor/" + SpecialCharacters.getInstance(null)
274 .xml2Display(cofactor.getCompound().toString(), EncodingType.CHEBI_CODE), true);
275 physicalEntityParticipant bpCofactor = null;
276 bpCofactor = model.addNew(physicalEntityParticipant.class, cofactorId);
277 physicalEntity bpCofactorCompound = null;
278 String cofactorCompoundId = BiopaxPhysicalEntity.getBiopaxId(cofactor.getCompound());
279 if (model.containsID(cofactorCompoundId)){
280 bpCofactorCompound = (physicalEntity) model.getByID(cofactorCompoundId);
281 } else {
282 bpCofactorCompound = new BiopaxPhysicalEntity(cofactor.getCompound(), model)
283 .getBiopaxPhysicalEntity();
284 }
285 bpCofactor.setPHYSICAL_ENTITY(bpCofactorCompound);
286 return bpCofactor;
287 }
288
289 private xref getBpXref(String db, String id, Model model, String relationship){
290 xref x = null;
291 String rdfId = Biopax.fixId(null, db + "_" + id, false);
292 if (model.containsID(rdfId)){
293 x = (xref) model.getByID(rdfId);
294 } else {
295 x = relationship == null?
296 model.addNew(unificationXref.class, rdfId):
297 model.addNew(relationshipXref.class, rdfId);
298 x.setDB(db);
299 x.setID(id);
300 if (relationship != null){
301 ((relationshipXref) x).setRELATIONSHIP_TYPE(relationship);
302 }
303 }
304 return x;
305 }
306 }