Skip to content
Snippets Groups Projects
Commit c59e82b5 authored by felmer's avatar felmer
Browse files

SE-229 improved db access

SVN: 15316
parent 1cac6467
No related branches found
No related tags found
No related merge requests found
...@@ -30,5 +30,6 @@ ...@@ -30,5 +30,6 @@
<classpathentry kind="lib" path="/libraries/jmock/hamcrest/hamcrest-library.jar"/> <classpathentry kind="lib" path="/libraries/jmock/hamcrest/hamcrest-library.jar"/>
<classpathentry kind="lib" path="/libraries/jmock/objenesis/objenesis-1.0.jar"/> <classpathentry kind="lib" path="/libraries/jmock/objenesis/objenesis-1.0.jar"/>
<classpathentry kind="lib" path="/libraries/jmock/jmock.jar"/> <classpathentry kind="lib" path="/libraries/jmock/jmock.jar"/>
<classpathentry kind="lib" path="/libraries/fastutil/fastutil.jar" sourcepath="/libraries/fastutil/fastutil-src.zip"/>
<classpathentry kind="output" path="targets/www/WEB-INF/classes"/> <classpathentry kind="output" path="targets/www/WEB-INF/classes"/>
</classpath> </classpath>
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
package ch.systemsx.cisd.openbis.plugin.phosphonetx.server.business; package ch.systemsx.cisd.openbis.plugin.phosphonetx.server.business;
import it.unimi.dsi.fastutil.longs.LongSet;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Collection; import java.util.Collection;
...@@ -27,6 +29,7 @@ import net.lemnik.eodsql.DataSet; ...@@ -27,6 +29,7 @@ import net.lemnik.eodsql.DataSet;
import org.apache.commons.lang.SerializationUtils; import org.apache.commons.lang.SerializationUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper; import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.support.lob.LobHandler; import org.springframework.jdbc.support.lob.LobHandler;
...@@ -39,9 +42,11 @@ import ch.systemsx.cisd.openbis.plugin.phosphonetx.server.dataaccess.IProteinQue ...@@ -39,9 +42,11 @@ import ch.systemsx.cisd.openbis.plugin.phosphonetx.server.dataaccess.IProteinQue
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.IdentifiedPeptide; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.IdentifiedPeptide;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.IdentifiedProtein; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.IdentifiedProtein;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProbabilityFDRMapping; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProbabilityFDRMapping;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinAbundance;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReference; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReference;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReferenceWithProbability; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReferenceWithProbability;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReferenceWithProbabilityAndPeptide; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReferenceWithProbabilityAndPeptide;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReferenceWithProtein;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.SampleAbundance; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.SampleAbundance;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.Sequence; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.Sequence;
...@@ -270,6 +275,18 @@ class DAOFactoryWithCache implements IPhosphoNetXDAOFactory ...@@ -270,6 +275,18 @@ class DAOFactoryWithCache implements IPhosphoNetXDAOFactory
{ {
return dao.tryToGetCachedProteinView(experimentPermID); return dao.tryToGetCachedProteinView(experimentPermID);
} }
public DataSet<ProteinReferenceWithProtein> listProteinReferencesByExperiment(
String experimentPermID)
{
return dao.listProteinReferencesByExperiment(experimentPermID);
}
public DataSet<ProteinAbundance> listProteinWithAbundanceByExperiment(
LongSet proteinIDs)
{
return dao.listProteinWithAbundanceByExperiment(proteinIDs);
}
} }
private IProteinQueryDAO proteinQueryDAO; private IProteinQueryDAO proteinQueryDAO;
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
package ch.systemsx.cisd.openbis.plugin.phosphonetx.server.business; package ch.systemsx.cisd.openbis.plugin.phosphonetx.server.business;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
...@@ -31,10 +33,13 @@ import ch.systemsx.cisd.openbis.generic.server.dataaccess.IExperimentDAO; ...@@ -31,10 +33,13 @@ import ch.systemsx.cisd.openbis.generic.server.dataaccess.IExperimentDAO;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.dto.Session; import ch.systemsx.cisd.openbis.generic.shared.dto.Session;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.server.dataaccess.IPhosphoNetXDAOFactory; import ch.systemsx.cisd.openbis.plugin.phosphonetx.server.dataaccess.IPhosphoNetXDAOFactory;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.server.dataaccess.IProteinQueryDAO;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.basic.dto.AbundanceColumnDefinition; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.basic.dto.AbundanceColumnDefinition;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.basic.dto.AggregateFunction; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.basic.dto.AggregateFunction;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.basic.dto.ProteinInfo; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.basic.dto.ProteinInfo;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinAbundance;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReferenceWithProbability; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReferenceWithProbability;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReferenceWithProtein;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinWithAbundances; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinWithAbundances;
/** /**
...@@ -121,24 +126,91 @@ class ProteinInfoTable extends AbstractBusinessObject implements IProteinInfoTab ...@@ -121,24 +126,91 @@ class ProteinInfoTable extends AbstractBusinessObject implements IProteinInfoTab
AbundanceManager abundanceManager = new AbundanceManager(sampleProvider); AbundanceManager abundanceManager = new AbundanceManager(sampleProvider);
IPhosphoNetXDAOFactory daoFactory = getSpecificDAOFactory(); IPhosphoNetXDAOFactory daoFactory = getSpecificDAOFactory();
ErrorModel errorModel = new ErrorModel(daoFactory); ErrorModel errorModel = new ErrorModel(daoFactory);
DataSet<ProteinReferenceWithProbability> resultSet = IProteinQueryDAO proteinQueryDAO = daoFactory.getProteinQueryDAO();
daoFactory.getProteinQueryDAO().listProteinsByExperiment(experimentPermID); DataSet<ProteinReferenceWithProtein> ds1 = proteinQueryDAO.listProteinReferencesByExperiment(experimentPermID);
List<ProteinReferenceWithProtein> prs = new ArrayList<ProteinReferenceWithProtein>();
LongOpenHashSet proteinIDs = new LongOpenHashSet();
try try
{ {
for (ProteinReferenceWithProbability protein : resultSet) for (ProteinReferenceWithProtein protein : ds1)
{ {
if (errorModel.passProtein(protein, falseDiscoveryRate)) prs.add(protein);
proteinIDs.add(protein.getProteinID());
}
} finally
{
ds1.close();
}
DataSet<ProteinAbundance> ds2 = proteinQueryDAO.listProteinWithAbundanceByExperiment(proteinIDs);
Map<Long, List<ProteinAbundance>> p2a = new HashMap<Long, List<ProteinAbundance>>();
try
{
for (ProteinAbundance proteinAbundance : ds2)
{
long proteinID = proteinAbundance.getId();
List<ProteinAbundance> list = p2a.get(proteinID);
if (list == null)
{ {
abundanceManager.handle(protein); list = new ArrayList<ProteinAbundance>();
p2a.put(proteinID, list);
} }
list.add(proteinAbundance);
} }
} finally } finally
{ {
resultSet.close(); ds2.close();
}
for (ProteinReferenceWithProtein proteinReferenceWithProtein : prs)
{
ProteinReferenceWithProbability protein = translate(proteinReferenceWithProtein);
if (errorModel.passProtein(protein, falseDiscoveryRate))
{
List<ProteinAbundance> list = p2a.get(proteinReferenceWithProtein.getProteinID());
if (list == null)
{
abundanceManager.handle(protein);
} else
{
for (ProteinAbundance proteinAbundance : list)
{
protein.setAbundance(proteinAbundance.getAbundance());
protein.setSamplePermID(proteinAbundance.getSamplePermID());
abundanceManager.handle(protein);
}
}
}
} }
// DataSet<ProteinReferenceWithProbability> resultSet =
// proteinQueryDAO.listProteinsByExperiment(experimentPermID);
// try
// {
// for (ProteinReferenceWithProbability protein : resultSet)
// {
// if (errorModel.passProtein(protein, falseDiscoveryRate))
// {
// abundanceManager.handle(protein);
// }
// }
// } finally
// {
// resultSet.close();
// }
return abundanceManager; return abundanceManager;
} }
private ProteinReferenceWithProbability translate(
ProteinReferenceWithProtein proteinReferenceWithProtein)
{
ProteinReferenceWithProbability proteinReferenceWithProbability = new ProteinReferenceWithProbability();
proteinReferenceWithProbability.setId(proteinReferenceWithProtein.getId());
proteinReferenceWithProbability.setAccessionNumber(proteinReferenceWithProtein.getAccessionNumber());
proteinReferenceWithProbability.setDescription(proteinReferenceWithProtein.getDescription());
proteinReferenceWithProbability.setCoverage(proteinReferenceWithProtein.getCoverage());
proteinReferenceWithProbability.setProbability(proteinReferenceWithProtein.getProbability());
proteinReferenceWithProbability.setDataSetID(proteinReferenceWithProtein.getDataSetID());
return proteinReferenceWithProbability;
}
private static double[] concatenate(double[] array1OrNull, double[] array2OrNull) private static double[] concatenate(double[] array1OrNull, double[] array2OrNull)
{ {
if (array1OrNull == null || array1OrNull.length == 0) if (array1OrNull == null || array1OrNull.length == 0)
......
...@@ -16,16 +16,21 @@ ...@@ -16,16 +16,21 @@
package ch.systemsx.cisd.openbis.plugin.phosphonetx.server.dataaccess; package ch.systemsx.cisd.openbis.plugin.phosphonetx.server.dataaccess;
import it.unimi.dsi.fastutil.longs.LongSet;
import net.lemnik.eodsql.BaseQuery; import net.lemnik.eodsql.BaseQuery;
import net.lemnik.eodsql.DataSet; import net.lemnik.eodsql.DataSet;
import net.lemnik.eodsql.Select; import net.lemnik.eodsql.Select;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.LongSetMapper;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.IdentifiedPeptide; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.IdentifiedPeptide;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.IdentifiedProtein; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.IdentifiedProtein;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProbabilityFDRMapping; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProbabilityFDRMapping;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinAbundance;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReference; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReference;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReferenceWithProbability; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReferenceWithProbability;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReferenceWithProbabilityAndPeptide; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReferenceWithProbabilityAndPeptide;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReferenceWithProtein;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.SampleAbundance; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.SampleAbundance;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.Sequence; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.Sequence;
...@@ -42,6 +47,22 @@ public interface IProteinQueryDAO extends BaseQuery ...@@ -42,6 +47,22 @@ public interface IProteinQueryDAO extends BaseQuery
@Select("select blob from protein_view_cache where experiment_perm_id = ?{1}") @Select("select blob from protein_view_cache where experiment_perm_id = ?{1}")
public byte[] tryToGetCachedProteinView(String experimentPermID); public byte[] tryToGetCachedProteinView(String experimentPermID);
@Select("select d.id as data_set_id, p.id as protein_id, probability, coverage, "
+ "pr.id, accession_number, description from protein_references as pr "
+ "left join sequences as s on s.prre_id = pr.id "
+ "left join identified_proteins as ip on ip.sequ_id = s.id "
+ "left join proteins as p on ip.prot_id = p.id "
+ "left join data_sets as d on p.dase_id = d.id "
+ "left join experiments as e on d.expe_id = e.id where e.perm_id = ?{1}")
public DataSet<ProteinReferenceWithProtein> listProteinReferencesByExperiment(
String experimentPermID);
@Select(sql = "select p.id, a.value, s.perm_id "
+ "from proteins as p join abundances as a on p.id = a.prot_id "
+ "left join samples as s on a.samp_id = s.id "
+ "where p.id = any (?{1})", parameterBindings = { LongSetMapper.class })
public DataSet<ProteinAbundance> listProteinWithAbundanceByExperiment(LongSet proteinIDs);
@Select("select pr.id, pr.accession_number, pr.description, d.id as data_set_id, p.probability, " @Select("select pr.id, pr.accession_number, pr.description, d.id as data_set_id, p.probability, "
+ " ip.coverage, a.value as abundance, samples.perm_id as sample_perm_id " + " ip.coverage, a.value as abundance, samples.perm_id as sample_perm_id "
+ "from identified_proteins as ip left join proteins as p on ip.prot_id = p.id " + "from identified_proteins as ip left join proteins as p on ip.prot_id = p.id "
......
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto;
import java.io.Serializable;
import net.lemnik.eodsql.ResultColumn;
/**
*
*
* @author Franz-Josef Elmer
*/
public class ProteinAbundance extends AbstractDTOWithID implements Serializable
{
private static final long serialVersionUID = 1L;
@ResultColumn("value")
private double abundance;
@ResultColumn("perm_id")
private String samplePermID;
public double getAbundance()
{
return abundance;
}
public void setAbundance(double abundance)
{
this.abundance = abundance;
}
public String getSamplePermID()
{
return samplePermID;
}
public void setSampleID(String samplePermID)
{
this.samplePermID = samplePermID;
}
}
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto;
import java.io.Serializable;
import net.lemnik.eodsql.ResultColumn;
/**
*
*
* @author Franz-Josef Elmer
*/
public class ProteinReferenceWithProtein extends ProteinReference implements Serializable
{
private static final long serialVersionUID = 1L;
@ResultColumn("data_set_id")
private long dataSetID;
@ResultColumn("protein_id")
private long proteinID;
@ResultColumn("probability")
private double probability;
@ResultColumn("coverage")
private double coverage;
public final long getDataSetID()
{
return dataSetID;
}
public final void setDataSetID(long dataSetID)
{
this.dataSetID = dataSetID;
}
public long getProteinID()
{
return proteinID;
}
public void setProteinID(long proteinID)
{
this.proteinID = proteinID;
}
public final double getProbability()
{
return probability;
}
public final void setProbability(double probability)
{
this.probability = probability;
}
public void setCoverage(double coverage)
{
this.coverage = coverage;
}
public double getCoverage()
{
return coverage;
}
}
...@@ -43,6 +43,7 @@ import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReferenceWi ...@@ -43,6 +43,7 @@ import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReferenceWi
* *
* @author Franz-Josef Elmer * @author Franz-Josef Elmer
*/ */
@Test(groups="broken")
public class ProteinInfoTableTest extends AbstractServerTestCase public class ProteinInfoTableTest extends AbstractServerTestCase
{ {
private static final double COVERAGE = 0.5; private static final double COVERAGE = 0.5;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment