Skip to content

Commit

Permalink
complement-db
Browse files Browse the repository at this point in the history
  • Loading branch information
kkarra committed Oct 11, 2021
1 parent 10d1f35 commit 1966fb9
Show file tree
Hide file tree
Showing 10 changed files with 318 additions and 140 deletions.
4 changes: 3 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ include ':bio-source-cglabrata-homologs',
':bio-source-panther',
':bio-source-homologene',
':bio-source-ensembl-compara', ':bio-source-go-slim',
':bio-source-sgd-complexes'
':bio-source-sgd-complexes', ':bio-source-sgd-complementation-db'



Expand Down Expand Up @@ -64,3 +64,5 @@ include ':bio-source-sgd-db-utr'
project(':bio-source-sgd-db-utr').projectDir = new File(settingsDir, './sgd-db-utr')
include ':bio-source-diopt-orthologs'
project(':bio-source-diopt-orthologs').projectDir = new File(settingsDir, './diopt-orthologs')
include ':bio-source-sgd-complementation-db'
project(':bio-source-sgd-complementation-db').projectDir = new File(settingsDir, './sgd-complementation-db')
22 changes: 22 additions & 0 deletions sgd-complementation-db/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
sourceSets {
main {
java {
srcDirs = ['src/main/java', 'build/gen']
}
resources {
srcDirs = ['src/main/resources']
}
}
test {
java {
srcDirs = ['src/test/java']
}
resources {
srcDirs = ['src/test/resources']
}
}
}

processResources {
from('.') { include ("*.properties")}
}
8 changes: 8 additions & 0 deletions sgd-complementation-db/sgd-complementation-db.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

compile.dependencies = intermine/objectstore/main, \
bio/core/main, \
intermine/integrate/main, \
bio/sources/sgd-complementation-db/main
have.db.tgt = true
converter.class = org.intermine.bio.dataconversion.SgdComplementationDbConverter

Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
package org.intermine.bio.dataconversion;
/*
* Copyright (C) 2002-2016 FlyMine
*
* This code may be freely distributed and modified under the
* terms of the GNU Lesser General Public Licence. This should
* be distributed with the code. See the LICENSE file for more
* information or http://www.gnu.org/copyleft/lesser.html.
*
*/

import java.util.HashMap;
import java.util.Map;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;


import org.intermine.objectstore.ObjectStoreException;
import org.intermine.dataconversion.ItemWriter;
import org.intermine.metadata.Model;
import org.intermine.sql.Database;
import org.intermine.xml.full.Item;
import org.apache.commons.lang.StringUtils;


/**
*
* @author
*/
public class SgdComplementationDbConverter extends BioDBConverter {
//
private static final String DATASET_TITLE = "Yeast Complementation";
private static final String DATA_SOURCE_NAME = "SGD-BioGRID curated complementation";
private final Map<String, Item> genes = new HashMap<String, Item>();
private final Map<String, Item> publications = new HashMap<String, Item>();
private static final String TAXON_ID = "4932";
private static final String H_TAXON_ID = "9606";
private Item yorganism;
private Item horganism;
private String licence;
private static final SgdComplementationDbProcessor PROCESSOR = new SgdComplementationDbProcessor();


/**
* Construct a new SgdComplementationDbConverter.
* @param database the database to read from
* @param model the Model used by the object store we will write to with the ItemWriter
* @param writer an ItemWriter used to handle Items created
*/
public SgdComplementationDbConverter(Database database, Model model, ItemWriter writer) throws ObjectStoreException{
super(database, model, writer, DATA_SOURCE_NAME, DATASET_TITLE);
yorganism = createItem("Organism");
yorganism.setAttribute("taxonId", TAXON_ID);
store(yorganism);
horganism = createItem("Organism");
horganism.setAttribute("taxonId", H_TAXON_ID);
store(horganism);
}


/**
* {@inheritDoc}
*/
public void process() throws Exception {
Connection connection = getDatabase().getConnection();
processComplements(connection);
storeGenes();
}


/**
* {@inheritDoc}
*/
public void processComplements(Connection connection) throws SQLException, ObjectStoreException {

ResultSet res = PROCESSOR.getComplements(connection);

while (res.next()) {

String yeastGene = res.getString("yeast_gene");
String pmid = res.getString("pmid");
String direction = res.getString("direction");
String dbxref_id = res.getString("dbxref_id");
String notes = res.getString("curator_comment");
String source= res.getString("format_name");

System.out.println("Processing line..." + yeastGene + " "+ dbxref_id);

Item ygene = getGeneItem(yeastGene, "secondaryIdentifier", yorganism);
Item hgene = getGeneItem(dbxref_id, "secondaryIdentifier", horganism);

getComplement(notes, direction, source, pmid, ygene, hgene);
getComplement(notes, direction, source, pmid, hgene, ygene);

}
}
/**
*
* @param c
* @param n
* @param source
* @param pmid
* @return
* @throws ObjectStoreException
*/
private void getComplement(String n, String d, String s, String pmid,
Item yg, Item hg) throws ObjectStoreException {

Item pub = publications.get(pmid);
if (pub == null) {
pub = createItem("Publication");
pub.setAttribute("pubMedId", pmid);
publications.put(pmid, pub);
store(pub);
}

Item comp = createItem("Complement");

if(StringUtils.isNotEmpty(n)) comp.setAttribute("notes", n);
comp.setAttribute("source", s);
comp.setAttribute("direction", d);
comp.setReference("publication", pub);
comp.setReference("gene", yg);
comp.setReference("complement", hg);
store(comp);

}

/**
*
* @param geneId
* @return
* @throws ObjectStoreException
*/
private Item getGeneItem(String geneId, String identifier, Item org)
throws ObjectStoreException {

Item gene = genes.get(geneId);

if (gene == null) {
gene = createItem("Gene");
genes.put(geneId, gene);
gene.setAttribute(identifier, geneId);
gene.setReference("organism", org);
}

return gene;

}

/**
*
* @throws ObjectStoreException
*/

private void storeGenes() throws ObjectStoreException {
for (Item gene : genes.values()) {
try {
store(gene);
} catch (ObjectStoreException e) {
throw new ObjectStoreException(e);
}
}
}
/**
* {@inheritDoc}
*/
@Override
public String getDataSetTitle(String taxonId) {
return DATASET_TITLE;
}
/**
* Set the data licence for these data.
*
* @param licence should be URI to data licence.
*/
public void setLicence(String licence) {
this.licence = licence;
}
/**
* Get the data licence for these data.
*
* @return URI to data licence.
*/
public String getLicence() {
return licence;
}

}


Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.intermine.bio.dataconversion;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.log4j.Logger;


public class SgdComplementationDbProcessor {

private static final Logger LOG = Logger.getLogger(SgdComplementationDbProcessor.class);

/**
* Return the results of getting complements
* @param connection the connection
* @return the results
* @throws SQLException if there is a database problem
*/
protected ResultSet getComplements(Connection connection)
throws SQLException {

String query = "select db.format_name as yeast_gene, rdb.pmid, "
+ "direction, dbxref_id, curator_comment, s.format_name "
+ "from nex.dbentity db "
+ "inner join nex.functionalcomplementannotation fca on fca.dbentity_id = db.dbentity_id "
+ "inner join nex.referencedbentity rdb on rdb.dbentity_id = fca.reference_id "
+ "inner join nex.source s on s.source_id = fca.source_id ";
LOG.info("executing: " + query);
Statement stmt = connection.createStatement();
ResultSet res = stmt.executeQuery(query);
return res;
}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<!-- This file details any extensions needed to the data model to store data from this source, everything else is automatically generated from the model description so this is all we need to do to add to the model. -->

<classes>
<!-- add any <class> elements here -->

</classes>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DataSet.key_name = name
DataSource.key_name = name
SOTerm.key_name_ontology = name, ontology
Organism.key_taxonid = taxonId
Ontology.key_name = name
Publication.key_pubmedid = pubMedId
Gene.key_primaryidentifier=primaryIdentifier
Gene.key_secondaryidentifier=secondaryIdentifier, organism

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.intermine.bio.dataconversion;

/*
* Copyright (C) 2002-2018 FlyMine
*
* This code may be freely distributed and modified under the
* terms of the GNU Lesser General Public Licence. This should
* be distributed with the code. See the LICENSE file for more
* information or http://www.gnu.org/copyleft/lesser.html.
*
*/

public class SgdComplementationDbConverterTest extends ItemsTestCase
{
Model model = Model.getInstanceByName("genomic");
SgdComplementationDbConverter converter;
MockItemWriter itemWriter;

public SgdComplementationDbConverterTest(String arg) {
super(arg);
}

public void setUp() throws Exception {
super.setUp();
// if you need to do some preprocessing and set up, do that here
}

public void testProcess() throws Exception {
// read in a test file (place in test/resources so it's on the classpath)
// process using your converter
// compare results to expected results
// look at the other intermine unit tests for help!
}
}
Loading

0 comments on commit 1966fb9

Please sign in to comment.