private QueryResult<VariableSet> createExampleVariableSet(String name, boolean confidential) throws CatalogDBException { Set<Variable> variables = new HashSet<>(); variables.addAll(Arrays.asList( new Variable("NAME", "", Variable.VariableType.TEXT, "", true, false, Collections.<String>emptyList(), 0, "", "", null, Collections.<String, Object>emptyMap()), new Variable("AGE", "", Variable.VariableType.DOUBLE, null, true, false, Collections.singletonList("0:99"), 1, "", "", null, Collections.<String, Object>emptyMap()), new Variable("HEIGHT", "", Variable.VariableType.DOUBLE, "1.5", false, false, Collections.singletonList("0:"), 2, "", "", null, Collections.<String, Object>emptyMap()), new Variable("ALIVE", "", Variable.VariableType.BOOLEAN, "", true, false, Collections.<String>emptyList(), 3, "", "", null, Collections.<String, Object>emptyMap()), new Variable("PHEN", "", Variable.VariableType.CATEGORICAL, "", true, false, Arrays.asList("CASE", "CONTROL"), 4, "", "", null, Collections.<String, Object>emptyMap()) )); VariableSet variableSet = new VariableSet(name, name, false, confidential, "My description", variables, 1, Collections.emptyMap()); return catalogStudyDBAdaptor.createVariableSet(5L, variableSet); }
@Test public void testLoadPedigree_GivenVariableSet() throws Exception { HashSet<Variable> variables = new HashSet<>(); variables.add(new Variable("id", "", Variable.VariableType.DOUBLE, null, true, false, Collections.<String>emptyList(), 0, null, "", null, null)); variables.add(new Variable("name", "", Variable.VariableType.TEXT, null, true, false, Collections.<String>emptyList(), 0, null, "", null, null)); variables.add(new Variable("fatherId", "", Variable.VariableType.DOUBLE, null, false, false, Collections.<String>emptyList(), 0, null, "", null, null)); variables.add(new Variable("Population", "", Variable.VariableType.CATEGORICAL, null, true, false, populations, 0, null, "", null, null)); variables.add(new Variable("NonExistingField", "", Variable.VariableType.DOUBLE, "", false, false, Collections.emptyList(), 0, null, "", null, null)); VariableSet variableSet = new VariableSet("", "", false, false, "", variables, 1, null); validate(pedigree, variableSet); }
@Test public void testCreateRepeatedVariableSet() throws CatalogException { Study study = catalogManager.getStudyManager().get("user@1000G:phase1", null, sessionIdUser).first(); List<Variable> variables = Arrays.asList( new Variable("NAME", "", Variable.VariableType.TEXT, "", true, false, Collections.<String>emptyList(), 0, "", "", null, Collections.<String, Object>emptyMap()), new Variable("NAME", "", Variable.VariableType.BOOLEAN, "", true, false, Collections.<String>emptyList(), 3, "", "", null, Collections.<String, Object>emptyMap()), new Variable("AGE", "", Variable.VariableType.DOUBLE, null, true, false, Collections.singletonList("0:99"), 1, "", "", null, Collections.<String, Object>emptyMap()), new Variable("HEIGHT", "", Variable.VariableType.DOUBLE, "1.5", false, false, Collections.singletonList("0:"), 2, "", "", null, Collections.<String, Object>emptyMap()), new Variable("PHEN", "", Variable.VariableType.CATEGORICAL, "", true, false, Arrays.asList("CASE", "CONTROL"), 4, "", "", null, Collections.<String, Object>emptyMap()) ); thrown.expect(CatalogException.class); catalogManager.getStudyManager().createVariableSet(study.getFqn(), "vs1", "vs1", true, false, "", null, variables, sessionIdUser); }
/** * VariableSet methods * *************************** */ @Test public void testCreateVariableSet() throws CatalogException { Study study = catalogManager.getStudyManager().get("user@1000G:phase1", null, sessionIdUser).first(); long variableSetNum = study.getVariableSets().size(); List<Variable> variables = new ArrayList<>(); variables.addAll(Arrays.asList( new Variable("NAME", "", Variable.VariableType.TEXT, "", true, false, Collections.<String>emptyList(), 0, "", "", null, Collections.<String, Object>emptyMap()), new Variable("AGE", "", Variable.VariableType.DOUBLE, null, true, false, Collections.singletonList("0:99"), 1, "", "", null, Collections.<String, Object>emptyMap()), new Variable("HEIGHT", "", Variable.VariableType.DOUBLE, "1.5", false, false, Collections.singletonList("0:"), 2, "", "", null, Collections.<String, Object>emptyMap()), new Variable("ALIVE", "", Variable.VariableType.BOOLEAN, "", true, false, Collections.<String>emptyList(), 3, "", "", null, Collections.<String, Object>emptyMap()), new Variable("PHEN", "", Variable.VariableType.CATEGORICAL, "", true, false, Arrays.asList("CASE", "CONTROL"), 4, "", "", null, Collections.<String, Object>emptyMap()) )); QueryResult<VariableSet> queryResult = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", true, false, "", null, variables, sessionIdUser); assertEquals(1, queryResult.getResult().size()); study = catalogManager.getStudyManager().get(study.getId(), null, sessionIdUser).first(); assertEquals(variableSetNum + 1, study.getVariableSets().size()); }
/** * Tries to add a new variable to a non existent variableSet. * @throws CatalogDBException */ @Test public void addFieldToVariableSetTest2() throws CatalogDBException, CatalogAuthorizationException { Variable variable = new Variable("NAM", "", Variable.VariableType.TEXT, "", true, false, Collections.emptyList(), 0, "", "", null, Collections.emptyMap()); thrown.expect(CatalogDBException.class); thrown.expectMessage("not found"); catalogStudyDBAdaptor.addFieldToVariableSet(18, variable, user3.getId()); }
@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()); }
@Test public void testAnnotate() throws CatalogException { List<Variable> variables = new ArrayList<>(); variables.add(new Variable("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();
@Test public void annotationToDB1() throws Exception { Variable v = new Variable().setId("a").setType(Variable.VariableType.BOOLEAN); Set<Variable> setOfVariables = new HashSet<>(); setOfVariables.add(v); VariableSet variableSet = new VariableSet().setVariables(setOfVariables).setUid(1); Map<String, Object> myMap = new HashMap<>(); myMap.put("b", "nothing"); AnnotationConverter annotableConverter = new AnnotationConverter(); List<Document> document1 = annotableConverter.annotationToDB(variableSet, "annotName", myMap); assertTrue(document1.isEmpty()); myMap.put("a", "hello"); List<Document> document2 = annotableConverter.annotationToDB(variableSet, "annotName", myMap); assertEquals(1, document2.size()); assertEquals(5, document2.get(0).size()); assertEquals("a", document2.get(0).get(AnnotationConverter.ID)); assertEquals("annotName", document2.get(0).get(AnnotationConverter.ANNOTATION_SET_NAME)); assertEquals(1L, document2.get(0).get(AnnotationConverter.VARIABLE_SET)); assertEquals("hello", document2.get(0).get(AnnotationConverter.VALUE)); }
/** * Creates a new variable once and attempts to create the same one again. * @throws CatalogDBException */ @Test public void addFieldToVariableSetTest1() throws CatalogDBException, CatalogAuthorizationException { createExampleVariableSet("VARSET_1", false); createExampleVariableSet("VARSET_2", true); Variable variable = new Variable("NAM", "", Variable.VariableType.TEXT, "", true, false, Collections.emptyList(), 0, "", "", null, Collections.emptyMap()); QueryResult<VariableSet> queryResult = catalogStudyDBAdaptor.addFieldToVariableSet(18, variable, user3.getId()); // Check that the new variable has been inserted in the variableSet assertTrue(queryResult.first().getVariables().stream().filter(variable1 -> variable.getId().equals(variable1.getId())).findAny() .isPresent()); // We try to insert the same one again. thrown.expect(CatalogDBException.class); thrown.expectMessage("already exist"); catalogStudyDBAdaptor.addFieldToVariableSet(18, variable, user3.getId()); }
@Test public void testDeleteVariableSet() throws CatalogException { Study study = catalogManager.getStudyManager().resolveId("1000G:phase1", "user"); List<Variable> variables = Arrays.asList( new Variable("NAME", "", Variable.VariableType.TEXT, "", true, false, Collections.<String>emptyList(), 0, "", "", null, Collections.<String, Object>emptyMap()), new Variable("AGE", "", Variable.VariableType.DOUBLE, null, true, false, Collections.singletonList("0:99"), 1, "", "", null, Collections.<String, Object>emptyMap()) ); VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(study.getFqn(), "vs1", "vs1", true, false, "", null, variables, sessionIdUser).first(); VariableSet vs1_deleted = catalogManager.getStudyManager().deleteVariableSet(studyFqn, Long.toString(vs1.getUid()), sessionIdUser).first(); assertEquals(vs1.getUid(), vs1_deleted.getUid()); thrown.expect(CatalogException.class); //VariableSet does not exist thrown.expectMessage("not found"); catalogManager.getStudyManager().getVariableSet(studyFqn, vs1.getId(), null, sessionIdUser); }
bcSet.add(new Variable().setId("c").setMultiValue(true).setType(Variable.VariableType.BOOLEAN)); Set<Variable> bSet = new HashSet<>(); bSet.add(new Variable().setId("b").setType(Variable.VariableType.OBJECT).setVariableSet(bcSet)); Set<Variable> rootSet = new HashSet<>(); rootSet.add(new Variable().setId("a").setMultiValue(true).setType(Variable.VariableType.OBJECT).setVariableSet(bSet));
bcSet.add(new Variable().setId("c").setType(Variable.VariableType.BOOLEAN)); Set<Variable> bSet = new HashSet<>(); bSet.add(new Variable().setId("b").setMultiValue(true).setType(Variable.VariableType.OBJECT).setVariableSet(bcSet)); Set<Variable> rootSet = new HashSet<>(); rootSet.add(new Variable().setId("a").setMultiValue(true).setType(Variable.VariableType.OBJECT).setVariableSet(bSet));
@Test public void testDeleteAnnotationset() 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,
@Test public void testDeleteVariableSetInUse() throws CatalogException { String sampleId1 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_1"), new QueryOptions(), sessionIdUser).first().getId(); List<Variable> variables = Arrays.asList( new Variable("NAME", "", "", Variable.VariableType.TEXT, "", true, false, Collections.emptyList(), 0, "", "", null, Collections.emptyMap()), new Variable("AGE", "", "", Variable.VariableType.DOUBLE, null, false, false, Collections.singletonList("0:99"), 1, "", "", null, Collections.emptyMap()) ); VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", true, false, "", null, variables, sessionIdUser).first(); Map<String, Object> annotations = new HashMap<>(); annotations.put("NAME", "LINUS"); catalogManager.getSampleManager().update(studyFqn, sampleId1, new ObjectMap() .append(SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key(), Collections.singletonList(new ObjectMap() .append(AnnotationSetManager.ID, "annotationId") .append(AnnotationSetManager.VARIABLE_SET_ID, vs1.getId()) .append(AnnotationSetManager.ANNOTATIONS, annotations)) ), QueryOptions.empty(), sessionIdUser); try { catalogManager.getStudyManager().deleteVariableSet(studyFqn, Long.toString(vs1.getUid()), sessionIdUser).first(); } finally { VariableSet variableSet = catalogManager.getStudyManager().getVariableSet(studyFqn, vs1.getId(), null, sessionIdUser).first(); assertEquals(vs1.getUid(), variableSet.getUid()); thrown.expect(CatalogDBException.class); //Expect the exception from the try } }
variables.add(new Variable("NAME", "NAME", "", Variable.VariableType.TEXT, "", true, false, Collections.emptyList(), 0, "", "", null, Collections.emptyMap())); VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", false, false, "", null, variables,
variables.add(new Variable("NAME", "NAME", "", Variable.VariableType.TEXT, "", true, false, Collections.emptyList(), 0, "", "", null, Collections.emptyMap())); VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", true, false, "", null, variables,
variables.add(new Variable("NAME", "NAME", "", Variable.VariableType.TEXT, "", true, false, Collections.emptyList(), 0, "", "", null, Collections.emptyMap())); VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", true, false, "", null, variables,
new Variable("name", "", "", Variable.VariableType.TEXT, null, true, false, null, 0, null, null, null, null), new Variable("age", "", "", Variable.VariableType.INTEGER, null, true, false, null, 0, null, null, null, null), new Variable("other", "", "", Variable.VariableType.TEXT, "unknown", false, false, null, 0, null, null, null, null)), sessionId);
variables.add(new Variable("NUM", "NUM", "", Variable.VariableType.DOUBLE, "", true, false, null, 0, "", "", null, Collections.emptyMap())); VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", false, false, "", null, variables,
new Variable("NAME", "", Variable.VariableType.TEXT, "", true, false, Collections.<String>emptyList(), 0, "", "", null, Collections.<String, Object>emptyMap()), new Variable("AGE", "", Variable.VariableType.DOUBLE, null, true, false, Collections.singletonList("0:99"), 1, "", "", null, Collections.<String, Object>emptyMap()) );