Search in sources :

Example 1 with GenomeBrowserAttributes

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;
}
Also used : GenomeBrowserAttributes(org.molgenis.genomebrowser.meta.GenomeBrowserAttributes) HashMap(java.util.HashMap) GenomeBrowserSettings(org.molgenis.genomebrowser.meta.GenomeBrowserSettings) GenomeBrowserTrack(org.molgenis.genomebrowser.GenomeBrowserTrack)

Example 2 with GenomeBrowserAttributes

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;
}
Also used : GenomeBrowserAttributes(org.molgenis.genomebrowser.meta.GenomeBrowserAttributes) Entity(org.molgenis.data.Entity)

Example 3 with 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);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) GenomeBrowserAttributes(org.molgenis.genomebrowser.meta.GenomeBrowserAttributes) GenomeBrowserTrack(org.molgenis.genomebrowser.GenomeBrowserTrack) Test(org.testng.annotations.Test)

Example 4 with GenomeBrowserAttributes

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();
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) GenomeBrowserAttributes(org.molgenis.genomebrowser.meta.GenomeBrowserAttributes) GenomeBrowserTrack(org.molgenis.genomebrowser.GenomeBrowserTrack) Test(org.testng.annotations.Test)

Example 5 with GenomeBrowserAttributes

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));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) GenomeBrowserAttributes(org.molgenis.genomebrowser.meta.GenomeBrowserAttributes) QueryImpl(org.molgenis.data.support.QueryImpl) MetaDataService(org.molgenis.data.meta.MetaDataService) Attribute(org.molgenis.data.meta.model.Attribute) GenomeBrowserTrack(org.molgenis.genomebrowser.GenomeBrowserTrack) Test(org.testng.annotations.Test)

Aggregations

GenomeBrowserAttributes (org.molgenis.genomebrowser.meta.GenomeBrowserAttributes)6 EntityType (org.molgenis.data.meta.model.EntityType)4 GenomeBrowserTrack (org.molgenis.genomebrowser.GenomeBrowserTrack)4 Test (org.testng.annotations.Test)4 HashMap (java.util.HashMap)1 Entity (org.molgenis.data.Entity)1 MetaDataService (org.molgenis.data.meta.MetaDataService)1 Attribute (org.molgenis.data.meta.model.Attribute)1 QueryImpl (org.molgenis.data.support.QueryImpl)1 GenomeBrowserSettings (org.molgenis.genomebrowser.meta.GenomeBrowserSettings)1 GenomeBrowserServiceTest (org.molgenis.genomebrowser.service.GenomeBrowserServiceTest)1