diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/api/v2/sequencedatabases/BlastDatabase.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/api/v2/sequencedatabases/BlastDatabase.java index fd3fffd4f4fb162a6aa1cf53003ff63c0cb70518..353230d43c5489ec9ba375718a3bb09eb79ee202 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/api/v2/sequencedatabases/BlastDatabase.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/api/v2/sequencedatabases/BlastDatabase.java @@ -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.utils.BlastUtils; 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.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.EntityPropertyBlastSearchResultLocation; @@ -162,35 +163,21 @@ public class BlastDatabase extends AbstractSearchDomainService { Row row = new Row(line); SearchDomainSearchResult sequenceSearchResult = new SearchDomainSearchResult(); - sequenceSearchResult.setScore(row.bitscore); - 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); + sequenceSearchResult.setScore(createBlastScore(row)); + AlignmentMatch alignmentMatch = createAlignmentMatch(row); Matcher matcher = STITLE_PATTERN.matcher(row.title); if (matcher.matches()) { - DataSetFileBlastSearchResultLocation resultLocation = new DataSetFileBlastSearchResultLocation(); - resultLocation.setIdentifier(matcher.group(1)); - resultLocation.setDataSetCode(matcher.group(2)); - resultLocation.setPathInDataSet(matcher.group(3)); - resultLocation.setAlignmentMatch(alignmentMatch); - sequenceSearchResult.setResultLocation(resultLocation); + sequenceSearchResult.setResultLocation( + createDataSetFileBlastSearchResultLocation(matcher, alignmentMatch)); result.add(sequenceSearchResult); } else { matcher = ENTITY_PROPERTY_TITLE_PATTERN.matcher(row.title); if (matcher.matches()) { - EntityPropertyBlastSearchResultLocation resultLocation = new EntityPropertyBlastSearchResultLocation(); - resultLocation.setEntityKind(EntityKind.valueOf(matcher.group(1))); - resultLocation.setPermId(matcher.group(2)); - resultLocation.setPropertyType(matcher.group(3)); - resultLocation.setAlignmentMatch(alignmentMatch); - sequenceSearchResult.setResultLocation(resultLocation); + sequenceSearchResult.setResultLocation( + createEntityPropertyBlastSearchResultLocation(matcher, alignmentMatch)); result.add(sequenceSearchResult); } } @@ -201,6 +188,47 @@ public class BlastDatabase extends AbstractSearchDomainService } 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) { @@ -223,7 +251,7 @@ public class BlastDatabase extends AbstractSearchDomainService command.add("-query"); command.add(queryFile.getAbsolutePath()); 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) { parameters.put("task", defaultTask); @@ -304,6 +332,8 @@ public class BlastDatabase extends AbstractSearchDomainService { private String title; private double bitscore; + private double score; + private double evalue; private int sstart; private int send; private int qstart; @@ -317,6 +347,8 @@ public class BlastDatabase extends AbstractSearchDomainService String[] cells = line.split("\t"); title = cells[len++]; bitscore = asDouble(cells); + score = asDouble(cells); + evalue = asDouble(cells); sstart = asInt(cells); send = asInt(cells); qstart = asInt(cells); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/SearchDomainSearcherTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/SearchDomainSearcherTest.java index 17e74650929f19f9fef45b640a652b5443fe7a0a..16de68eb33535db333016537fd151099117d9abb 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/SearchDomainSearcherTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/SearchDomainSearcherTest.java @@ -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.EntityKind; 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.SearchDomainSearchResult; import ch.systemsx.cisd.openbis.generic.shared.basic.IPermIdHolder; @@ -139,22 +140,22 @@ public class SearchDomainSearcherTest extends AbstractBOTest createSearcher().searchForEntitiesWithSequences(SEQUENCE_DATABASE, SEQUENCE_SNIPPET, OPTIONAL_PARAMETERS); 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], " + "alignment in query: [7-10], number of mismatches: 0, total number of gaps: 0]", results.get(0).getSearchResult().toString()); 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], " + "alignment in query: [7-10], number of mismatches: 0, total number of gaps: 0]", results.get(1).getSearchResult().toString()); 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], " + "alignment in query: [7-10], number of mismatches: 0, total number of gaps: 0]", results.get(2).getSearchResult().toString()); 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], " + "alignment in query: [7-10], number of mismatches: 0, total number of gaps: 0]", results.get(3).getSearchResult().toString()); @@ -175,22 +176,22 @@ public class SearchDomainSearcherTest extends AbstractBOTest List<SearchDomainSearchResultWithFullEntity> results = 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]", results.get(0).getSearchResult().toString()); assertEquals(ds3.getCode(), ((AbstractExternalData) results.get(0).getEntity()).getCode()); 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]", results.get(1).getSearchResult().toString()); assertEquals(ds3.getCode(), ((AbstractExternalData) results.get(1).getEntity()).getCode()); 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]", results.get(2).getSearchResult().toString()); assertEquals(ds2.getCode(), ((AbstractExternalData) results.get(2).getEntity()).getCode()); 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]", results.get(3).getSearchResult().toString()); assertEquals(ds1.getCode(), ((AbstractExternalData) results.get(3).getEntity()).getCode()); @@ -241,7 +242,7 @@ public class SearchDomainSearcherTest extends AbstractBOTest SearchDomain searchDomain = new SearchDomain(); searchDomain.setName("test-db"); result.setSearchDomain(searchDomain); - result.setScore(score++); + result.setScore(new SimpleScore(score++)); DataSetFileSearchResultLocation resultLocation = new DataSetFileSearchResultLocation(); resultLocation.setDataSetCode(foundDataSet); resultLocation.setPathInDataSet(foundDataSet + "/path"); @@ -254,7 +255,7 @@ public class SearchDomainSearcherTest extends AbstractBOTest } }); } - + private void prepareSearchForEntityPropertiesWithSequences(final DataStorePE dataStore, final IDataStoreService service, final double initialScore, final String... foundLocations) { @@ -271,7 +272,7 @@ public class SearchDomainSearcherTest extends AbstractBOTest SearchDomain searchDomain = new SearchDomain(); searchDomain.setName("test-db"); result.setSearchDomain(searchDomain); - result.setScore(score++); + result.setScore(new SimpleScore(score++)); EntityPropertyBlastSearchResultLocation resultLocation = new EntityPropertyBlastSearchResultLocation(); String[] splittedLocation = foundLocation.split(":"); resultLocation.setEntityKind(EntityKind.valueOf(splittedLocation[0])); @@ -392,4 +393,28 @@ public class SearchDomainSearcherTest extends AbstractBOTest } 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); + } + + } } diff --git a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/BlastScore.java b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/BlastScore.java new file mode 100644 index 0000000000000000000000000000000000000000..5fc523dbf91a423fe2bdd61f5487a40407409698 --- /dev/null +++ b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/BlastScore.java @@ -0,0 +1,74 @@ +/* + * 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; + } + +} diff --git a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/ISearchDomainResultScore.java b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/ISearchDomainResultScore.java new file mode 100644 index 0000000000000000000000000000000000000000..0629ebe5c52ac3ecce82bb62ee567937a275a24f --- /dev/null +++ b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/ISearchDomainResultScore.java @@ -0,0 +1,35 @@ +/* + * 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(); +} diff --git a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/SearchDomainSearchResult.java b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/SearchDomainSearchResult.java index bd0d561554e6f39b1cc6581bcda08a1da3c730e5..92b6ef83612d5cba0f50f71f7af8e3a44b614b41 100644 --- a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/SearchDomainSearchResult.java +++ b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/SearchDomainSearchResult.java @@ -34,7 +34,7 @@ public class SearchDomainSearchResult implements Serializable, Comparable<Search private ISearchDomainResultLocation resultLocation; - private double score; + private ISearchDomainResultScore score; public SearchDomain getSearchDomain() { @@ -46,12 +46,12 @@ public class SearchDomainSearchResult implements Serializable, Comparable<Search this.searchDomain = searchDomain; } - public double getScore() + public ISearchDomainResultScore getScore() { return score; } - public void setScore(double score) + public void setScore(ISearchDomainResultScore score) { this.score = score; } @@ -69,14 +69,14 @@ public class SearchDomainSearchResult implements Serializable, Comparable<Search @Override public int compareTo(SearchDomainSearchResult searchResult) { - return Double.compare(score, searchResult.getScore()); + return Double.compare(score.getScore(), searchResult.getScore().getScore()); } @Override public String toString() { - return "Search Domain: " + getSearchDomain() + ", Score: " + score - + ", Result location: [" + resultLocation + "]"; + return "Search Domain: " + getSearchDomain() + ", Score: [" + score + + "], Result location: [" + resultLocation + "]"; } }