Skip to content

Commit 7d0c668

Browse files
Merge branch 'release-3.x.x' into TASK-7531
2 parents bef975b + 84feed6 commit 7d0c668

16 files changed

Lines changed: 393 additions & 165 deletions

File tree

opencga-core/src/main/java/org/opencb/opencga/core/common/JacksonUtils.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818

1919
import com.fasterxml.jackson.annotation.JsonInclude;
2020
import com.fasterxml.jackson.core.JsonFactory;
21+
import com.fasterxml.jackson.databind.BeanDescription;
2122
import com.fasterxml.jackson.databind.DeserializationFeature;
2223
import com.fasterxml.jackson.databind.MapperFeature;
2324
import com.fasterxml.jackson.databind.ObjectMapper;
25+
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
2426
import com.fasterxml.jackson.databind.util.TokenBuffer;
2527
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
2628
import org.apache.avro.generic.GenericRecord;
@@ -49,6 +51,8 @@
4951
import javax.ws.rs.ext.ContextResolver;
5052
import java.io.IOException;
5153
import java.io.UncheckedIOException;
54+
import java.util.HashMap;
55+
import java.util.Map;
5256

5357
public class JacksonUtils {
5458

@@ -202,6 +206,13 @@ public static <T> T copySafe(T instance, Class<T> clazz) {
202206
}
203207
}
204208

209+
public static <T> T copy(T instance) throws IOException {
210+
if (instance == null) {
211+
return null;
212+
}
213+
return copy(instance, (Class<T>) instance.getClass());
214+
}
215+
205216
public static <T> T copy(T instance, Class<T> clazz) throws IOException {
206217
if (instance == null) {
207218
return null;
@@ -226,4 +237,18 @@ public static <T> void update(T valueToUpdate, Object overrides) throws IOExcept
226237
defaultObjectMapper.updateValue(valueToUpdate, overrides);
227238
}
228239

240+
public static Map<String, Class<?>> getFields(Class<?> aClass) {
241+
return getFields(aClass, getDefaultObjectMapper());
242+
}
243+
244+
public static Map<String, Class<?>> getFields(Class<?> aClass, ObjectMapper objectMapper) {
245+
BeanDescription beanDescription = objectMapper.getSerializationConfig().introspect(objectMapper.constructType(aClass));
246+
Map<String, Class<?>> fields = new HashMap<>(beanDescription.findProperties().size());
247+
for (BeanPropertyDefinition property : beanDescription.findProperties()) {
248+
Class<?> rawPrimaryType = property.getRawPrimaryType();
249+
fields.put(property.getName(), rawPrimaryType);
250+
}
251+
return fields;
252+
}
253+
229254
}

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.apache.commons.lang3.builder.ToStringStyle;
55
import org.opencb.cellbase.core.models.DataRelease;
66
import org.opencb.commons.datastore.core.ObjectMap;
7+
import org.opencb.opencga.core.common.JacksonUtils;
78
import org.opencb.opencga.storage.core.variant.adaptors.VariantQueryException;
89

910
import java.util.*;
@@ -40,6 +41,14 @@ public VariantAnnotationSets(VariantAnnotationMetadata current, List<VariantAnno
4041
this.saved = saved;
4142
}
4243

44+
public VariantAnnotationSets(VariantAnnotationSets other) {
45+
this.current = other.current == null ? null : new VariantAnnotationMetadata(other.current);
46+
this.saved = new ArrayList<>(other.saved.size());
47+
for (VariantAnnotationMetadata saved : other.saved) {
48+
this.saved.add(new VariantAnnotationMetadata(saved));
49+
}
50+
}
51+
4352
public VariantAnnotationMetadata getCurrent() {
4453
return current;
4554
}
@@ -114,6 +123,19 @@ public VariantAnnotationMetadata(int id, String name, Date creationDate, Variant
114123
this.privateSources = privateSources;
115124
}
116125

126+
public VariantAnnotationMetadata(VariantAnnotationMetadata other) {
127+
this.id = other.id;
128+
this.name = other.name;
129+
this.creationDate = other.creationDate;
130+
this.annotator = other.annotator;
131+
this.sourceVersion = new ArrayList<>(other.sourceVersion.size());
132+
for (ObjectMap source : other.sourceVersion) {
133+
this.sourceVersion.add(new ObjectMap(source));
134+
}
135+
this.dataRelease = other.dataRelease == null ? null : JacksonUtils.copySafe(other.dataRelease, DataRelease.class);
136+
this.privateSources = other.privateSources != null ? new ArrayList<>(other.privateSources) : null;
137+
}
138+
117139
public int getId() {
118140
return id;
119141
}
@@ -293,9 +315,18 @@ public ProjectMetadata(String species, String assembly, String dataRelease, int
293315
this.counters = counters != null ? counters : new HashMap<>();
294316
}
295317

318+
public ProjectMetadata(ProjectMetadata other) {
319+
this.species = other.species;
320+
this.assembly = other.assembly;
321+
this.dataRelease = other.dataRelease;
322+
this.release = other.release;
323+
this.attributes = other.attributes != null ? new ObjectMap(other.attributes) : new ObjectMap();
324+
this.annotation = other.annotation != null ? new VariantAnnotationSets(other.annotation) : new VariantAnnotationSets();
325+
this.counters = other.counters != null ? new HashMap<>(other.counters) : new HashMap<>();
326+
}
327+
296328
public ProjectMetadata copy() {
297-
return new ProjectMetadata(species, assembly, dataRelease, release, new ObjectMap(attributes), new HashMap<>(counters),
298-
annotation);
329+
return new ProjectMetadata(this);
299330
}
300331

301332
public String getSpecies() {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ public void deleteAnnotation(String name, ObjectMap params) throws StorageEngine
474474
newVariantAnnotationManager(params).deleteAnnotation(name, params);
475475
}
476476

477+
public DataResult<VariantAnnotation> getAnnotation(Query query, QueryOptions options) throws StorageEngineException {
478+
options = addDefaultLimit(options, getOptions());
479+
return getDBAdaptor().getAnnotation(VariantAnnotationManager.CURRENT, query, options);
480+
}
481+
477482
public DataResult<VariantAnnotation> getAnnotation(String name, Query query, QueryOptions options) throws StorageEngineException {
478483
options = addDefaultLimit(options, getOptions());
479484
return getDBAdaptor().getAnnotation(name, query, options);

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.commons.collections4.CollectionUtils;
2020
import org.apache.commons.lang3.StringUtils;
21+
import org.opencb.cellbase.core.models.DataRelease;
2122
import org.opencb.commons.datastore.core.ObjectMap;
2223
import org.opencb.commons.datastore.core.Query;
2324
import org.opencb.opencga.storage.core.exceptions.StorageEngineException;
@@ -153,7 +154,7 @@ protected final VariantAnnotationMetadata checkCurrentAnnotation(ProjectMetadata
153154
if (current.getDataRelease() == null) {
154155
// Missing current dataRelease. Continue.
155156
} else {
156-
if (!current.getDataRelease().equals(newVariantAnnotationMetadata.getDataRelease())) {
157+
if (!dataReleaseEquals(current.getDataRelease(), newVariantAnnotationMetadata.getDataRelease())) {
157158
String msg = "DataRelease has changed. "
158159
+ "Existing annotation calculated with dataRelease " + current.getDataRelease().getRelease()
159160
+ ", attempting to annotate with " + newVariantAnnotationMetadata.getDataRelease().getRelease();
@@ -194,6 +195,30 @@ protected final VariantAnnotationMetadata checkCurrentAnnotation(ProjectMetadata
194195
return current;
195196
}
196197

198+
/**
199+
* Check if two DataRelease are equal.
200+
*
201+
* Fields to compare:
202+
* - release
203+
* - date
204+
* - collections
205+
* - sources
206+
*
207+
* Ignored fields:
208+
* - active
209+
* - activeByDefaultIn
210+
*
211+
* @param current Current DataRelease
212+
* @param other Other DataRelease
213+
* @return true if both DataRelease are equal
214+
*/
215+
public static boolean dataReleaseEquals(DataRelease current, DataRelease other) {
216+
return current.getRelease() == other.getRelease()
217+
&& Objects.equals(current.getDate(), other.getDate())
218+
&& Objects.equals(current.getCollections(), other.getCollections())
219+
&& Objects.equals(current.getSources(), other.getSources());
220+
}
221+
197222
private static String removePatchFromVersion(String version) {
198223
String[] split = StringUtils.split(version, '.');
199224
if (split.length <= 1) {

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ public abstract class VariantStorageBaseTest extends GenericTest implements Vari
116116
protected static URI corruptedInputUri;
117117

118118
public static final String ANNOTATOR_EXTENSION_VCF_TEST_FILE_NAME = "variant-test-file-annotator-extension.vcf.gz";
119-
protected static URI annotatorExtensionInputUri;
120119

121120
protected static URI outputUri;
122121
protected VariantStorageEngine variantStorageEngine;
@@ -146,20 +145,16 @@ public static void _beforeClass() throws Exception {
146145
Path inputPath = rootDir.resolve(VCF_TEST_FILE_NAME);
147146
Path smallInputPath = rootDir.resolve(SMALL_VCF_TEST_FILE_NAME);
148147
Path corruptedInputPath = rootDir.resolve(VCF_CORRUPTED_FILE_NAME);
149-
Path annotatorExtensionInputPath = rootDir.resolve(ANNOTATOR_EXTENSION_VCF_TEST_FILE_NAME);
150148
Files.copy(VariantStorageEngineTest.class.getClassLoader().getResourceAsStream(VCF_TEST_FILE_NAME), inputPath,
151149
StandardCopyOption.REPLACE_EXISTING);
152150
Files.copy(VariantStorageEngineTest.class.getClassLoader().getResourceAsStream(SMALL_VCF_TEST_FILE_NAME), smallInputPath,
153151
StandardCopyOption.REPLACE_EXISTING);
154152
Files.copy(VariantStorageEngineTest.class.getClassLoader().getResourceAsStream(VCF_CORRUPTED_FILE_NAME), corruptedInputPath,
155153
StandardCopyOption.REPLACE_EXISTING);
156-
Files.copy(VariantStorageEngineTest.class.getClassLoader().getResourceAsStream(ANNOTATOR_EXTENSION_VCF_TEST_FILE_NAME),
157-
annotatorExtensionInputPath, StandardCopyOption.REPLACE_EXISTING);
158154

159155
inputUri = inputPath.toUri();
160156
smallInputUri = smallInputPath.toUri();
161157
corruptedInputUri = corruptedInputPath.toUri();
162-
annotatorExtensionInputUri = annotatorExtensionInputPath.toUri();
163158
outputUri = rootDir.toUri();
164159
// logger.info("count: " + count.getAndIncrement());
165160

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.opencb.opencga.storage.core.variant.annotation;
2+
3+
import org.junit.Assume;
4+
import org.junit.experimental.categories.Category;
5+
import org.opencb.opencga.core.testclassification.duration.ShortTests;
6+
import org.opencb.opencga.storage.core.variant.dummy.DummyVariantStorageTest;
7+
8+
9+
@Category(ShortTests.class)
10+
public class DummyVariantAnnotationManagerTest extends VariantAnnotationManagerTest implements DummyVariantStorageTest {
11+
12+
@Override
13+
public void testMultiAnnotations() throws Exception {
14+
Assume.assumeTrue("Multi annotations not supported in DummyVariantStorageEngine", false);
15+
super.testMultiAnnotations();
16+
}
17+
18+
@Override
19+
public void testCosmicAnnotatorExtensionWithCosmicAnnotation() throws Exception {
20+
Assume.assumeTrue("Can not check actual results", false);
21+
super.testCosmicAnnotatorExtensionWithCosmicAnnotation();
22+
}
23+
}

0 commit comments

Comments
 (0)