Search in sources :

Example 1 with CyTableReader

use of org.cytoscape.io.read.CyTableReader in project cytoscape-impl by cytoscape.

the class LoadTableFileTaskFactoryImpl method createTaskIterator.

@Override
public TaskIterator createTaskIterator(final File file) {
    final CyTableReaderManager tableReaderMgr = serviceRegistrar.getService(CyTableReaderManager.class);
    final CyTableReader reader = tableReaderMgr.getReader(file.toURI(), file.toURI().toString());
    return new TaskIterator(new CombineReaderAndMappingTask(reader, serviceRegistrar));
}
Also used : TaskIterator(org.cytoscape.work.TaskIterator) CyTableReaderManager(org.cytoscape.io.read.CyTableReaderManager) CyTableReader(org.cytoscape.io.read.CyTableReader)

Example 2 with CyTableReader

use of org.cytoscape.io.read.CyTableReader in project cytoscape-impl by cytoscape.

the class LoadTableURLTaskFactoryImpl method createTaskIterator.

@Override
public TaskIterator createTaskIterator(URL url) {
    URI uri = null;
    try {
        uri = url.toURI();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    final CyTableReaderManager tableReaderMgr = serviceRegistrar.getService(CyTableReaderManager.class);
    final CyTableReader reader = tableReaderMgr.getReader(uri, uri.toString());
    return new TaskIterator(new CombineReaderAndMappingTask(reader, serviceRegistrar));
}
Also used : TaskIterator(org.cytoscape.work.TaskIterator) CyTableReaderManager(org.cytoscape.io.read.CyTableReaderManager) CyTableReader(org.cytoscape.io.read.CyTableReader) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 3 with CyTableReader

use of org.cytoscape.io.read.CyTableReader in project cytoscape-impl by cytoscape.

the class AbstractLoadTableTask method loadTable.

void loadTable(final String name, final URI uri, boolean combine, final TaskMonitor taskMonitor) throws Exception {
    taskMonitor.setStatusMessage("Finding Table Data Reader...");
    final CyTableReaderManager tableReaderMgr = serviceRegistrar.getService(CyTableReaderManager.class);
    final CyTableReader reader = tableReaderMgr.getReader(uri, uri.toString());
    if (reader == null)
        throw new NullPointerException("Failed to find reader for specified file.");
    if (combine) {
        taskMonitor.setStatusMessage("Importing Data Table...");
        insertTasksAfterCurrentTask(new CombineReaderAndMappingTask(reader, serviceRegistrar));
    } else {
        taskMonitor.setStatusMessage("Loading Data Table...");
        insertTasksAfterCurrentTask(new ReaderTableTask(reader, serviceRegistrar), new AddImportedTableTask(reader, serviceRegistrar));
    }
}
Also used : CyTableReaderManager(org.cytoscape.io.read.CyTableReaderManager) CyTableReader(org.cytoscape.io.read.CyTableReader)

Example 4 with CyTableReader

use of org.cytoscape.io.read.CyTableReader 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

CyTableReader (org.cytoscape.io.read.CyTableReader)4 CyTableReaderManager (org.cytoscape.io.read.CyTableReaderManager)3 TaskIterator (org.cytoscape.work.TaskIterator)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Matcher (java.util.regex.Matcher)1 CyTableMetadataBuilder (org.cytoscape.io.internal.read.session.CyTableMetadataImpl.CyTableMetadataBuilder)1 CyTable (org.cytoscape.model.CyTable)1