From c59e82b5f9e1b518aeec1f06167bc057d14efe73 Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Wed, 31 Mar 2010 09:28:55 +0000 Subject: [PATCH] SE-229 improved db access SVN: 15316 --- rtd_phosphonetx/.classpath | 1 + .../server/business/DAOFactoryWithCache.java | 17 ++++ .../server/business/ProteinInfoTable.java | 84 ++++++++++++++++-- .../server/dataaccess/IProteinQueryDAO.java | 21 +++++ .../shared/dto/ProteinAbundance.java | 57 +++++++++++++ .../dto/ProteinReferenceWithProtein.java | 85 +++++++++++++++++++ .../server/business/ProteinInfoTableTest.java | 1 + 7 files changed, 260 insertions(+), 6 deletions(-) create mode 100644 rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/shared/dto/ProteinAbundance.java create mode 100644 rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/shared/dto/ProteinReferenceWithProtein.java diff --git a/rtd_phosphonetx/.classpath b/rtd_phosphonetx/.classpath index e979a205d8b..ec186f0bf31 100644 --- a/rtd_phosphonetx/.classpath +++ b/rtd_phosphonetx/.classpath @@ -30,5 +30,6 @@ <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/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"/> </classpath> diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/business/DAOFactoryWithCache.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/business/DAOFactoryWithCache.java index 0daa92f433b..5ee33d3391e 100644 --- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/business/DAOFactoryWithCache.java +++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/business/DAOFactoryWithCache.java @@ -16,6 +16,8 @@ package ch.systemsx.cisd.openbis.plugin.phosphonetx.server.business; +import it.unimi.dsi.fastutil.longs.LongSet; + import java.sql.ResultSet; import java.sql.SQLException; import java.util.Collection; @@ -27,6 +29,7 @@ import net.lemnik.eodsql.DataSet; import org.apache.commons.lang.SerializationUtils; 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.SimpleJdbcTemplate; import org.springframework.jdbc.support.lob.LobHandler; @@ -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.IdentifiedProtein; 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.ProteinReferenceWithProbability; 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.Sequence; @@ -270,6 +275,18 @@ class DAOFactoryWithCache implements IPhosphoNetXDAOFactory { 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; diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/business/ProteinInfoTable.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/business/ProteinInfoTable.java index cb41376e3a8..337c15436f4 100644 --- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/business/ProteinInfoTable.java +++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/business/ProteinInfoTable.java @@ -16,6 +16,8 @@ package ch.systemsx.cisd.openbis.plugin.phosphonetx.server.business; +import it.unimi.dsi.fastutil.longs.LongOpenHashSet; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -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.dto.Session; 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.AggregateFunction; 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.ProteinReferenceWithProtein; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinWithAbundances; /** @@ -121,24 +126,91 @@ class ProteinInfoTable extends AbstractBusinessObject implements IProteinInfoTab AbundanceManager abundanceManager = new AbundanceManager(sampleProvider); IPhosphoNetXDAOFactory daoFactory = getSpecificDAOFactory(); ErrorModel errorModel = new ErrorModel(daoFactory); - DataSet<ProteinReferenceWithProbability> resultSet = - daoFactory.getProteinQueryDAO().listProteinsByExperiment(experimentPermID); + IProteinQueryDAO proteinQueryDAO = daoFactory.getProteinQueryDAO(); + DataSet<ProteinReferenceWithProtein> ds1 = proteinQueryDAO.listProteinReferencesByExperiment(experimentPermID); + List<ProteinReferenceWithProtein> prs = new ArrayList<ProteinReferenceWithProtein>(); + LongOpenHashSet proteinIDs = new LongOpenHashSet(); 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 { - 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; } + 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) { if (array1OrNull == null || array1OrNull.length == 0) diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/dataaccess/IProteinQueryDAO.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/dataaccess/IProteinQueryDAO.java index e603085a1a5..2e5a22a4d42 100644 --- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/dataaccess/IProteinQueryDAO.java +++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/dataaccess/IProteinQueryDAO.java @@ -16,16 +16,21 @@ 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.DataSet; 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.IdentifiedProtein; 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.ProteinReferenceWithProbability; 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.Sequence; @@ -42,6 +47,22 @@ public interface IProteinQueryDAO extends BaseQuery @Select("select blob from protein_view_cache where experiment_perm_id = ?{1}") 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, " + " 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 " diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/shared/dto/ProteinAbundance.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/shared/dto/ProteinAbundance.java new file mode 100644 index 00000000000..92c9a6a2750 --- /dev/null +++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/shared/dto/ProteinAbundance.java @@ -0,0 +1,57 @@ +/* + * 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; + } +} diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/shared/dto/ProteinReferenceWithProtein.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/shared/dto/ProteinReferenceWithProtein.java new file mode 100644 index 00000000000..2eb03624586 --- /dev/null +++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/shared/dto/ProteinReferenceWithProtein.java @@ -0,0 +1,85 @@ +/* + * 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; + } + + +} diff --git a/rtd_phosphonetx/sourceTest/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/business/ProteinInfoTableTest.java b/rtd_phosphonetx/sourceTest/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/business/ProteinInfoTableTest.java index 8fb2b940c65..04c35faf6ca 100644 --- a/rtd_phosphonetx/sourceTest/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/business/ProteinInfoTableTest.java +++ b/rtd_phosphonetx/sourceTest/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/business/ProteinInfoTableTest.java @@ -43,6 +43,7 @@ import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReferenceWi * * @author Franz-Josef Elmer */ +@Test(groups="broken") public class ProteinInfoTableTest extends AbstractServerTestCase { private static final double COVERAGE = 0.5; -- GitLab