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

SSDM-1287: raw score and evalue provided.

SVN: 33013
parent 48c7e994
No related branches found
No related tags found
No related merge requests found
...@@ -45,6 +45,7 @@ import ch.systemsx.cisd.etlserver.plugins.BlastDatabaseCreationMaintenanceTask; ...@@ -45,6 +45,7 @@ import ch.systemsx.cisd.etlserver.plugins.BlastDatabaseCreationMaintenanceTask;
import ch.systemsx.cisd.openbis.dss.generic.shared.api.internal.v2.ISearchDomainService; import ch.systemsx.cisd.openbis.dss.generic.shared.api.internal.v2.ISearchDomainService;
import ch.systemsx.cisd.openbis.dss.generic.shared.utils.BlastUtils; import ch.systemsx.cisd.openbis.dss.generic.shared.utils.BlastUtils;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.AlignmentMatch; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.AlignmentMatch;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.BlastScore;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetFileBlastSearchResultLocation; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetFileBlastSearchResultLocation;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.EntityKind;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.EntityPropertyBlastSearchResultLocation; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.EntityPropertyBlastSearchResultLocation;
...@@ -162,35 +163,21 @@ public class BlastDatabase extends AbstractSearchDomainService ...@@ -162,35 +163,21 @@ public class BlastDatabase extends AbstractSearchDomainService
{ {
Row row = new Row(line); Row row = new Row(line);
SearchDomainSearchResult sequenceSearchResult = new SearchDomainSearchResult(); SearchDomainSearchResult sequenceSearchResult = new SearchDomainSearchResult();
sequenceSearchResult.setScore(row.bitscore); sequenceSearchResult.setScore(createBlastScore(row));
AlignmentMatch alignmentMatch = new AlignmentMatch(); AlignmentMatch alignmentMatch = createAlignmentMatch(row);
alignmentMatch.setSequenceStart(row.sstart);
alignmentMatch.setSequenceEnd(row.send);
alignmentMatch.setQueryStart(row.qstart);
alignmentMatch.setQueryEnd(row.qend);
alignmentMatch.setNumberOfMismatches(row.numberOfMismatchs);
alignmentMatch.setTotalNumberOfGaps(row.totalNumberOfGaps);
Matcher matcher = STITLE_PATTERN.matcher(row.title); Matcher matcher = STITLE_PATTERN.matcher(row.title);
if (matcher.matches()) if (matcher.matches())
{ {
DataSetFileBlastSearchResultLocation resultLocation = new DataSetFileBlastSearchResultLocation(); sequenceSearchResult.setResultLocation(
resultLocation.setIdentifier(matcher.group(1)); createDataSetFileBlastSearchResultLocation(matcher, alignmentMatch));
resultLocation.setDataSetCode(matcher.group(2));
resultLocation.setPathInDataSet(matcher.group(3));
resultLocation.setAlignmentMatch(alignmentMatch);
sequenceSearchResult.setResultLocation(resultLocation);
result.add(sequenceSearchResult); result.add(sequenceSearchResult);
} else } else
{ {
matcher = ENTITY_PROPERTY_TITLE_PATTERN.matcher(row.title); matcher = ENTITY_PROPERTY_TITLE_PATTERN.matcher(row.title);
if (matcher.matches()) if (matcher.matches())
{ {
EntityPropertyBlastSearchResultLocation resultLocation = new EntityPropertyBlastSearchResultLocation(); sequenceSearchResult.setResultLocation(
resultLocation.setEntityKind(EntityKind.valueOf(matcher.group(1))); createEntityPropertyBlastSearchResultLocation(matcher, alignmentMatch));
resultLocation.setPermId(matcher.group(2));
resultLocation.setPropertyType(matcher.group(3));
resultLocation.setAlignmentMatch(alignmentMatch);
sequenceSearchResult.setResultLocation(resultLocation);
result.add(sequenceSearchResult); result.add(sequenceSearchResult);
} }
} }
...@@ -201,6 +188,47 @@ public class BlastDatabase extends AbstractSearchDomainService ...@@ -201,6 +188,47 @@ public class BlastDatabase extends AbstractSearchDomainService
} }
return result; return result;
} }
private EntityPropertyBlastSearchResultLocation createEntityPropertyBlastSearchResultLocation(Matcher matcher, AlignmentMatch alignmentMatch)
{
EntityPropertyBlastSearchResultLocation resultLocation = new EntityPropertyBlastSearchResultLocation();
resultLocation.setEntityKind(EntityKind.valueOf(matcher.group(1)));
resultLocation.setPermId(matcher.group(2));
resultLocation.setPropertyType(matcher.group(3));
resultLocation.setAlignmentMatch(alignmentMatch);
return resultLocation;
}
private DataSetFileBlastSearchResultLocation createDataSetFileBlastSearchResultLocation(Matcher matcher, AlignmentMatch alignmentMatch)
{
DataSetFileBlastSearchResultLocation resultLocation = new DataSetFileBlastSearchResultLocation();
resultLocation.setIdentifier(matcher.group(1));
resultLocation.setDataSetCode(matcher.group(2));
resultLocation.setPathInDataSet(matcher.group(3));
resultLocation.setAlignmentMatch(alignmentMatch);
return resultLocation;
}
private AlignmentMatch createAlignmentMatch(Row row)
{
AlignmentMatch alignmentMatch = new AlignmentMatch();
alignmentMatch.setSequenceStart(row.sstart);
alignmentMatch.setSequenceEnd(row.send);
alignmentMatch.setQueryStart(row.qstart);
alignmentMatch.setQueryEnd(row.qend);
alignmentMatch.setNumberOfMismatches(row.numberOfMismatchs);
alignmentMatch.setTotalNumberOfGaps(row.totalNumberOfGaps);
return alignmentMatch;
}
private BlastScore createBlastScore(Row row)
{
BlastScore blastScore = new BlastScore();
blastScore.setScore(row.score);
blastScore.setBitScore(row.bitscore);
blastScore.setEvalue(row.evalue);
return blastScore;
}
private List<String> createCommand(SequenceType sequenceType, File queryFile, Map<String, String> parameters) private List<String> createCommand(SequenceType sequenceType, File queryFile, Map<String, String> parameters)
{ {
...@@ -223,7 +251,7 @@ public class BlastDatabase extends AbstractSearchDomainService ...@@ -223,7 +251,7 @@ public class BlastDatabase extends AbstractSearchDomainService
command.add("-query"); command.add("-query");
command.add(queryFile.getAbsolutePath()); command.add(queryFile.getAbsolutePath());
command.add("-outfmt"); command.add("-outfmt");
command.add("6 stitle bitscore sstart send qstart qend mismatch gaps"); command.add("6 stitle bitscore score evalue sstart send qstart qend mismatch gaps");
if (parameters.containsKey("task") == false) if (parameters.containsKey("task") == false)
{ {
parameters.put("task", defaultTask); parameters.put("task", defaultTask);
...@@ -304,6 +332,8 @@ public class BlastDatabase extends AbstractSearchDomainService ...@@ -304,6 +332,8 @@ public class BlastDatabase extends AbstractSearchDomainService
{ {
private String title; private String title;
private double bitscore; private double bitscore;
private double score;
private double evalue;
private int sstart; private int sstart;
private int send; private int send;
private int qstart; private int qstart;
...@@ -317,6 +347,8 @@ public class BlastDatabase extends AbstractSearchDomainService ...@@ -317,6 +347,8 @@ public class BlastDatabase extends AbstractSearchDomainService
String[] cells = line.split("\t"); String[] cells = line.split("\t");
title = cells[len++]; title = cells[len++];
bitscore = asDouble(cells); bitscore = asDouble(cells);
score = asDouble(cells);
evalue = asDouble(cells);
sstart = asInt(cells); sstart = asInt(cells);
send = asInt(cells); send = asInt(cells);
qstart = asInt(cells); qstart = asInt(cells);
......
...@@ -34,6 +34,7 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.AlignmentMatch; ...@@ -34,6 +34,7 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.AlignmentMatch;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetFileSearchResultLocation; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetFileSearchResultLocation;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.EntityKind;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.EntityPropertyBlastSearchResultLocation; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.EntityPropertyBlastSearchResultLocation;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.ISearchDomainResultScore;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchDomain; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchDomain;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchDomainSearchResult; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchDomainSearchResult;
import ch.systemsx.cisd.openbis.generic.shared.basic.IPermIdHolder; import ch.systemsx.cisd.openbis.generic.shared.basic.IPermIdHolder;
...@@ -139,22 +140,22 @@ public class SearchDomainSearcherTest extends AbstractBOTest ...@@ -139,22 +140,22 @@ public class SearchDomainSearcherTest extends AbstractBOTest
createSearcher().searchForEntitiesWithSequences(SEQUENCE_DATABASE, SEQUENCE_SNIPPET, OPTIONAL_PARAMETERS); createSearcher().searchForEntitiesWithSequences(SEQUENCE_DATABASE, SEQUENCE_SNIPPET, OPTIONAL_PARAMETERS);
assertEquals("E1", results.get(0).getEntity().getPermId()); assertEquals("E1", results.get(0).getEntity().getPermId());
assertEquals("Search Domain: test-db, Score: 11.5, Result location: " assertEquals("Search Domain: test-db, Score: [11.5], Result location: "
+ "[Experiment perm id: E1, property type: S, alignment in sequence: [42-45], " + "[Experiment perm id: E1, property type: S, alignment in sequence: [42-45], "
+ "alignment in query: [7-10], number of mismatches: 0, total number of gaps: 0]", + "alignment in query: [7-10], number of mismatches: 0, total number of gaps: 0]",
results.get(0).getSearchResult().toString()); results.get(0).getSearchResult().toString());
assertEquals("S2", results.get(1).getEntity().getPermId()); assertEquals("S2", results.get(1).getEntity().getPermId());
assertEquals("Search Domain: test-db, Score: 10.5, Result location: " assertEquals("Search Domain: test-db, Score: [10.5], Result location: "
+ "[Sample perm id: S2, property type: OLIGO, alignment in sequence: [42-45], " + "[Sample perm id: S2, property type: OLIGO, alignment in sequence: [42-45], "
+ "alignment in query: [7-10], number of mismatches: 0, total number of gaps: 0]", + "alignment in query: [7-10], number of mismatches: 0, total number of gaps: 0]",
results.get(1).getSearchResult().toString()); results.get(1).getSearchResult().toString());
assertEquals("S1", results.get(2).getEntity().getPermId()); assertEquals("S1", results.get(2).getEntity().getPermId());
assertEquals("Search Domain: test-db, Score: 9.5, Result location: " assertEquals("Search Domain: test-db, Score: [9.5], Result location: "
+ "[Sample perm id: S1, property type: OLIGO, alignment in sequence: [42-45], " + "[Sample perm id: S1, property type: OLIGO, alignment in sequence: [42-45], "
+ "alignment in query: [7-10], number of mismatches: 0, total number of gaps: 0]", + "alignment in query: [7-10], number of mismatches: 0, total number of gaps: 0]",
results.get(2).getSearchResult().toString()); results.get(2).getSearchResult().toString());
assertEquals("DS1", results.get(3).getEntity().getPermId()); assertEquals("DS1", results.get(3).getEntity().getPermId());
assertEquals("Search Domain: test-db, Score: 0.5, Result location: " assertEquals("Search Domain: test-db, Score: [0.5], Result location: "
+ "[Data set perm id: DS1, property type: SEQ, alignment in sequence: [42-45], " + "[Data set perm id: DS1, property type: SEQ, alignment in sequence: [42-45], "
+ "alignment in query: [7-10], number of mismatches: 0, total number of gaps: 0]", + "alignment in query: [7-10], number of mismatches: 0, total number of gaps: 0]",
results.get(3).getSearchResult().toString()); results.get(3).getSearchResult().toString());
...@@ -175,22 +176,22 @@ public class SearchDomainSearcherTest extends AbstractBOTest ...@@ -175,22 +176,22 @@ public class SearchDomainSearcherTest extends AbstractBOTest
List<SearchDomainSearchResultWithFullEntity> results = List<SearchDomainSearchResultWithFullEntity> results =
createSearcher().searchForEntitiesWithSequences(SEQUENCE_DATABASE, SEQUENCE_SNIPPET, OPTIONAL_PARAMETERS); createSearcher().searchForEntitiesWithSequences(SEQUENCE_DATABASE, SEQUENCE_SNIPPET, OPTIONAL_PARAMETERS);
assertEquals("Search Domain: test-db, Score: 14.5, Result location: [Data set: ds3, path: ds3/path, " assertEquals("Search Domain: test-db, Score: [14.5], Result location: [Data set: ds3, path: ds3/path, "
+ "identifier: [id-ds3], position: 42]", + "identifier: [id-ds3], position: 42]",
results.get(0).getSearchResult().toString()); results.get(0).getSearchResult().toString());
assertEquals(ds3.getCode(), ((AbstractExternalData) results.get(0).getEntity()).getCode()); assertEquals(ds3.getCode(), ((AbstractExternalData) results.get(0).getEntity()).getCode());
assertEquals("/G1/P1/exp1", ((AbstractExternalData) results.get(0).getEntity()).getExperiment().getIdentifier()); assertEquals("/G1/P1/exp1", ((AbstractExternalData) results.get(0).getEntity()).getExperiment().getIdentifier());
assertEquals("Search Domain: test-db, Score: 13.5, Result location: [Data set: ds3, path: ds3/path, " assertEquals("Search Domain: test-db, Score: [13.5], Result location: [Data set: ds3, path: ds3/path, "
+ "identifier: [id-ds3], position: 42]", + "identifier: [id-ds3], position: 42]",
results.get(1).getSearchResult().toString()); results.get(1).getSearchResult().toString());
assertEquals(ds3.getCode(), ((AbstractExternalData) results.get(1).getEntity()).getCode()); assertEquals(ds3.getCode(), ((AbstractExternalData) results.get(1).getEntity()).getCode());
assertEquals("/G1/P1/exp1", ((AbstractExternalData) results.get(1).getEntity()).getExperiment().getIdentifier()); assertEquals("/G1/P1/exp1", ((AbstractExternalData) results.get(1).getEntity()).getExperiment().getIdentifier());
assertEquals("Search Domain: test-db, Score: 1.5, Result location: [Data set: ds2, path: ds2/path, " assertEquals("Search Domain: test-db, Score: [1.5], Result location: [Data set: ds2, path: ds2/path, "
+ "identifier: [id-ds2], position: 42]", + "identifier: [id-ds2], position: 42]",
results.get(2).getSearchResult().toString()); results.get(2).getSearchResult().toString());
assertEquals(ds2.getCode(), ((AbstractExternalData) results.get(2).getEntity()).getCode()); assertEquals(ds2.getCode(), ((AbstractExternalData) results.get(2).getEntity()).getCode());
assertEquals("/G1/P1/exp1", ((AbstractExternalData) results.get(2).getEntity()).getExperiment().getIdentifier()); assertEquals("/G1/P1/exp1", ((AbstractExternalData) results.get(2).getEntity()).getExperiment().getIdentifier());
assertEquals("Search Domain: test-db, Score: 0.5, Result location: [Data set: ds1, path: ds1/path, " assertEquals("Search Domain: test-db, Score: [0.5], Result location: [Data set: ds1, path: ds1/path, "
+ "identifier: [id-ds1], position: 42]", + "identifier: [id-ds1], position: 42]",
results.get(3).getSearchResult().toString()); results.get(3).getSearchResult().toString());
assertEquals(ds1.getCode(), ((AbstractExternalData) results.get(3).getEntity()).getCode()); assertEquals(ds1.getCode(), ((AbstractExternalData) results.get(3).getEntity()).getCode());
...@@ -241,7 +242,7 @@ public class SearchDomainSearcherTest extends AbstractBOTest ...@@ -241,7 +242,7 @@ public class SearchDomainSearcherTest extends AbstractBOTest
SearchDomain searchDomain = new SearchDomain(); SearchDomain searchDomain = new SearchDomain();
searchDomain.setName("test-db"); searchDomain.setName("test-db");
result.setSearchDomain(searchDomain); result.setSearchDomain(searchDomain);
result.setScore(score++); result.setScore(new SimpleScore(score++));
DataSetFileSearchResultLocation resultLocation = new DataSetFileSearchResultLocation(); DataSetFileSearchResultLocation resultLocation = new DataSetFileSearchResultLocation();
resultLocation.setDataSetCode(foundDataSet); resultLocation.setDataSetCode(foundDataSet);
resultLocation.setPathInDataSet(foundDataSet + "/path"); resultLocation.setPathInDataSet(foundDataSet + "/path");
...@@ -254,7 +255,7 @@ public class SearchDomainSearcherTest extends AbstractBOTest ...@@ -254,7 +255,7 @@ public class SearchDomainSearcherTest extends AbstractBOTest
} }
}); });
} }
private void prepareSearchForEntityPropertiesWithSequences(final DataStorePE dataStore, private void prepareSearchForEntityPropertiesWithSequences(final DataStorePE dataStore,
final IDataStoreService service, final double initialScore, final String... foundLocations) final IDataStoreService service, final double initialScore, final String... foundLocations)
{ {
...@@ -271,7 +272,7 @@ public class SearchDomainSearcherTest extends AbstractBOTest ...@@ -271,7 +272,7 @@ public class SearchDomainSearcherTest extends AbstractBOTest
SearchDomain searchDomain = new SearchDomain(); SearchDomain searchDomain = new SearchDomain();
searchDomain.setName("test-db"); searchDomain.setName("test-db");
result.setSearchDomain(searchDomain); result.setSearchDomain(searchDomain);
result.setScore(score++); result.setScore(new SimpleScore(score++));
EntityPropertyBlastSearchResultLocation resultLocation = new EntityPropertyBlastSearchResultLocation(); EntityPropertyBlastSearchResultLocation resultLocation = new EntityPropertyBlastSearchResultLocation();
String[] splittedLocation = foundLocation.split(":"); String[] splittedLocation = foundLocation.split(":");
resultLocation.setEntityKind(EntityKind.valueOf(splittedLocation[0])); resultLocation.setEntityKind(EntityKind.valueOf(splittedLocation[0]));
...@@ -392,4 +393,28 @@ public class SearchDomainSearcherTest extends AbstractBOTest ...@@ -392,4 +393,28 @@ public class SearchDomainSearcherTest extends AbstractBOTest
} }
return permIds; return permIds;
} }
private static final class SimpleScore implements ISearchDomainResultScore
{
private static final long serialVersionUID = 1L;
private final double score;
SimpleScore(double score)
{
this.score = score;
}
@Override
public double getScore()
{
return score;
}
@Override
public String toString()
{
return Double.toString(score);
}
}
} }
/*
* Copyright 2014 ETH Zuerich, SIS
*
* 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.generic.shared.api.v1.dto;
import ch.systemsx.cisd.base.annotation.JsonObject;
/**
* Wraps raw score, bit score and evalue of a BLAST search result.
*
* @author Franz-Josef Elmer
*/
@JsonObject("BlastScore")
public class BlastScore implements ISearchDomainResultScore
{
private static final long serialVersionUID = 1L;
private double score;
private double bitScore;
private double evalue;
@Override
public double getScore()
{
return score;
}
public void setScore(double score)
{
this.score = score;
}
public double getBitScore()
{
return bitScore;
}
public void setBitScore(double bitScore)
{
this.bitScore = bitScore;
}
public double getEvalue()
{
return evalue;
}
public void setEvalue(double evalue)
{
this.evalue = evalue;
}
@Override
public String toString()
{
return "Score: " + score + ", bit score: " + bitScore + ", evalue: " + evalue;
}
}
/*
* Copyright 2014 ETH Zuerich, SIS
*
* 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.generic.shared.api.v1.dto;
import java.io.Serializable;
import ch.systemsx.cisd.base.annotation.JsonObject;
/**
* Basic interface of classes specifying a score of search domain result.
*
* @author Franz-Josef Elmer
*/
@JsonObject("ISearchDomainResultScore")
public interface ISearchDomainResultScore extends Serializable
{
/**
* Returns the score of the result.
*/
public double getScore();
}
...@@ -34,7 +34,7 @@ public class SearchDomainSearchResult implements Serializable, Comparable<Search ...@@ -34,7 +34,7 @@ public class SearchDomainSearchResult implements Serializable, Comparable<Search
private ISearchDomainResultLocation resultLocation; private ISearchDomainResultLocation resultLocation;
private double score; private ISearchDomainResultScore score;
public SearchDomain getSearchDomain() public SearchDomain getSearchDomain()
{ {
...@@ -46,12 +46,12 @@ public class SearchDomainSearchResult implements Serializable, Comparable<Search ...@@ -46,12 +46,12 @@ public class SearchDomainSearchResult implements Serializable, Comparable<Search
this.searchDomain = searchDomain; this.searchDomain = searchDomain;
} }
public double getScore() public ISearchDomainResultScore getScore()
{ {
return score; return score;
} }
public void setScore(double score) public void setScore(ISearchDomainResultScore score)
{ {
this.score = score; this.score = score;
} }
...@@ -69,14 +69,14 @@ public class SearchDomainSearchResult implements Serializable, Comparable<Search ...@@ -69,14 +69,14 @@ public class SearchDomainSearchResult implements Serializable, Comparable<Search
@Override @Override
public int compareTo(SearchDomainSearchResult searchResult) public int compareTo(SearchDomainSearchResult searchResult)
{ {
return Double.compare(score, searchResult.getScore()); return Double.compare(score.getScore(), searchResult.getScore().getScore());
} }
@Override @Override
public String toString() public String toString()
{ {
return "Search Domain: " + getSearchDomain() + ", Score: " + score return "Search Domain: " + getSearchDomain() + ", Score: [" + score
+ ", Result location: [" + resultLocation + "]"; + "], Result location: [" + resultLocation + "]";
} }
} }
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