View Javadoc

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   * Adapter class to convert IntEnz <code>EnzymeEntry</code>s into BioPAX
42   * <code>catalysys</code> objects and viceversa.<br/>
43   * Note that one IntEnz <code>EnzymeEntry</code> may catalyze more than one
44   * reaction. As BioPAX <code>catalysis</code> allows one CONTROLLED property
45   * at most, several <code>catalysis</code> may be generated per IntEnz entry.
46   */
47  public class BiopaxCatalysis {
48  
49      private EnzymeEntry enzymeEntry;
50  
51      private Collection<catalysis> cat;
52  
53      /**
54       * Constructor from an IntEnz EnzymeEntry.
55       * <br/>
56       * The following BioPAX properties are currently ignored:
57       * <ul>
58       *  <li>CONTROL-TYPE: ACTIVATION by default</li>
59       *  <li>PARTICIPANTS: defined in the enclosed reaction (CONTROLLED)</li>
60       *  <li>AVAILABILITY</li>
61       *  <li>EVIDENCE</li>
62       *  <li>INTERACTION-TYPE</li>
63       * </ul>
64       * Notes about enzyme <b>names</b>:
65       * <ul>
66       *  <li>the systematic name is mapped to BioPAX' NAME.</li>
67       *  <li>the common/accepted/recommended name is mapped to BioPAX' SHORT-NAME.</li>
68       *  <li>BioPAX' SYNONYMS include both of them, following the specification.</li>
69       * </ul>
70       * Notes about <b>xrefs</b>:
71       * <ul>
72       *  <li>GO xrefs are assigned to BioPAX catalysis.</li>
73       *  <li>PROSITE xrefs are assigned to BioPAX' CONTROLLER property, as
74              relationshipXref.</li>
75       *  <li>Any other xrefs are assigned to BioPAX' CONTROLLER property, as
76              unificationXrefs</li>
77       * </ul>
78       * IntEnz <b>citations</b> are exported as publicationXref assigned to the
79       * BioPAX' catalysis.
80       * @param enzymeEntry an IntEnz enzyme.
81       * @param model A BioPAX model to add the catalysis to.
82       */
83      public BiopaxCatalysis(EnzymeEntry enzymeEntry, Model model){
84          this.enzymeEntry = enzymeEntry;
85          cat = new HashSet<catalysis>();
86  
87          // bp:CONTROLLER
88          String ec = enzymeEntry.getEc().toString();
89          protein enzyme = model.addNew(protein.class, ec);
90          // bp:NAME - this will be the systematic name
91          enzyme.setNAME(SpecialCharacters.getInstance(null)
92              .xml2Display(enzymeEntry.getSystematicName().getName(), EncodingType.CHEBI_CODE));
93          // bp:SHORT-NAME - common/accepted/recommended name
94          enzyme.setSHORT_NAME(SpecialCharacters.getInstance(null)
95              .xml2Display(enzymeEntry.getCommonName().getName(), EncodingType.CHEBI_CODE));
96          // bp:SYNONYMS (BioPAX docs say NAME and SHORT-NAME should be included here)
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         // bp:COMMENT
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         // bp:XREF
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         // bp:XREF (publicationXref)
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         // bp:DATA-SOURCE
178         dataSource bpDataSource =
179             Biopax.getBpDataSource(Database.valueOf(enzymeEntry.getSource().toString()), model);
180 
181         // FIXME: some NPE (transferred/deleted entries) can be avoided here:
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             // bp:CONTROLLER
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             // bp:COFACTOR
194             for (Object o : enzymeEntry.getCofactors()){
195                 if (o instanceof Cofactor){
196                     c.addCOFACTOR(getBiopaxCofactor((Cofactor) o, catalysisId, model));
197                 } else { // OperatorSet; XXX: here we loose operator information.
198                     for (Object o2 : (OperatorSet) o){
199                         c.addCOFACTOR(getBiopaxCofactor((Cofactor) o2, catalysisId, model));
200                     }
201                 }
202             }
203             // bp:DATA-SOURCE
204             c.addDATA_SOURCE(bpDataSource);
205             // bp:CONTROLLED
206             biochemicalReaction controlled = (biochemicalReaction)
207                 new BiopaxBiochemicalReaction(vr.getReaction(), model, null/*FIXME*/,
208 					Biopax.RHEA_PREFIX).getBiopaxConversion();
209             controlled.addEC_NUMBER(ec); // XXX: this is already done in the constructor, actually
210             c.addCONTROLLED(controlled);
211             // bp:DIRECTION
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 				// No direction at all.
224 				break;
225             }
226             // bp:COMMENT
227             c.setCOMMENT(bpComments);
228             // IUBMB flag as a comment to the catalysis, not the reaction:
229             c.addCOMMENT("INTENZ:IUBMB=" + vr.isIubmb());
230             // bp:XREF
231             for (xref catXref: catXrefs){
232                 c.addXREF(catXref);
233             }
234             // bp:XREF (bibliography citations)
235             for (publicationXref pubXref: pubXrefs){
236                 c.addXREF(pubXref);
237             }
238             cat.add(c);
239         }
240     }
241 
242     /**
243      * Not yet implemented. Throws an exception.
244      * @param cat
245      */
246     public BiopaxCatalysis(catalysis cat){
247         throw new RuntimeException("Not yet implemented");
248         //this.cat = Collections.singleton(cat);
249     }
250 
251     /**
252      * @return the IntEnz side of this apapter.
253      */
254     public EnzymeEntry getIntEnzEnzyme(){
255         return enzymeEntry;
256     }
257 
258     /**
259      * @return the BioPAX side of this adapter.
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 }