Search in sources :

Example 1 with ItemFactory

use of org.intermine.xml.full.ItemFactory in project intermine by intermine.

the class DataSourceUpdater method execute.

/**
 * For each data set in the objectstore, retreive it's details from UniProt data file
 * @throws BuildException if an error occurs
 */
@Override
public void execute() {
    // Needed so that STAX can find it's implementation classes
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    if (osAlias == null) {
        throw new BuildException("osAlias attribute is not set");
    }
    if (outputFile == null) {
        throw new BuildException("outputFile attribute is not set");
    }
    if (dataSourceFile == null) {
        throw new BuildException("dataSourceFile attribute is not set");
    }
    LOG.info("Starting DataSourceUpdater");
    Writer writer = null;
    try {
        writer = new FileWriter(outputFile);
        ObjectStore os = ObjectStoreFactory.getObjectStore(osAlias);
        // get the data sources already in the database
        dataSourceNames = getDataSources(os);
        // parse the uniprot data source file
        Map<String, DataSourceHolder> allDataSources = parseDataFile(new FileReader(dataSourceFile));
        ItemFactory itemFactory = new ItemFactory(os.getModel(), "-1_");
        writer.write(FullRenderer.getHeader() + "\n");
        // write the relevant data sources to file
        for (DataSourceHolder holder : allDataSources.values()) {
            Item datasource = itemFactory.makeItemForClass("DataSource");
            datasource.setAttribute("name", holder.name);
            if (holder.descr != null) {
                datasource.setAttribute("description", holder.descr);
            }
            if (holder.url != null) {
                datasource.setAttribute("url", holder.url);
            }
            if (holder.pubMedId != null) {
                Item publication = itemFactory.makeItemForClass("Publication");
                publication.setAttribute("pubMedId", holder.pubMedId);
                writer.write(FullRenderer.render(publication));
                datasource.addToCollection("publications", publication);
            }
            writer.write(FullRenderer.render(datasource));
        }
        writer.write(FullRenderer.getFooter() + "\n");
    } catch (Exception e) {
        throw new BuildException("exception while retrieving data sets", e);
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
        if (writer != null) {
            try {
                writer.close();
            } catch (Exception e) {
            // ignore
            }
        }
    }
}
Also used : Item(org.intermine.xml.full.Item) ObjectStore(org.intermine.objectstore.ObjectStore) ItemFactory(org.intermine.xml.full.ItemFactory) FileWriter(java.io.FileWriter) FileReader(java.io.FileReader) BuildException(org.apache.tools.ant.BuildException) FileWriter(java.io.FileWriter) Writer(java.io.Writer) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException)

Example 2 with ItemFactory

use of org.intermine.xml.full.ItemFactory in project intermine by intermine.

the class GoConverterTest method testCreateWithObjects.

public void testCreateWithObjects() throws Exception {
    ItemFactory tgtItemFactory = new ItemFactory(Model.getInstanceByName("genomic"));
    Item organism = tgtItemFactory.makeItem("3_1", "Organism", "");
    organism.setAttribute("taxonId", "7227");
    Set<String> expected = new HashSet<String>();
    expected.add("4_1");
    expected.add("4_2");
    converter.initialiseMapsForFile();
    assertEquals(expected, new HashSet<String>(converter.createWithObjects("FLYBASE:Grip84; FB:FBgn0026430, FLYBASE:l(1)dd4; FB:FBgn0001612", organism)));
}
Also used : Item(org.intermine.xml.full.Item) ItemFactory(org.intermine.xml.full.ItemFactory) HashSet(java.util.HashSet)

Example 3 with ItemFactory

use of org.intermine.xml.full.ItemFactory in project intermine by intermine.

the class CreateChromosomeLocationsProcessTest method setUp.

public void setUp() throws Exception {
    osw = ObjectStoreWriterFactory.getObjectStoreWriter("osw.bio-test");
    osw.getObjectStore().flushObjectById();
    model = Model.getInstanceByName("genomic");
    itemFactory = new ItemFactory(model);
}
Also used : ItemFactory(org.intermine.xml.full.ItemFactory)

Example 4 with ItemFactory

use of org.intermine.xml.full.ItemFactory in project intermine by intermine.

the class MakeSpanningLocationsProcessTest method setUp.

public void setUp() throws Exception {
    osw = ObjectStoreWriterFactory.getObjectStoreWriter("osw.bio-test");
    osw.getObjectStore().flushObjectById();
    model = Model.getInstanceByName("genomic");
    itemFactory = new ItemFactory(model);
}
Also used : ItemFactory(org.intermine.xml.full.ItemFactory)

Example 5 with ItemFactory

use of org.intermine.xml.full.ItemFactory in project intermine by intermine.

the class GFF3RecordHandlerTest method setUp.

public void setUp() throws Exception {
    tgtModel = Model.getInstanceByName("genomic");
    itemFactory = new ItemFactory(tgtModel);
}
Also used : ItemFactory(org.intermine.xml.full.ItemFactory)

Aggregations

ItemFactory (org.intermine.xml.full.ItemFactory)8 FileWriter (java.io.FileWriter)3 Writer (java.io.Writer)3 HashSet (java.util.HashSet)3 BuildException (org.apache.tools.ant.BuildException)3 ObjectStore (org.intermine.objectstore.ObjectStore)3 Item (org.intermine.xml.full.Item)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 InputSource (org.xml.sax.InputSource)2 Database (com.sleepycat.je.Database)1 DatabaseConfig (com.sleepycat.je.DatabaseConfig)1 DatabaseEntry (com.sleepycat.je.DatabaseEntry)1 Environment (com.sleepycat.je.Environment)1 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)1 Transaction (com.sleepycat.je.Transaction)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 EOFException (java.io.EOFException)1 File (java.io.File)1