use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.
the class TableBrowserToolBar method getAttributeArray.
private String[] getAttributeArray() {
final CyTable attrs = browserTableModel.getDataTable();
final Collection<CyColumn> columns = attrs.getColumns();
final String[] attributeArray = new String[columns.size() - 1];
int index = 0;
for (final CyColumn column : columns) {
if (!column.isPrimaryKey())
attributeArray[index++] = column.getName();
}
Arrays.sort(attributeArray);
return attributeArray;
}
use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.
the class TableBrowserToolBar method createNewAttribute.
private void createNewAttribute(final String type, boolean isShared) {
try {
final String[] existingAttrs = getAttributeArray();
String newAttribName = null;
do {
newAttribName = JOptionPane.showInputDialog(this, "Column Name: ", "Create New " + type + " Column", JOptionPane.QUESTION_MESSAGE);
if (newAttribName == null)
return;
newAttribName = newAttribName.trim();
if (newAttribName.isEmpty()) {
JOptionPane.showMessageDialog(null, "Column name must not be blank.", "Error", JOptionPane.ERROR_MESSAGE);
newAttribName = null;
} else if (Arrays.binarySearch(existingAttrs, newAttribName) >= 0) {
JOptionPane.showMessageDialog(null, "Column " + newAttribName + " already exists.", "Error", JOptionPane.ERROR_MESSAGE);
newAttribName = null;
}
} while (newAttribName == null);
final CyTable attrs;
if (isShared) {
final CyNetwork network = serviceRegistrar.getService(CyApplicationManager.class).getCurrentNetwork();
if (network instanceof CySubNetwork) {
final CyRootNetwork rootNetwork = ((CySubNetwork) network).getRootNetwork();
CyTable sharedTable = null;
if (this.objType == CyNode.class)
sharedTable = rootNetwork.getSharedNodeTable();
else if (this.objType == CyEdge.class)
sharedTable = rootNetwork.getSharedEdgeTable();
else if (this.objType == CyNetwork.class)
sharedTable = rootNetwork.getSharedNetworkTable();
else
throw new IllegalStateException("Object type is not valid. This should not happen.");
attrs = sharedTable;
} else {
throw new IllegalArgumentException("This is not a CySubNetwork and there is no shared table.");
}
} else {
attrs = browserTableModel.getDataTable();
}
if (type.equals("String"))
attrs.createColumn(newAttribName, String.class, false);
else if (type.equals("Floating Point"))
attrs.createColumn(newAttribName, Double.class, false);
else if (type.equals("Integer"))
attrs.createColumn(newAttribName, Integer.class, false);
else if (type.equals("Long Integer"))
attrs.createColumn(newAttribName, Long.class, false);
else if (type.equals("Boolean"))
attrs.createColumn(newAttribName, Boolean.class, false);
else if (type.equals("String List"))
attrs.createListColumn(newAttribName, String.class, false);
else if (type.equals("Floating Point List"))
attrs.createListColumn(newAttribName, Double.class, false);
else if (type.equals("Integer List"))
attrs.createListColumn(newAttribName, Integer.class, false);
else if (type.equals("Long Integer List"))
attrs.createListColumn(newAttribName, Long.class, false);
else if (type.equals("Boolean List"))
attrs.createListColumn(newAttribName, Boolean.class, false);
else
throw new IllegalArgumentException("unknown column type \"" + type + "\".");
} catch (IllegalArgumentException e) {
JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
}
use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.
the class NetworkLineParser method mapAttribute.
/**
* Based on the attribute types, map the entry to Node or Edge tables.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
private <T extends CyIdentifiable> void mapAttribute(final T element, final String entry, final int index) {
if (entry == null || entry.length() == 0)
return;
final AttributeDataType type = mapping.getDataTypes()[index];
if (type.isList()) {
final CyTable table = network.getRow(element).getTable();
if (table.getColumn(mapping.getAttributeNames()[index]) == null)
table.createListColumn(mapping.getAttributeNames()[index], type.getListType(), false);
final String[] delimiters = mapping.getListDelimiters();
String delimiter = delimiters != null && delimiters.length > index ? delimiters[index] : AbstractMappingParameters.DEF_LIST_DELIMITER;
if (delimiter == null || delimiter.isEmpty())
delimiter = AbstractMappingParameters.DEF_LIST_DELIMITER;
Object value = parse(entry, type, delimiter);
if (value instanceof List) {
// In case of list, do not overwrite the attribute. Get the existing list, and add it to the list.
List<Object> curList = network.getRow(element).get(mapping.getAttributeNames()[index], List.class);
if (curList == null)
curList = new ArrayList<>();
curList.addAll((List) value);
value = curList;
}
network.getRow(element).set(mapping.getAttributeNames()[index], value);
} else {
createColumn(element, mapping.getAttributeNames()[index], type.getType());
final Object value = parse(entry, type, null);
network.getRow(element).set(mapping.getAttributeNames()[index], value);
}
}
use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.
the class OBOReader method mapHeader.
private void mapHeader() {
final CyTable networkTable = this.ontologyDAG.getDefaultNetworkTable();
for (String tag : header.keySet()) {
if (networkTable.getColumn(tag) == null)
networkTable.createColumn(tag, String.class, false);
networkTable.getRow(ontologyDAG.getSUID()).set(tag, header.get(tag));
}
if (networkTable.getColumn(DAG_ATTR) == null)
networkTable.createColumn(DAG_ATTR, Boolean.class, true);
networkTable.getRow(ontologyDAG.getSUID()).set(DAG_ATTR, true);
ontologyDAG.getRow(ontologyDAG).set(CyNetwork.NAME, dagName);
}
use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.
the class LoadTableReaderTask method loadAnnotation.
private void loadAnnotation(TaskMonitor tm) {
tm.setProgress(0.0);
TextTableReader reader = this.reader;
AttributeMappingParameters readerAMP = (AttributeMappingParameters) reader.getMappingParameter();
String primaryKey = readerAMP.getAttributeNames()[readerAMP.getKeyIndex()];
tm.setProgress(0.1);
final CyTableFactory tableFactory = serviceRegistrar.getService(CyTableFactory.class);
final CyTable table = tableFactory.createTable("AttrTable " + inputName.substring(inputName.lastIndexOf('/') + 1) + " " + Integer.toString(numImports++), primaryKey, String.class, true, true);
cyTables = new CyTable[] { table };
tm.setProgress(0.3);
try {
this.reader.readTable(table);
} catch (IOException e) {
e.printStackTrace();
}
tm.setProgress(1.0);
}
Aggregations