Search in sources :

Example 1 with CyTableMetadataBuilder

use of org.cytoscape.io.internal.read.session.CyTableMetadataImpl.CyTableMetadataBuilder in project cytoscape-impl by cytoscape.

the class Cy3SessionReaderImpl method mergeNetworkTables.

private final void mergeNetworkTables() throws UnsupportedEncodingException {
    final CyNetworkTableManager networkTableManager = serviceRegistrar.getService(CyNetworkTableManager.class);
    for (final Entry<Long, Set<CyTableMetadataBuilder>> entry : networkTableMap.entrySet()) {
        final Object oldId = entry.getKey();
        final Set<CyTableMetadataBuilder> builders = entry.getValue();
        final CyNetwork network = cache.getNetwork(oldId);
        if (network == null) {
            logger.error("Cannot merge network tables: Cannot find network " + oldId);
            continue;
        }
        for (final CyTableMetadataBuilder builder : builders) {
            if (cancelled)
                return;
            builder.setNetwork(network);
            mergeNetworkTable(network, builder, networkTableManager);
            CyTableMetadata metadata = builder.build();
            tableMetadata.add(metadata);
            // Update filename<->table maps
            final String filename = builderFilenameMap.get(builder);
            filenameTableMap.put(filename, metadata.getTable());
        }
    }
}
Also used : CyNetworkTableManager(org.cytoscape.model.CyNetworkTableManager) Set(java.util.Set) HashSet(java.util.HashSet) CyTableMetadataBuilder(org.cytoscape.io.internal.read.session.CyTableMetadataImpl.CyTableMetadataBuilder) CyNetwork(org.cytoscape.model.CyNetwork) CyTableMetadata(org.cytoscape.model.CyTableMetadata)

Example 2 with CyTableMetadataBuilder

use of org.cytoscape.io.internal.read.session.CyTableMetadataImpl.CyTableMetadataBuilder in project cytoscape-impl by cytoscape.

the class Cy3SessionReaderImpl method extractTable.

private void extractTable(InputStream stream, String entryName) throws Exception {
    CyTableReader reader = (CyTableReader) csvCyReaderFactory.createTaskIterator(stream, entryName).next();
    reader.run(taskMonitor);
    // Assume one table per entry
    CyTable table = reader.getTables()[0];
    Matcher matcher = NETWORK_TABLE_PATTERN.matcher(entryName);
    if (matcher.matches()) {
        String networkName = SessionUtil.unescape(matcher.group(2));
        Long oldNetId = getOldNetworkId(networkName);
        if (oldNetId == null) {
            throw new NullPointerException("Cannot extract table. Network SUID is null for entry: " + entryName);
        }
        String namespace = SessionUtil.unescape(matcher.group(3));
        Class<?> type = Class.forName(SessionUtil.unescape(matcher.group(4)));
        String title = SessionUtil.unescape(matcher.group(5));
        table.setTitle(title);
        CyTableMetadataBuilder builder = new CyTableMetadataBuilder().setCyTable(table).setNamespace(namespace).setType(type);
        Set<CyTableMetadataBuilder> builders = networkTableMap.get(oldNetId);
        if (builders == null) {
            builders = new HashSet<>();
            networkTableMap.put(oldNetId, builders);
        }
        builders.add(builder);
        String filename = matcher.group(1);
        filenameTableMap.put(filename, table);
        builderFilenameMap.put(builder, filename);
        return;
    }
    matcher = GLOBAL_TABLE_PATTERN.matcher(entryName);
    if (matcher.matches()) {
        String title = SessionUtil.unescape(matcher.group(3));
        table.setTitle(title);
        CyTableMetadataBuilder builder = new CyTableMetadataBuilder().setCyTable(table).setNetwork(null);
        tableMetadata.add(builder.build());
        String filename = matcher.group(1);
        filenameTableMap.put(filename, table);
        builderFilenameMap.put(builder, filename);
        // Look for SUID-type columns--only global tables now
        suidUpdater.addTable(table);
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) Matcher(java.util.regex.Matcher) CyTableMetadataBuilder(org.cytoscape.io.internal.read.session.CyTableMetadataImpl.CyTableMetadataBuilder) CyTableReader(org.cytoscape.io.read.CyTableReader)

Aggregations

CyTableMetadataBuilder (org.cytoscape.io.internal.read.session.CyTableMetadataImpl.CyTableMetadataBuilder)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Matcher (java.util.regex.Matcher)1 CyTableReader (org.cytoscape.io.read.CyTableReader)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyNetworkTableManager (org.cytoscape.model.CyNetworkTableManager)1 CyTable (org.cytoscape.model.CyTable)1 CyTableMetadata (org.cytoscape.model.CyTableMetadata)1