Skip to content

Commit bbd0ef6

Browse files
authored
Merge pull request #2640 from opencb/TASK-5564
TASK-5564 - Update data sources for CellBase 6.x
2 parents 318a7af + 30efd6b commit bbd0ef6

11 files changed

Lines changed: 153 additions & 13 deletions

File tree

opencga-core/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
<filtering>true</filtering>
169169
<includes>
170170
<include>configuration.yml</include>
171+
<include>org/opencb/opencga/core/dependencies.properties</include>
171172
</includes>
172173
</resource>
173174
<resource>

opencga-core/src/main/java/org/opencb/opencga/core/cellbase/CellBaseValidator.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private CellBaseConfiguration validate(boolean autoComplete) throws IOException
167167

168168
String serverVersion = getVersionFromServer();
169169
if (!supportsDataRelease(serverVersion)) {
170-
logger.warn("DataRelease not supported on version '" + serverVersion + ".x'");
170+
logger.warn("DataRelease not supported on version '{}.x'", serverVersion);
171171
} else {
172172
String dataRelease = getDataRelease();
173173
if (StringUtils.isEmpty(dataRelease)) {
@@ -290,6 +290,24 @@ public static boolean supportsDataRelease(String serverVersion) {
290290
return VersionUtils.isMinVersion("5.1.0", serverVersion);
291291
}
292292

293+
/**
294+
* Check if the CellBase server supports Releases.
295+
*
296+
* Release support starts at version 6.7.0.
297+
* This is different from Data Release support which starts at version 5.1.0
298+
*
299+
* @return
300+
* @throws IOException
301+
*/
302+
public boolean supportsRelease() throws IOException {
303+
return supportsRelease(getVersionFromServer());
304+
}
305+
306+
public static boolean supportsRelease(String serverVersion) {
307+
// Release support starts at version 6.7.0
308+
return VersionUtils.isMinVersion("6.7.0", serverVersion);
309+
}
310+
293311
public boolean supportsDataReleaseActiveByDefaultIn() throws IOException {
294312
return supportsDataReleaseActiveByDefaultIn(getVersionFromServer());
295313
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package org.opencb.opencga.core.common;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
import java.io.InputStream;
7+
import java.util.Properties;
8+
9+
public class DependenciesState {
10+
11+
private static DependenciesState instance;
12+
private static final String DEPENDENCIES_RESOURCE_NAME = "org/opencb/opencga/core/dependencies.properties";
13+
14+
private Properties properties;
15+
16+
private DependenciesState(Properties properties) {
17+
this.properties = properties;
18+
}
19+
20+
public static DependenciesState getInstance() {
21+
if (instance == null) {
22+
Logger logger = LoggerFactory.getLogger(DependenciesState.class);
23+
Properties properties = new Properties();
24+
try (InputStream stream = DependenciesState.class.getClassLoader().getResourceAsStream(DEPENDENCIES_RESOURCE_NAME)) {
25+
if (stream != null) {
26+
properties.load(stream);
27+
}
28+
} catch (Exception e) {
29+
logger.warn("Could not load dependencies properties from resource: {}", DEPENDENCIES_RESOURCE_NAME, e);
30+
}
31+
instance = new DependenciesState(properties);
32+
}
33+
return instance;
34+
}
35+
36+
public String getDependencyVersion(String dependencyName) {
37+
return properties.getProperty(dependencyName);
38+
}
39+
40+
public String getOpenCGAVersion() {
41+
return properties.getProperty("opencga.version");
42+
}
43+
44+
public String getBiodataVersion() {
45+
return properties.getProperty("biodata.version");
46+
}
47+
48+
public String getCellBaseVersion() {
49+
return properties.getProperty("cellbase.version");
50+
}
51+
52+
public String getJavaCommonsLibsVersion() {
53+
return properties.getProperty("java-common-libs.version");
54+
}
55+
56+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
opencga.version=${project.version}
2+
cellbase.version=${cellbase.version}
3+
biodata.version=${biodata.version}
4+
java-common-libs.version=${java-common-libs.version}

opencga-core/src/test/java/org/opencb/opencga/core/cellbase/CellBaseValidatorTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,22 @@ public class CellBaseValidatorTest {
2424
public void testValidateFixVersion() throws IOException {
2525
CellBaseConfiguration c = CellBaseValidator.validate(new CellBaseConfiguration(ParamConstants.CELLBASE_URL, "5.2", "3", null), "hsapiens", "grch38", true);
2626
Assert.assertEquals("v5.2", c.getVersion());
27+
Assert.assertEquals("3", c.getDataRelease());
28+
29+
c = CellBaseValidator.validate(new CellBaseConfiguration(ParamConstants.CELLBASE_URL, "6.7", "1", null), "hsapiens", "grch38", true);
30+
Assert.assertEquals("v6.7", c.getVersion());
31+
Assert.assertEquals("1", c.getDataRelease());
2732
}
2833

2934
@Test
3035
public void testValidateUndefinedDataRelease() throws IOException {
3136
CellBaseConfiguration c = CellBaseValidator.validate(new CellBaseConfiguration(ParamConstants.CELLBASE_URL, "v5.2", null, null), "hsapiens", "grch38", true);
3237
Assert.assertEquals("v5.2", c.getVersion());
3338
Assert.assertNotNull(c.getDataRelease());
39+
40+
c = CellBaseValidator.validate(new CellBaseConfiguration(ParamConstants.CELLBASE_URL, "v6.7", null, null), "hsapiens", "grch38", true);
41+
Assert.assertEquals("v6.7", c.getVersion());
42+
Assert.assertNotNull(c.getDataRelease());
3443
}
3544

3645
@Test

opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/metadata/models/ProjectMetadata.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ public int hashCode() {
262262
public static class VariantAnnotatorProgram {
263263
private String name;
264264
private String version;
265+
// TODO: Add clientVersion;
265266
private String commit;
266267

267268
public VariantAnnotatorProgram() {

opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/variant/adaptors/VariantField.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ public enum VariantField {
8383
ANNOTATION_REPEAT(ANNOTATION, "annotation.repeat"),
8484
ANNOTATION_DRUGS(ANNOTATION, "annotation.drugs"),
8585
ANNOTATION_ADDITIONAL_ATTRIBUTES(ANNOTATION, "annotation.additionalAttributes"),
86-
ANNOTATION_GENOMIC_SEQUENCE_CONTEXT(ANNOTATION, "annotation.genomicSequenceContext");
86+
ANNOTATION_GENOMIC_SEQUENCE_CONTEXT(ANNOTATION, "annotation.genomicSequenceContext"),
87+
ANNOTATION_GENE_IMPRINTING(ANNOTATION, "annotation.geneImprinting"),
88+
ANNOTATION_GENE_FUSIONS(ANNOTATION, "annotation.geneFusions"),
89+
ANNOTATION_POLYGENIC_SCORES(ANNOTATION, "annotation.polygenicScores");
8790

8891
private static final Set<VariantField> ALL_FIELDS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(values())));
8992

opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/variant/annotation/VariantAnnotationManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ protected final VariantAnnotationMetadata checkCurrentAnnotation(ProjectMetadata
222222
}
223223

224224
/**
225-
* Check if two DataRelease are equal.
225+
* Check if two data releases are equal.
226226
*
227227
* Fields to compare:
228228
* - release
@@ -234,9 +234,9 @@ protected final VariantAnnotationMetadata checkCurrentAnnotation(ProjectMetadata
234234
* - active
235235
* - activeByDefaultIn
236236
*
237-
* @param current Current DataRelease
238-
* @param other Other DataRelease
239-
* @return true if both DataRelease are equal
237+
* @param current Current data release
238+
* @param other Other data release
239+
* @return true if both data release are equal
240240
*/
241241
public static boolean dataReleaseEquals(DataRelease current, DataRelease other) {
242242
return current.getRelease() == other.getRelease()

opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/variant/annotation/annotators/CellBaseRestVariantAnnotator.java

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import org.opencb.commons.datastore.core.Event;
2828
import org.opencb.commons.datastore.core.ObjectMap;
2929
import org.opencb.commons.datastore.core.QueryOptions;
30+
import org.opencb.commons.utils.VersionUtils;
31+
import org.opencb.opencga.core.common.DependenciesState;
3032
import org.opencb.opencga.core.config.storage.StorageConfiguration;
3133
import org.opencb.opencga.storage.core.metadata.models.ProjectMetadata;
3234
import org.opencb.opencga.storage.core.utils.CellBaseUtils;
@@ -46,6 +48,7 @@ public class CellBaseRestVariantAnnotator extends AbstractCellBaseVariantAnnotat
4648

4749
private final CellBaseClient cellBaseClient;
4850
private final CellBaseUtils cellBaseUtils;
51+
private ProjectMetadata.VariantAnnotatorProgram variantAnnotatorProgram;
4952

5053
public CellBaseRestVariantAnnotator(StorageConfiguration storageConfiguration, ProjectMetadata projectMetadata, ObjectMap options)
5154
throws VariantAnnotatorException {
@@ -74,6 +77,34 @@ public CellBaseRestVariantAnnotator(StorageConfiguration storageConfiguration, P
7477
throw new VariantAnnotatorException(e.getMessage(), e);
7578
}
7679

80+
logger.info("CellBase client version: {}", DependenciesState.getInstance().getCellBaseVersion());
81+
ProjectMetadata.VariantAnnotatorProgram program = getVariantAnnotatorProgram();
82+
logger.info("CellBase server version: {} commit: {}",
83+
program.getVersion(),
84+
program.getCommit());
85+
86+
VersionUtils.Version serverCellbaseVersion = new VersionUtils.Version(program.getVersion());
87+
VersionUtils.Version cellbaseClientVersion = new VersionUtils.Version(DependenciesState.getInstance().getCellBaseVersion());
88+
89+
// If server version is ahead of client version, warn the user
90+
if (serverCellbaseVersion.compareTo(cellbaseClientVersion) > 0) {
91+
logger.warn("CellBase server version '{}' is more recent than CellBase client version '{}'. "
92+
+ "It is recommended to update the CellBase client library to avoid compatibility issues.",
93+
serverCellbaseVersion, cellbaseClientVersion);
94+
}
95+
}
96+
97+
public static void main(String[] args) {
98+
99+
VersionUtils.Version serverCellbaseVersion = new VersionUtils.Version("6.7.0");
100+
VersionUtils.Version cellbaseClientVersion = new VersionUtils.Version("6.6.0");
101+
102+
// If server version is ahead of client version, warn the user
103+
if (serverCellbaseVersion.compareTo(cellbaseClientVersion, true) > 0) {
104+
logger.warn("CellBase server version '{}' is more recent than CellBase client version '{}'. "
105+
+ "It is recommended to update the CellBase client library to avoid compatibility issues.",
106+
serverCellbaseVersion, cellbaseClientVersion);
107+
}
77108
}
78109

79110
@Override
@@ -88,26 +119,36 @@ protected List<CellBaseDataResult<VariantAnnotation>> annotateFiltered(List<Vari
88119
.getAnnotationByVariantIds(variantIds, new QueryOptions(queryOptions), true);
89120
return response.getResponses();
90121
} catch (IOException e) {
91-
throw new VariantAnnotatorException("Error fetching variants from " + getDebugInfo("/genomic/variant/annotation"));
122+
throw new VariantAnnotatorException("Error fetching variants from " + getDebugInfo("/genomic/variant/annotation"), e);
92123
}
93124
}
94125

95126
@Override
96127
public ProjectMetadata.VariantAnnotationMetadata getVariantAnnotationMetadata() throws VariantAnnotatorException {
97128
DataRelease dataRelease = null;
129+
String url = "/meta/" + species + "/dataReleases";
98130
try {
99131
if (cellBaseUtils.supportsDataRelease()) {
132+
// if (cellBaseUtils.supportsRelease()) {
133+
// url = "/meta/" + species + "/releases";
134+
// Release dr = cellBaseClient.getMetaClient()
135+
// .releases()
136+
// .allResults()
137+
// .stream()
138+
// .filter(r -> String.valueOf(r.getRelease()).equals(cellBaseClient.getDataRelease()))
139+
// .findFirst()
140+
// .orElse(null);
141+
// }
100142
dataRelease = cellBaseClient.getMetaClient()
101143
.dataReleases()
102144
.allResults()
103145
.stream()
104-
.filter(dr -> String.valueOf(dr.getRelease()).equals(cellBaseClient.getDataRelease()))
146+
.filter(r -> String.valueOf(r.getRelease()).equals(cellBaseClient.getDataRelease()))
105147
.findFirst()
106148
.orElse(null);
107149
}
108150
} catch (IOException e) {
109-
throw new VariantAnnotatorException("Error fetching CellBase information from "
110-
+ getDebugInfo("/meta/" + species + "/dataReleases") + ". ");
151+
throw new VariantAnnotatorException("Error fetching CellBase information from " + getDebugInfo(url) + ". ", e);
111152
}
112153
List<String> privateSources;
113154
if (StringUtils.isNotEmpty(cellBaseUtils.getApiKey())) {
@@ -124,6 +165,13 @@ public ProjectMetadata.VariantAnnotationMetadata getVariantAnnotationMetadata()
124165
}
125166

126167
private ProjectMetadata.VariantAnnotatorProgram getVariantAnnotatorProgram() throws VariantAnnotatorException {
168+
if (variantAnnotatorProgram == null) {
169+
variantAnnotatorProgram = fetchVariantAnnotatorProgram();
170+
}
171+
return variantAnnotatorProgram;
172+
}
173+
174+
private ProjectMetadata.VariantAnnotatorProgram fetchVariantAnnotatorProgram() throws VariantAnnotatorException {
127175
CellBaseDataResponse<ObjectMap> response;
128176
try {
129177
response = cellBaseClient.getMetaClient().about();
@@ -167,7 +215,7 @@ private List<ObjectMap> getVariantAnnotatorSourceVersion() throws VariantAnnotat
167215
if (event != null) {
168216
throw new VariantAnnotatorException(
169217
"Error fetching CellBase source information from " + getDebugInfo("/meta/versions") + ". "
170-
+ event.getName() + " : " + event.getMessage());
218+
+ event.getName() + " : " + event.getMessage());
171219
}
172220
List<ObjectMap> objectMaps = new ArrayList<>();
173221
if (response.getResponses() != null) {

opencga-storage/opencga-storage-core/src/test/java/org/opencb/opencga/storage/core/variant/annotation/VariantAnnotationManagerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ public void checkAnnotationSnapshot(VariantStorageEngine variantStorageEngine, S
600600
int count = 0;
601601
for (VariantAnnotation annotation: variantStorageEngine.getAnnotation(annotationName, query, new QueryOptions(QueryOptions.LIMIT, 5000)).getResults()) {
602602
assertEquals("an id -- " + expectedId, annotation.getId());
603-
// assertEquals("1", annotation.getAdditionalAttributes().get("opencga").getAttribute().get("release"));
603+
// assertEquals("1", annotation.getAdditionalAttributes().get("opencga").getAttribute().getRelease());
604604
assertEquals(expectedAnnotationName, annotation.getAdditionalAttributes().get(GROUP_NAME.key())
605605
.getAttribute().get(VariantField.AdditionalAttributes.ANNOTATION_ID.key()));
606606
count++;

0 commit comments

Comments
 (0)