Search in sources :

Example 26 with CyRow

use of org.cytoscape.model.CyRow in project EnrichmentMapApp by BaderLab.

the class CreateDiseaseSignatureNetworkTask method createExistingEdgeCache.

private static Map<EdgeCacheKey, CyEdge> createExistingEdgeCache(String prefix, CyNetwork network, CyTable edgeTable) {
    Map<EdgeCacheKey, CyEdge> cache = new HashMap<>();
    // Get rows for signature edges
    Collection<CyRow> rows = edgeTable.getMatchingRows(CyEdge.INTERACTION, CreateDiseaseSignatureTaskParallel.INTERACTION);
    for (CyRow row : rows) {
        String name = row.get(CyNetwork.NAME, String.class);
        Long suid = row.get(CyIdentifiable.SUID, Long.class);
        String signatureDataSetName = Columns.EDGE_SIG_DATASET.get(row, prefix);
        CyEdge edge = network.getEdge(suid);
        // we are assuming that the EM data set name is part of the edge name
        cache.put(new EdgeCacheKey(name, signatureDataSetName), edge);
    }
    return cache;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge)

Example 27 with CyRow

use of org.cytoscape.model.CyRow in project EnrichmentMapApp by BaderLab.

the class CreateEMNetworkTask method createNodes.

private Map<String, CyNode> createNodes(CyNetwork network) {
    Map<String, CyNode> nodes = new HashMap<>();
    Map<String, Set<Integer>> geneSets = map.unionAllGeneSetsOfInterest();
    for (String genesetName : geneSets.keySet()) {
        CyNode node = network.addNode();
        nodes.put(genesetName, node);
        // Set common attributes
        CyRow row = network.getRow(node);
        row.set(CyNetwork.NAME, genesetName);
        Columns.NODE_FORMATTED_NAME.set(row, prefix, null, formatLabel(genesetName));
        // MKTODO why is this column needed?
        Columns.NODE_NAME.set(row, prefix, null, genesetName);
        Columns.NODE_GS_DESCR.set(row, prefix, null, map.findGeneSetDescription(genesetName));
        Columns.NODE_GS_TYPE.set(row, prefix, null, Columns.NODE_GS_TYPE_ENRICHMENT);
        Set<Integer> geneIds = geneSets.get(genesetName);
        List<String> genes = geneIds.stream().map(map::getGeneFromHashKey).collect(Collectors.toList());
        Columns.NODE_GENES.set(row, prefix, null, genes);
        Columns.NODE_GS_SIZE.set(row, prefix, null, genes.size());
        // Set attributes specific to each dataset
        for (EMDataSet ds : map.getDataSetList()) {
            if (ds.getGeneSetsOfInterest().getGeneSets().containsKey(genesetName))
                ds.addNodeSuid(node.getSUID());
            Map<String, EnrichmentResult> enrichmentResults = ds.getEnrichments().getEnrichments();
            EnrichmentResult result = enrichmentResults.get(genesetName);
            // if result is null it will fail both instanceof checks
            if (result instanceof GSEAResult)
                setGSEAResultNodeAttributes(row, ds.getName(), (GSEAResult) result);
            else if (result instanceof GenericResult)
                setGenericResultNodeAttributes(row, ds.getName(), (GenericResult) result);
        }
    }
    return nodes;
}
Also used : EnrichmentResult(org.baderlab.csplugins.enrichmentmap.model.EnrichmentResult) GSEAResult(org.baderlab.csplugins.enrichmentmap.model.GSEAResult) Set(java.util.Set) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) HashMap(java.util.HashMap) CyRow(org.cytoscape.model.CyRow) GenericResult(org.baderlab.csplugins.enrichmentmap.model.GenericResult) CyNode(org.cytoscape.model.CyNode) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet)

Example 28 with CyRow

use of org.cytoscape.model.CyRow in project EnrichmentMapApp by BaderLab.

the class WidthFunction method calculateAndSetEdgeWidths.

private void calculateAndSetEdgeWidths(CyNetwork network, String prefix, TaskMonitor taskMonitor) {
    EdgeWidthParams edgeWidthParams = EdgeWidthParams.restore(network);
    EnrichmentMap map = emManager.getEnrichmentMap(network.getSUID());
    //		String widthAttribute = prefix + EDGE_WIDTH_FORMULA_COLUMN;
    int n = network.getDefaultEdgeTable().getRowCount();
    int i = 0;
    for (CyRow row : network.getDefaultEdgeTable().getAllRows()) {
        if (taskMonitor != null)
            taskMonitor.setProgress((double) i / (double) n);
        i++;
        String interaction = row.get(CyEdge.INTERACTION, String.class);
        if (isSignature(interaction)) {
            String cutoffType = EDGE_CUTOFF_TYPE.get(row, prefix, null);
            PostAnalysisFilterType filterType = PostAnalysisFilterType.fromDisplayString(cutoffType);
            if (filterType == null) {
                EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, null, null);
                continue;
            }
            Double pvalue, cutoff;
            switch(filterType) {
                case MANN_WHIT_TWO_SIDED:
                    pvalue = EDGE_MANN_WHIT_TWOSIDED_PVALUE.get(row, prefix);
                    cutoff = EDGE_MANN_WHIT_CUTOFF.get(row, prefix);
                    break;
                case MANN_WHIT_GREATER:
                    pvalue = EDGE_MANN_WHIT_GREATER_PVALUE.get(row, prefix);
                    cutoff = EDGE_MANN_WHIT_CUTOFF.get(row, prefix);
                    break;
                case MANN_WHIT_LESS:
                    pvalue = EDGE_MANN_WHIT_LESS_PVALUE.get(row, prefix);
                    cutoff = EDGE_MANN_WHIT_CUTOFF.get(row, prefix);
                    break;
                default:
                    pvalue = EDGE_HYPERGEOM_PVALUE.get(row, prefix);
                    cutoff = EDGE_HYPERGEOM_CUTOFF.get(row, prefix);
                    break;
            }
            if (pvalue == null || cutoff == null) {
                EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, null);
            } else if (pvalue <= cutoff / 100) {
                EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, edgeWidthParams.pa_lessThan100);
            } else if (pvalue <= cutoff / 10) {
                EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, edgeWidthParams.pa_lessThan10);
            } else {
                EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, edgeWidthParams.pa_greater);
            }
        } else {
            // Can use a continuous mapping object to perform calculation
            // even though it won't be added to the visual style.
            ContinuousMapping<Double, Double> conmapping_edgewidth = (ContinuousMapping<Double, Double>) vmfFactoryContinuous.createVisualMappingFunction(prefix + EDGE_SIMILARITY_COEFF, Double.class, BasicVisualLexicon.EDGE_WIDTH);
            Double under_width = 0.5;
            Double min_width = edgeWidthParams.em_lower;
            Double max_width = edgeWidthParams.em_upper;
            Double over_width = 6.0;
            // Create boundary conditions                  less than,   equals,  greater than
            BoundaryRangeValues<Double> bv4 = new BoundaryRangeValues<>(under_width, min_width, min_width);
            BoundaryRangeValues<Double> bv5 = new BoundaryRangeValues<>(max_width, max_width, over_width);
            conmapping_edgewidth.addPoint(map.getParams().getSimilarityCutoff(), bv4);
            conmapping_edgewidth.addPoint(1.0, bv5);
            Double value = conmapping_edgewidth.getMappedValue(row);
            EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, value);
        }
    }
}
Also used : ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) PostAnalysisFilterType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType) BoundaryRangeValues(org.cytoscape.view.vizmap.mappings.BoundaryRangeValues) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) CyRow(org.cytoscape.model.CyRow)

Example 29 with CyRow

use of org.cytoscape.model.CyRow in project EnrichmentMapApp by BaderLab.

the class AbstractChart method getDataFromColumns.

public Map<String, List<Double>> getDataFromColumns(final CyNetwork network, final CyIdentifiable model, final List<CyColumnIdentifier> columnNames) {
    LinkedHashMap<String, List<Double>> data = new LinkedHashMap<>();
    final CyRow row = network.getRow(model);
    if (row == null)
        return data;
    final CyTable table = row.getTable();
    final List<Double> singleSeriesValues = new ArrayList<>();
    final StringBuilder singleSeriesKey = new StringBuilder();
    int singleSeriesIndex = -1;
    int count = 0;
    for (final CyColumnIdentifier colId : columnNames) {
        final CyColumn column = table.getColumn(colId.getColumnName());
        if (column == null)
            continue;
        final String colName = column.getName();
        final List<Double> values = new ArrayList<>();
        if (column.getType() == List.class) {
            // List Column: One column = one data series
            final Class<?> type = column.getListElementType();
            if (type == Double.class) {
                List<Double> list = row.getList(colName, Double.class);
                if (list != null)
                    values.addAll(list);
            } else if (type == Integer.class) {
                List<Integer> list = row.getList(colName, Integer.class);
                if (list != null) {
                    for (Integer i : list) values.add(i.doubleValue());
                }
            } else if (type == Long.class) {
                List<Long> list = row.getList(colName, Long.class);
                if (list != null) {
                    for (Long l : list) values.add(l.doubleValue());
                }
            } else if (type == Float.class) {
                List<Float> list = row.getList(colName, Float.class);
                if (list != null) {
                    for (Float f : list) values.add(f.doubleValue());
                }
            }
            data.put(colName, values);
        } else {
            // Single Column: All single columns together make only one data series
            final Class<?> type = column.getType();
            if (Number.class.isAssignableFrom(type)) {
                if (!row.isSet(colName)) {
                    singleSeriesValues.add(Double.NaN);
                } else if (type == Double.class) {
                    singleSeriesValues.add(row.get(colName, Double.class));
                } else if (type == Integer.class) {
                    Integer i = row.get(colName, Integer.class);
                    singleSeriesValues.add(i.doubleValue());
                } else if (type == Float.class) {
                    Float f = row.get(colName, Float.class);
                    singleSeriesValues.add(f.doubleValue());
                }
                singleSeriesKey.append(colName + ",");
                // The index of this data series is the index of the first single column
                if (singleSeriesIndex == -1)
                    singleSeriesIndex = count;
            }
        }
        count++;
    }
    if (!singleSeriesValues.isEmpty()) {
        singleSeriesKey.deleteCharAt(singleSeriesKey.length() - 1);
        // To add the series of single columns into the correct position, we have to rebuild the data map
        final Set<Entry<String, List<Double>>> entrySet = data.entrySet();
        data = new LinkedHashMap<>();
        int i = 0;
        for (final Entry<String, List<Double>> entry : entrySet) {
            if (i == singleSeriesIndex)
                data.put(singleSeriesKey.toString(), singleSeriesValues);
            data.put(entry.getKey(), entry.getValue());
            i++;
        }
        if (// (entrySet.isEmpty() || i >= entrySet.size())
        !data.containsKey(singleSeriesKey.toString()))
            data.put(singleSeriesKey.toString(), singleSeriesValues);
    }
    return data;
}
Also used : ArrayList(java.util.ArrayList) CyColumn(org.cytoscape.model.CyColumn) CyColumnIdentifier(org.cytoscape.view.presentation.property.values.CyColumnIdentifier) CyRow(org.cytoscape.model.CyRow) LinkedHashMap(java.util.LinkedHashMap) CyTable(org.cytoscape.model.CyTable) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) List(java.util.List)

Example 30 with CyRow

use of org.cytoscape.model.CyRow in project cytoscape-api by cytoscape.

the class AbstractCySubNetworkTest method testEdgeAddedInSubnetworkHasNameAttr.

@Test
public void testEdgeAddedInSubnetworkHasNameAttr() {
    n1 = root.addNode();
    n2 = root.addNode();
    e1 = root.addEdge(n1, n2, true);
    root.getRow(e1).set(CyNetwork.NAME, "homer");
    root.getSharedEdgeTable().getRow(e1.getSUID()).set(CyRootNetwork.SHARED_NAME, "homer");
    final String originalName = root.getRow(e1).get(CyNetwork.NAME, String.class);
    assertEquals("homer", originalName);
    sub = root.addSubNetwork();
    sub.addNode(n1);
    sub.addNode(n2);
    sub.addEdge(e1);
    final List<CyEdge> subEdges = sub.getEdgeList();
    assertEquals(1, subEdges.size());
    final CyEdge newEdge = subEdges.get(0);
    final CyRow row = sub.getRow(newEdge);
    assertEquals("homer", row.get(CyRootNetwork.SHARED_NAME, String.class));
    assertEquals("homer", row.get(CyNetwork.NAME, String.class));
}
Also used : CyRow(org.cytoscape.model.CyRow) DummyCyEdge(org.cytoscape.model.DummyCyEdge) CyEdge(org.cytoscape.model.CyEdge) Test(org.junit.Test)

Aggregations

CyRow (org.cytoscape.model.CyRow)33 CyTable (org.cytoscape.model.CyTable)12 CyColumn (org.cytoscape.model.CyColumn)10 ArrayList (java.util.ArrayList)9 CyEdge (org.cytoscape.model.CyEdge)8 CyNode (org.cytoscape.model.CyNode)8 Test (org.junit.Test)8 HashMap (java.util.HashMap)7 CyNetwork (org.cytoscape.model.CyNetwork)7 List (java.util.List)6 EMDataSet (org.baderlab.csplugins.enrichmentmap.model.EMDataSet)4 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 Map (java.util.Map)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 EnrichmentMap (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)3 CyColumnIdentifier (org.cytoscape.view.presentation.property.values.CyColumnIdentifier)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Paint (java.awt.Paint)2