use of org.molgenis.genomebrowser.meta.GenomeBrowserAttributes in project molgenis by molgenis.
the class GenomeBrowserService method getGenomeBrowserTracks.
public Map<String, GenomeBrowserTrack> getGenomeBrowserTracks(EntityType entityType, List<GenomeBrowserAttributes> defaultGenomeBrowserAttributes) {
Map<String, GenomeBrowserTrack> settings = new HashMap<>();
dataService.findAll(GENOMEBROWSERSETTINGS, new QueryImpl<GenomeBrowserSettings>().eq(GenomeBrowserSettingsMetadata.ENTITY, entityType.getIdValue()), GenomeBrowserSettings.class).forEach(referenceSettings -> settings.put(referenceSettings.getIdentifier(), GenomeBrowserTrack.create(referenceSettings)));
if (settings.isEmpty()) {
// if not check if attrs match any default config
Collections.sort(defaultGenomeBrowserAttributes);
for (GenomeBrowserAttributes genomeBrowserAttributes : defaultGenomeBrowserAttributes) {
List<String> attributeNames = Lists.newArrayList(entityType.getAttributeNames());
if (areAllAttributeAvailable(genomeBrowserAttributes, attributeNames)) {
GenomeBrowserTrack genomeBrowserTrack = getDefaultGenomeBrowserSettingsEntity(entityType, genomeBrowserAttributes);
settings.put(genomeBrowserTrack.getId(), genomeBrowserTrack);
break;
}
}
}
return settings;
}
use of org.molgenis.genomebrowser.meta.GenomeBrowserAttributes in project molgenis by molgenis.
the class GenomeBrowserServiceTest method getGenomeBrowserAttributes.
public static GenomeBrowserAttributes getGenomeBrowserAttributes(String pos, String chrom, String ref, String alt) {
Entity attrsEntity = mock(Entity.class);
GenomeBrowserAttributes genomeBrowserAttributes = new GenomeBrowserAttributes(attrsEntity);
when(attrsEntity.getString(POS)).thenReturn(pos);
when(attrsEntity.getString(CHROM)).thenReturn(chrom);
when(attrsEntity.getString(REF)).thenReturn(ref);
when(attrsEntity.getString(ALT)).thenReturn(alt);
return genomeBrowserAttributes;
}
use of org.molgenis.genomebrowser.meta.GenomeBrowserAttributes in project molgenis by molgenis.
the class GenomeBrowserServiceTest method testGetReferenceTracks.
@Test
public void testGetReferenceTracks() {
EntityType entity = mock(EntityType.class);
when(entity.getLabel()).thenReturn("label");
GenomeBrowserAttributes genomeBrowserAttributes = getGenomeBrowserAttributes("postion", "chrom", "normal", "mutant");
GenomeBrowserTrack reference = GenomeBrowserTrack.create("ref_id", "label", "ref_label", entity, GenomeBrowserSettings.TrackType.VARIANT, null, GenomeBrowserSettings.MolgenisReferenceMode.ALL, genomeBrowserAttributes, null, null, null, null);
EntityType molgenisEntity = mock(EntityType.class);
GenomeBrowserTrack track = GenomeBrowserTrack.create("id", "label", "entityLabel", molgenisEntity, GenomeBrowserSettings.TrackType.VARIANT, Collections.singletonList(reference), GenomeBrowserSettings.MolgenisReferenceMode.CONFIGURED, genomeBrowserAttributes, "alert(\"test\")", "attr 1:attr1,reference attribute:REF,position on genome:POS", null, null);
Map<String, GenomeBrowserTrack> result = genomeBrowserService.getReferenceTracks(track);
assertEquals(result.size(), 1);
assertEquals(result.get("ref_id"), reference);
}
use of org.molgenis.genomebrowser.meta.GenomeBrowserAttributes in project molgenis by molgenis.
the class GenomeBrowserServiceTest method testGetReferenceTracksNone.
@Test
public void testGetReferenceTracksNone() {
EntityType entity = mock(EntityType.class);
when(entity.getLabel()).thenReturn("label");
GenomeBrowserAttributes genomeBrowserAttributes = getGenomeBrowserAttributes("postion", "chrom", "normal", "mutant");
GenomeBrowserTrack reference = GenomeBrowserTrack.create("ref_id", "label", "ref_label", entity, GenomeBrowserSettings.TrackType.VARIANT, null, GenomeBrowserSettings.MolgenisReferenceMode.NONE, genomeBrowserAttributes, null, null, null, null);
EntityType molgenisEntity = mock(EntityType.class);
GenomeBrowserTrack track = GenomeBrowserTrack.create("id", "label", "entityLabel", molgenisEntity, GenomeBrowserSettings.TrackType.VARIANT, Collections.singletonList(reference), GenomeBrowserSettings.MolgenisReferenceMode.NONE, genomeBrowserAttributes, "alert(\"test\")", "attr 1:attr1,reference attribute:REF,position on genome:POS", null, null);
Map<String, GenomeBrowserTrack> result = genomeBrowserService.getReferenceTracks(track);
assertEquals(result.size(), 0);
verify(dataService, never()).getMeta();
}
use of org.molgenis.genomebrowser.meta.GenomeBrowserAttributes in project molgenis by molgenis.
the class GenomeBrowserServiceTest method testGetReferenceTracksAll.
@Test
public void testGetReferenceTracksAll() {
EntityType entity = mock(EntityType.class);
when(entity.getLabel()).thenReturn("label");
GenomeBrowserAttributes genomeBrowserAttributes = getGenomeBrowserAttributes("postion", "chrom", "normal", "mutant");
GenomeBrowserTrack reference = GenomeBrowserTrack.create("ref_id", "label", "ref_label", entity, GenomeBrowserSettings.TrackType.VARIANT, null, GenomeBrowserSettings.MolgenisReferenceMode.NONE, genomeBrowserAttributes, null, null, null, null);
EntityType molgenisEntity = mock(EntityType.class);
when(molgenisEntity.getLabel()).thenReturn("label");
GenomeBrowserTrack track = GenomeBrowserTrack.create("id", "label", "entityLabel", molgenisEntity, GenomeBrowserSettings.TrackType.VARIANT, Collections.singletonList(reference), GenomeBrowserSettings.MolgenisReferenceMode.ALL, genomeBrowserAttributes, "alert(\"test\")", "attr 1:attr1,reference attribute:REF,position on genome:POS", null, null);
GenomeBrowserAttributes attrs1 = getGenomeBrowserAttributes("pos", "chr", "ref", "alt");
GenomeBrowserAttributes attrs2 = getGenomeBrowserAttributes("POS", "CHROM", null, null);
when(dataService.findAll(GenomeBrowserAttributesMetadata.GENOMEBROWSERATTRIBUTES, new QueryImpl<GenomeBrowserAttributes>().eq(GenomeBrowserAttributesMetadata.DEFAULT, true), GenomeBrowserAttributes.class)).thenReturn(Stream.of(attrs1, attrs2));
EntityType type1 = mock(EntityType.class);
EntityType type2 = mock(EntityType.class);
EntityType type3 = mock(EntityType.class);
Attribute labelAttr = mock(Attribute.class);
when(labelAttr.getName()).thenReturn("refLabel");
List<EntityType> types = new ArrayList<>();
types.add(type1);
when(type1.getIdValue()).thenReturn("type1");
when(type1.getLabel()).thenReturn("label1");
when(type1.getAttributeNames()).thenReturn(Arrays.asList("POS", "CHROM", "AAP", "NOOT", "MIES"));
when(type1.getLabelAttribute()).thenReturn(labelAttr);
types.add(type2);
when(type2.getIdValue()).thenReturn("type2");
when(type2.getLabel()).thenReturn("label2");
when(type2.getAttributeNames()).thenReturn(Arrays.asList("pos", "chr", "ref", "alt", "aap"));
when(type2.getLabelAttribute()).thenReturn(labelAttr);
types.add(type3);
when(type3.getIdValue()).thenReturn("type3");
when(type3.getLabel()).thenReturn("label3");
when(type3.getAttributeNames()).thenReturn(Arrays.asList("pos", "chr", "ref", "alternative", "monkey"));
when(type3.getLabelAttribute()).thenReturn(labelAttr);
MetaDataService metaDataService = mock(MetaDataService.class);
when(dataService.getMeta()).thenReturn(metaDataService);
when(metaDataService.getEntityTypes()).thenReturn(types.stream());
Map<String, GenomeBrowserTrack> result = genomeBrowserService.getReferenceTracks(track);
assertEquals(result.size(), 2);
assertEquals(result.get("type2"), GenomeBrowserTrack.create("type2", "label2", "refLabel", type2, GenomeBrowserSettings.TrackType.VARIANT, Collections.emptyList(), GenomeBrowserSettings.MolgenisReferenceMode.ALL, attrs1, null, null, null, null));
assertEquals(result.get("type1"), GenomeBrowserTrack.create("type1", "label1", "refLabel", type1, GenomeBrowserSettings.TrackType.VARIANT, Collections.emptyList(), GenomeBrowserSettings.MolgenisReferenceMode.ALL, attrs2, null, null, null, null));
}
Aggregations