public QueryResult<Sample> removeAnnotationSets(String studyStr, String sampleStr, List<String> annotationSetIdList, QueryOptions options, String token) throws CatalogException { List<AnnotationSet> annotationSetList = annotationSetIdList .stream() .map(id -> new AnnotationSet().setId(id)) .collect(Collectors.toList()); return updateAnnotationSet(studyStr, sampleStr, annotationSetList, ParamUtils.UpdateAction.REMOVE, options, token); }
public QueryResult<Individual> removeAnnotationSets(String studyStr, String individualStr, List<String> annotationSetIdList, QueryOptions options, String token) throws CatalogException { List<AnnotationSet> annotationSetList = annotationSetIdList .stream() .map(id -> new AnnotationSet().setId(id)) .collect(Collectors.toList()); return updateAnnotationSet(studyStr, individualStr, annotationSetList, ParamUtils.UpdateAction.REMOVE, options, token); }
public QueryResult<Family> removeAnnotationSets(String studyStr, String familyStr, List<String> annotationSetIdList, QueryOptions options, String token) throws CatalogException { List<AnnotationSet> annotationSetList = annotationSetIdList .stream() .map(id -> new AnnotationSet().setId(id)) .collect(Collectors.toList()); return updateAnnotationSet(studyStr, familyStr, annotationSetList, ParamUtils.UpdateAction.REMOVE, options, token); }
public QueryResult<Cohort> removeAnnotationSets(String studyStr, String cohortStr, List<String> annotationSetIdList, QueryOptions options, String token) throws CatalogException { List<AnnotationSet> annotationSetList = annotationSetIdList .stream() .map(id -> new AnnotationSet().setId(id)) .collect(Collectors.toList()); return updateAnnotationSet(studyStr, cohortStr, annotationSetList, ParamUtils.UpdateAction.REMOVE, options, token); }
public QueryResult<Sample> updateAnnotations(String studyStr, String sampleStr, String annotationSetId, Map<String, Object> annotations, ParamUtils.CompleteUpdateAction action, QueryOptions options, String token) throws CatalogException { if (annotations == null || annotations.isEmpty()) { return new QueryResult<>(sampleStr, -1, -1, -1, "Nothing to do: The map of annotations is empty", "", Collections.emptyList()); } ObjectMap params = new ObjectMap(AnnotationSetManager.ANNOTATIONS, new AnnotationSet(annotationSetId, "", annotations)); options = ParamUtils.defaultObject(options, QueryOptions::new); options.put(Constants.ACTIONS, new ObjectMap(AnnotationSetManager.ANNOTATIONS, action)); return update(studyStr, sampleStr, params, options, token); }
public QueryResult<Individual> updateAnnotations(String studyStr, String individualStr, String annotationSetId, Map<String, Object> annotations, ParamUtils.CompleteUpdateAction action, QueryOptions options, String token) throws CatalogException { if (annotations == null || annotations.isEmpty()) { return new QueryResult<>(individualStr, -1, -1, -1, "Nothing to do: The map of annotations is empty", "", Collections.emptyList()); } ObjectMap params = new ObjectMap(AnnotationSetManager.ANNOTATIONS, new AnnotationSet(annotationSetId, "", annotations)); options = ParamUtils.defaultObject(options, QueryOptions::new); options.put(Constants.ACTIONS, new ObjectMap(AnnotationSetManager.ANNOTATIONS, action)); return update(studyStr, individualStr, params, options, token); }
public QueryResult<Family> updateAnnotations(String studyStr, String familyStr, String annotationSetId, Map<String, Object> annotations, ParamUtils.CompleteUpdateAction action, QueryOptions options, String token) throws CatalogException { if (annotations == null || annotations.isEmpty()) { return new QueryResult<>(familyStr, -1, -1, -1, "Nothing to do: The map of annotations is empty", "", Collections.emptyList()); } ObjectMap params = new ObjectMap(AnnotationSetManager.ANNOTATIONS, new AnnotationSet(annotationSetId, "", annotations)); options = ParamUtils.defaultObject(options, QueryOptions::new); options.put(Constants.ACTIONS, new ObjectMap(AnnotationSetManager.ANNOTATIONS, action)); return update(studyStr, familyStr, params, options, token); }
public QueryResult<File> updateAnnotations(String studyStr, String fileStr, String annotationSetId, Map<String, Object> annotations, ParamUtils.CompleteUpdateAction action, QueryOptions options, String token) throws CatalogException { if (annotations == null || annotations.isEmpty()) { return new QueryResult<>(fileStr, -1, -1, -1, "Nothing to do: The map of annotations is empty", "", Collections.emptyList()); } ObjectMap params = new ObjectMap(AnnotationSetManager.ANNOTATIONS, new AnnotationSet(annotationSetId, "", annotations)); options = ParamUtils.defaultObject(options, QueryOptions::new); options.put(Constants.ACTIONS, new ObjectMap(AnnotationSetManager.ANNOTATIONS, action)); return update(studyStr, fileStr, params, options, token); }
public QueryResult<Cohort> updateAnnotations(String studyStr, String cohortStr, String annotationSetId, Map<String, Object> annotations, ParamUtils.CompleteUpdateAction action, QueryOptions options, String token) throws CatalogException { if (annotations == null || annotations.isEmpty()) { return new QueryResult<>(cohortStr, -1, -1, -1, "Nothing to do: The map of annotations is empty", "", Collections.emptyList()); } ObjectMap params = new ObjectMap(AnnotationSetManager.ANNOTATIONS, new AnnotationSet(annotationSetId, "", annotations)); options = ParamUtils.defaultObject(options, QueryOptions::new); options.put(Constants.ACTIONS, new ObjectMap(AnnotationSetManager.ANNOTATIONS, action)); return update(studyStr, cohortStr, params, options, token); }
/** * Deletes the annotation set. * * @param id id of the entity storing the annotation. * @param studyStr study string. * @param annotationSetName annotation set name of the annotation to be deleted. * @param sessionId session id of the user asking for the annotation. * @return a queryResult object with the annotationSet that has been deleted. * @throws CatalogException when the session id is not valid, the user does not have permissions to delete the annotationSet or * the annotation set name is not valid. */ @Deprecated public QueryResult<AnnotationSet> deleteAnnotationSet(String id, @Nullable String studyStr, String annotationSetName, String sessionId) throws CatalogException { if (StringUtils.isEmpty(annotationSetName)) { throw new CatalogException("Missing annotationSetName field"); } ObjectMap params = new ObjectMap(AnnotationSetManager.ANNOTATION_SETS, Collections.singleton(new AnnotationSet().setId(annotationSetName))); QueryOptions options = new QueryOptions(Constants.ACTIONS, new ObjectMap(AnnotationSetManager.ANNOTATION_SETS, ParamUtils.UpdateAction.REMOVE)); QueryResult<R> update = update(studyStr, id, params, options, sessionId); return new QueryResult<>("Delete annotationSet", update.getDbTime(), 0, 0, update.getWarningMsg(), update.getErrorMsg(), Collections.emptyList()); }
/** * Deletes (or puts to the default value if mandatory) a list of annotations from the annotation set. * * @param id id of the entity storing the annotation. * @param studyStr study string. * @param annotationSetName annotation set name of the annotation where the update will be made. * @param annotations comma separated list of annotation names that will be deleted or updated to the default values. * @param sessionId session id of the user asking for the annotation. * @return a queryResult object with the annotation set after applying the changes. * @throws CatalogException when the session id is not valid, the user does not have permissions to delete the annotationSet, * the annotation set name is not valid or any of the annotation names are not valid. */ @Deprecated public QueryResult<AnnotationSet> deleteAnnotations(String id, @Nullable String studyStr, String annotationSetName, String annotations, String sessionId) throws CatalogException { if (StringUtils.isEmpty(annotations)) { throw new CatalogException("Missing annotations field"); } if (StringUtils.isEmpty(annotationSetName)) { throw new CatalogException("Missing annotationSetName field"); } ObjectMap params = new ObjectMap(AnnotationSetManager.ANNOTATIONS, new AnnotationSet(annotationSetName, "", new ObjectMap("remove", annotations))); QueryOptions options = new QueryOptions(); options.put(Constants.ACTIONS, new ObjectMap(AnnotationSetManager.ANNOTATIONS, ParamUtils.CompleteUpdateAction.REMOVE)); QueryResult<R> update = update(studyStr, id, params, new QueryOptions(), sessionId); return new QueryResult<>("Delete annotation", update.getDbTime(), 0, 0, update.getWarningMsg(), update.getErrorMsg(), Collections.emptyList()); }
private void validate(Pedigree pedigree, VariableSet variableSet) throws CatalogException { for (Map.Entry<String, Individual> entry : pedigree.getIndividuals().entrySet()) { Map<String, Object> annotation = loader.getAnnotation(entry.getValue(), null, variableSet, pedigree.getFields()); AnnotationUtils.checkAnnotationSet(variableSet, new AnnotationSet("", variableSet.getId(), annotation, "", 1, null), null, true); } } }
@Test public void mergeAnnotationsTest() { Map<String, Object> annotations = new HashMap<>(); annotations.put("K", "V"); annotations.put("K2", "V2"); annotations.put("K4", false); AnnotationSet annotationSet = new AnnotationSet("", "", annotations, "", 1, Collections.emptyMap()); Map<String, Object> newAnnotations = new ObjectMap() .append("K", "newValue") //Modify .append("K2", null) //Delete .append("K3", "newAnnotation"); //Add AnnotationUtils.mergeNewAnnotations(annotationSet, newAnnotations); Map<String, Object> newAnnotation = annotationSet.getAnnotations(); Assert.assertEquals(4, newAnnotation.size()); Assert.assertEquals("newValue", newAnnotation.get("K")); Assert.assertEquals(null, newAnnotation.get("K2")); Assert.assertEquals("newAnnotation", newAnnotation.get("K3")); Assert.assertEquals(false, newAnnotation.get("K4")); }
Map objectMap = (Map) object; checkAnnotationSet(new VariableSet(variable.getId(), variable.getId(), false, false, variable.getDescription(), variable.getVariableSet(), 1, null), new AnnotationSet("", variable.getId(), objectMap, null, 1, null), null, true);
Map<String, Object> newAnnotations, String sessionId) throws CatalogException { MyResource resource = getUid(id, studyStr, sessionId); AnnotationSet annotationSet = new AnnotationSet(annotationSetName, null, newAnnotations, Collections.emptyMap()); ObjectMap parameters; ObjectMapper jsonObjectMapper = getDefaultObjectMapper();
Map<String, Object> annotation = getAnnotation(individual, sampleMap, variableSet, ped.getFields()); try { AnnotationUtils.checkAnnotationSet(variableSet, new AnnotationSet("", variableSet.getId(), annotation, "", 1, null), null, true); } catch (CatalogException e) {
@Test public void testAnnotations() throws CatalogException, JsonProcessingException { List<Variable> variables = new ArrayList<>(); variables.add(new Variable("var_name", "", "", Variable.VariableType.TEXT, "", true, false, Collections.emptyList(), 0, "", "", null, Collections.emptyMap())); variables.add(new Variable("AGE", "", "", Variable.VariableType.INTEGER, "", false, false, Collections.emptyList(), 0, "", "", null, Collections.emptyMap())); variables.add(new Variable("HEIGHT", "", "", Variable.VariableType.DOUBLE, "", false, false, Collections.emptyList(), 0, "", "", null, Collections.emptyMap())); VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", false, false, "", null, variables, sessionIdUser).first(); ObjectMap annotations = new ObjectMap() .append("var_name", "Joe") .append("AGE", 25) .append("HEIGHT", 180); AnnotationSet annotationSet = new AnnotationSet("annotation1", vs1.getId(), annotations); AnnotationSet annotationSet1 = new AnnotationSet("annotation2", vs1.getId(), annotations); ObjectMapper jsonObjectMapper = getDefaultObjectMapper(); ObjectMap updateAnnotation = new ObjectMap() // Update the annotation values .append(FileDBAdaptor.QueryParams.ANNOTATION_SETS.key(), Arrays.asList( new ObjectMap(jsonObjectMapper.writeValueAsString(annotationSet)), new ObjectMap(jsonObjectMapper.writeValueAsString(annotationSet1)) )); QueryResult<File> update = catalogManager.getFileManager().update(studyFqn, "data/", updateAnnotation, QueryOptions.empty(), sessionIdUser); assertEquals(2, update.first().getAnnotationSets().size()); }
.append("AGE", 25) .append("HEIGHT", 180); AnnotationSet annotationSet = new AnnotationSet("annotation1", vs1.getId(), annotations); AnnotationSet annotationSet1 = new AnnotationSet("annotation2", vs1.getId(), annotations);
.append("AGE", 25) .append("HEIGHT", 180); AnnotationSet annotationSet = new AnnotationSet("annotation1", vs1.getId(), annotations);
sample.setAnnotationSets(Collections.singletonList(new AnnotationSet("annot1", vs.getId(), new ObjectMap("NAME", "s_1").append("AGE", 6).append("ALIVE", true).append("PHEN", "CONTROL")))); s_1 = catalogManager.getSampleManager().create(studyFqn, sample, new QueryOptions(), sessionIdUser).first().getId(); sample.setAnnotationSets(Collections.singletonList(new AnnotationSet("annot1", vs.getId(), new ObjectMap("NAME", "s_2").append("AGE", 10).append("ALIVE", false).append("PHEN", "CASE")))); s_2 = catalogManager.getSampleManager().create(studyFqn, sample, new QueryOptions(), sessionIdUser).first().getId(); sample.setAnnotationSets(Collections.singletonList(new AnnotationSet("annot1", vs.getId(), new ObjectMap("NAME", "s_3").append("AGE", 15).append("ALIVE", true).append("PHEN", "CONTROL")))); s_3 = catalogManager.getSampleManager().create(studyFqn, sample, new QueryOptions(), sessionIdUser).first().getId(); sample.setAnnotationSets(Collections.singletonList(new AnnotationSet("annot1", vs.getId(), new ObjectMap("NAME", "s_4").append("AGE", 22).append("ALIVE", false).append("PHEN", "CONTROL")))); s_4 = catalogManager.getSampleManager().create(studyFqn, sample, new QueryOptions(), sessionIdUser).first().getId(); sample.setAnnotationSets(Collections.singletonList(new AnnotationSet("annot1", vs.getId(), new ObjectMap("NAME", "s_5").append("AGE", 29).append("ALIVE", true).append("PHEN", "CASE")))); s_5 = catalogManager.getSampleManager().create(studyFqn, sample, new QueryOptions(), sessionIdUser).first().getId(); sample.setAnnotationSets(Collections.singletonList(new AnnotationSet("annot2", vs.getId(), new ObjectMap("NAME", "s_6").append("AGE", 38).append("ALIVE", true).append("PHEN", "CONTROL")))); s_6 = catalogManager.getSampleManager().create(studyFqn, sample, new QueryOptions(), sessionIdUser).first().getId(); sample.setAnnotationSets(Collections.singletonList(new AnnotationSet("annot2", vs.getId(), new ObjectMap("NAME", "s_7").append("AGE", 46).append("ALIVE", false).append("PHEN", "CASE")))); s_7 = catalogManager.getSampleManager().create(studyFqn, sample, new QueryOptions(), sessionIdUser).first().getId(); sample.setAnnotationSets(Collections.singletonList(new AnnotationSet("annot2", vs.getId(),