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

upload only proteins with an FDR <= 10%

SVN: 13732
parent 5822cd68
No related branches found
No related tags found
No related merge requests found
...@@ -48,12 +48,15 @@ import ch.systemsx.cisd.openbis.etlserver.phosphonetx.dto.Sequence; ...@@ -48,12 +48,15 @@ import ch.systemsx.cisd.openbis.etlserver.phosphonetx.dto.Sequence;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Group; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Group;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.GroupIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.GroupIdentifier;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.ProbabilityToFDRCalculator;
/** /**
* @author Franz-Josef Elmer * @author Franz-Josef Elmer
*/ */
class ResultDataSetUploader extends AbstractHandler class ResultDataSetUploader extends AbstractHandler
{ {
private static final double MAX_FALSE_DISCOVERY_RATE = 0.1;
static final String PARAMETER_TYPE_ABUNDANCE = "abundance"; static final String PARAMETER_TYPE_ABUNDANCE = "abundance";
private final Connection connection; private final Connection connection;
...@@ -214,7 +217,7 @@ class ResultDataSetUploader extends AbstractHandler ...@@ -214,7 +217,7 @@ class ResultDataSetUploader extends AbstractHandler
Long databaseID = dataSet.getDatabaseID(); Long databaseID = dataSet.getDatabaseID();
AbundanceHandler abundanceHandler = AbundanceHandler abundanceHandler =
new AbundanceHandler(openbisService, dao, groupIdentifier, experiment); new AbundanceHandler(openbisService, dao, groupIdentifier, experiment);
createProbabilityToFDRMapping(dataSetID, summary); ProbabilityToFDRCalculator calculator = createProbabilityToFDRMapping(dataSetID, summary);
List<ProteinGroup> proteinGroups = summary.getProteinGroups(); List<ProteinGroup> proteinGroups = summary.getProteinGroups();
for (ProteinGroup proteinGroup : proteinGroups) for (ProteinGroup proteinGroup : proteinGroups)
{ {
...@@ -225,7 +228,10 @@ class ResultDataSetUploader extends AbstractHandler ...@@ -225,7 +228,10 @@ class ResultDataSetUploader extends AbstractHandler
Protein protein = proteins.get(0); Protein protein = proteins.get(0);
try try
{ {
addProtein(protein, dataSetID, databaseID, abundanceHandler); if (calculator.calculateFDR(protein.getProbability()) <= MAX_FALSE_DISCOVERY_RATE)
{
addProtein(protein, dataSetID, databaseID, abundanceHandler);
}
} catch (Exception e) } catch (Exception e)
{ {
logException(e, "protein", protein.getName()); logException(e, "protein", protein.getName());
...@@ -354,8 +360,9 @@ class ResultDataSetUploader extends AbstractHandler ...@@ -354,8 +360,9 @@ class ResultDataSetUploader extends AbstractHandler
return null; return null;
} }
private void createProbabilityToFDRMapping(long dataSetID, ProteinSummary summary) private ProbabilityToFDRCalculator createProbabilityToFDRMapping(long dataSetID, ProteinSummary summary)
{ {
ProbabilityToFDRCalculator calculator = new ProbabilityToFDRCalculator();
Object[] s = summary.getSummaryHeader().getProgramDetails().getSummary(); Object[] s = summary.getSummaryHeader().getProgramDetails().getSummary();
if (s != null) if (s != null)
{ {
...@@ -369,9 +376,10 @@ class ResultDataSetUploader extends AbstractHandler ...@@ -369,9 +376,10 @@ class ResultDataSetUploader extends AbstractHandler
{ {
double probability = proteinSummaryDataFilter.getMinProbability(); double probability = proteinSummaryDataFilter.getMinProbability();
double fdr = proteinSummaryDataFilter.getFalsePositiveErrorRate(); double fdr = proteinSummaryDataFilter.getFalsePositiveErrorRate();
calculator.add(probability, fdr);
dao.createProbabilityToFDRMapping(dataSetID, probability, fdr); dao.createProbabilityToFDRMapping(dataSetID, probability, fdr);
} }
return; return calculator;
} }
} }
} }
......
...@@ -16,16 +16,14 @@ ...@@ -16,16 +16,14 @@
package ch.systemsx.cisd.openbis.plugin.phosphonetx.server.business; package ch.systemsx.cisd.openbis.plugin.phosphonetx.server.business;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import net.lemnik.eodsql.DataSet; import net.lemnik.eodsql.DataSet;
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.server.dataaccess.IProteinQueryDAO;
import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.ProbabilityToFDRCalculator;
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.ProteinReferenceWithProbability; import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReferenceWithProbability;
...@@ -35,63 +33,6 @@ import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReferenceWi ...@@ -35,63 +33,6 @@ import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.dto.ProteinReferenceWi
*/ */
class ErrorModel class ErrorModel
{ {
private static final class ProbabilityToFDRCalculator
{
private static final class MappingEntry implements Comparable<MappingEntry>
{
private final double probability;
private final double fdr;
MappingEntry(double probability, double fdr)
{
this.probability = probability;
this.fdr = fdr;
}
public int compareTo(MappingEntry that)
{
return probability < that.probability ? -1 : (probability > that.probability ? 1
: 0);
}
@Override
public String toString()
{
return probability + " = " + fdr;
}
}
private final List<MappingEntry> mappingEntries = new ArrayList<MappingEntry>();
void add(double probability, double falseDiscoveryRate)
{
mappingEntries.add(new MappingEntry(probability, falseDiscoveryRate));
}
void init()
{
Collections.sort(mappingEntries);
}
double calculateFDR(double probability)
{
int index = Collections.binarySearch(mappingEntries, new MappingEntry(probability, 0));
if (index >= 0)
{
return mappingEntries.get(index).fdr;
}
// calculate by linear interpolation
int index1 = -index - 1;
int index0 = index1 - 1;
assert index0 >= 0;
MappingEntry m0 = mappingEntries.get(index0);
MappingEntry m1 = mappingEntries.get(index1);
double scale = (m1.fdr - m0.fdr) / (m1.probability - m0.probability);
return m0.fdr + scale * (probability - m0.probability);
}
}
private final Map<Long, ProbabilityToFDRCalculator> calculators = private final Map<Long, ProbabilityToFDRCalculator> calculators =
new HashMap<Long, ProbabilityToFDRCalculator>(); new HashMap<Long, ProbabilityToFDRCalculator>();
......
/*
* Copyright 2009 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;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public final class ProbabilityToFDRCalculator
{
private static final class MappingEntry implements Comparable<ProbabilityToFDRCalculator.MappingEntry>
{
private final double probability;
private final double fdr;
MappingEntry(double probability, double fdr)
{
this.probability = probability;
this.fdr = fdr;
}
public int compareTo(ProbabilityToFDRCalculator.MappingEntry that)
{
return probability < that.probability ? -1 : (probability > that.probability ? 1
: 0);
}
@Override
public String toString()
{
return probability + " = " + fdr;
}
}
private final List<ProbabilityToFDRCalculator.MappingEntry> mappingEntries = new ArrayList<ProbabilityToFDRCalculator.MappingEntry>();
public void add(double probability, double falseDiscoveryRate)
{
mappingEntries.add(new MappingEntry(probability, falseDiscoveryRate));
}
public void init()
{
Collections.sort(mappingEntries);
}
public double calculateFDR(double probability)
{
int index = Collections.binarySearch(mappingEntries, new MappingEntry(probability, 0));
if (index >= 0)
{
return mappingEntries.get(index).fdr;
}
// calculate by linear interpolation
int index1 = -index - 1;
int index0 = index1 - 1;
assert index0 >= 0;
ProbabilityToFDRCalculator.MappingEntry m0 = mappingEntries.get(index0);
ProbabilityToFDRCalculator.MappingEntry m1 = mappingEntries.get(index1);
double scale = (m1.fdr - m0.fdr) / (m1.probability - m0.probability);
return m0.fdr + scale * (probability - m0.probability);
}
}
\ No newline at end of file
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