View Javadoc

1   package uk.ac.ebi.intenz.biopax.level2;
2   
3   import java.io.IOException;
4   import java.io.OutputStream;
5   import java.lang.reflect.InvocationTargetException;
6   import java.util.Collection;
7   import org.apache.log4j.Logger;
8   import org.biopax.paxtools.model.Model;
9   import uk.ac.ebi.intenz.domain.enzyme.EnzymeEntry;
10  
11  /**
12   * Utility class to dump IntEnz entries as BioPAX model.
13   * @author rafalcan
14   */
15  public class Biopax extends uk.ac.ebi.rhea.biopax.level2.Biopax {
16  
17      private static final Logger LOGGER = Logger.getLogger(Biopax.class);
18  
19      public static final String INTENZ_PREFIX = "intenz";
20      public static final String INTENZ_NS = "http://www.ebi.ac.uk/intenz/#";
21  
22  	/**
23  	 * Creates an empty ontology model with the needed namespaces.
24  	 * @return an OWL model.
25       *
26  	 */
27      public static Model createModel(){
28  		Model biopaxModel = uk.ac.ebi.rhea.biopax.level2.Biopax.createModel();
29  		biopaxModel.setXmlBase(INTENZ_NS);
30  		biopaxModel.getNameSpacePrefixMap().put("", INTENZ_NS);
31  		biopaxModel.getNameSpacePrefixMap().put(INTENZ_PREFIX, INTENZ_NS);
32  		return biopaxModel;
33  	}
34  
35      /**
36       * Writes a collection of enzyme entries to an output stream.
37       * @param enzymes
38       * @param os
39       * @throws java.io.IOException
40       * @throws java.lang.IllegalAccessException
41       * @throws java.lang.reflect.InvocationTargetException
42       */
43      public static void write(Collection<EnzymeEntry> enzymes, OutputStream os)
44      throws IOException, IllegalAccessException, InvocationTargetException {
45          Model model = Biopax.createModel();
46      	for (EnzymeEntry entry : enzymes) {
47              try {
48                  new BiopaxCatalysis(entry, model);
49                  LOGGER.info("Added to BioPAX model - EC " + entry.getEc());
50              } catch(Exception e){
51                  LOGGER.error("Unable to convert to BioPAX - EC " + entry.getEc(), e);
52              }
53          }
54          write(model, os);
55      }
56  }