private void mergeTables( final CyTable source, final CyTable target, final Class<? extends CyIdentifiable> type) { CyColumn sourceKey = source.getPrimaryKey(); CyColumn targetKey = target.getPrimaryKey(); String keyName = sourceKey.getName(); // Make sure keys match if (keyName.equals(targetKey.getName())) { // Merge columns first, because even if the source table has no rows to merge, // the columns have to be restored mergeColumns(keyName, source, target); for (CyRow sourceRow : source.getAllRows()) { if (cancelled) return; Long key = sourceRow.get(keyName, Long.class); CyIdentifiable entry = cache.getObjectById(key, type); Long mappedKey = entry != null ? entry.getSUID() : null; if (mappedKey == null) mappedKey = key; CyRow targetRow = target.getRow(mappedKey); mergeRow(keyName, sourceRow, targetRow); } } }
@Override public boolean handleIt( final CyIdentifiable to, final CyColumn toColumn, final Map<CyIdentifiable, CyColumn> mapFromGOFromAttr) { if (to == null || toColumn == null || mapFromGOFromAttr == null) { throw new java.lang.NullPointerException("All parameters should not be null."); } final CyTable table = toColumn.getTable(); final CyRow row = table.getRow(to.getSUID()); final ColumnType type = ColumnType.getType(toColumn); if (type == ColumnType.STRING) { final String toValue = row.get(toColumn.getName(), String.class); final Set<String> values = new TreeSet<String>(); values.add(toValue); for (Map.Entry<CyIdentifiable, CyColumn> entry : mapFromGOFromAttr.entrySet()) { final CyIdentifiable from = entry.getKey(); final CyColumn fromColumn = entry.getValue(); final CyRow fromRow = fromColumn.getTable().getRow(from.getSUID()); // TODO figure out which network to be using String fromValue = fromRow.get(fromColumn.getName(), String.class); if (fromValue != null) { values.add(fromValue.toString()); } } StringBuilder str = new StringBuilder(); for (String v : values) { str.append(v + ";"); } str.deleteCharAt(str.length() - 1); row.set(toColumn.getName(), str.toString()); return true; } // FIXME: how about Integer, Double, Boolean? return false; }
private String convertToName(final String id) { final Collection<CyRow> rows = ontologyDAG.getDefaultNodeTable().getMatchingRows(CyNetwork.NAME, id); if (!rows.isEmpty()) { final CyRow row = rows.iterator().next(); final String termName = row.get(OBOReader.TERM_NAME, String.class); if (termName != null) return termName; else return id; } else return id; }
/** {@inheritDoc} */ @Override public Evidence[] mapFromTable(CyEdge edge, CyTable table) { if (edge == null) throw new NullPointerException("edge cannot be null"); if (table == null) throw new NullPointerException("table cannot be null"); Set<String> nonAnnotationColumns = new HashSet<String>( asList( CyNetwork.SUID, NETWORK_SUID, NETWORK_NAME, EDGE_SUID, BEL_STATEMENT, SUMMARY_TEXT, CITATION_ID, CITATION_NAME, CITATION_TYPE, SPECIES)); Collection<CyRow> evidenceRows = table.getMatchingRows(EDGE_SUID, edge.getSUID()); List<Evidence> evidences = new ArrayList<Evidence>(evidenceRows.size()); if (!evidenceRows.isEmpty()) { for (CyRow evRow : evidenceRows) { Evidence e = new Evidence(); e.belStatement = evRow.get(BEL_STATEMENT, String.class); e.summaryText = evRow.get(SUMMARY_TEXT, String.class); e.citation = new Citation(); e.citation.id = evRow.get(CITATION_ID, String.class); e.citation.name = evRow.get(CITATION_NAME, String.class); e.citation.type = evRow.get(CITATION_TYPE, String.class); e.biologicalContext = new BiologicalContext(); e.biologicalContext.speciesCommonName = evRow.get(SPECIES, String.class); e.biologicalContext.variedAnnotations = new HashMap<String, Object>(); for (Entry<String, Object> columnValue : evRow.getAllValues().entrySet()) { if (nonAnnotationColumns.contains(columnValue.getKey())) continue; e.biologicalContext.variedAnnotations.put(columnValue.getKey(), columnValue.getValue()); } evidences.add(e); } } return evidences.toArray(new Evidence[evidences.size()]); }
/** {@inheritDoc} */ @Override public void mapToTable(Graph graph, Edge edge, Evidence evidence, CyTable table) { if (graph == null) throw new NullPointerException("graph cannot be null"); if (edge == null) throw new NullPointerException("edge cannot be null"); if (evidence == null) throw new NullPointerException("evidence cannot be null"); if (table == null) throw new NullPointerException("table cannot be null"); if (graph.cyNetwork == null) throw new IllegalArgumentException("graph's cyNetwork cannot be null"); if (edge.cyEdge == null) throw new IllegalArgumentException("edge's cyEdge cannot be null"); CyNetwork cyN = graph.cyNetwork; CyEdge cyE = edge.cyEdge; CyRow networkRow = cyN.getRow(cyN); String networkName = networkRow.get(CyNetwork.NAME, String.class); CyRow row = table.getRow(SUIDFactory.getNextSUID()); row.set(NETWORK_SUID, cyN.getSUID()); row.set(NETWORK_NAME, networkName); row.set(EDGE_SUID, cyE.getSUID()); row.set(BEL_STATEMENT, evidence.belStatement); row.set(SUMMARY_TEXT, evidence.summaryText); if (evidence.citation != null) { row.set(CITATION_TYPE, evidence.citation.type); row.set(CITATION_ID, evidence.citation.id); row.set(CITATION_NAME, evidence.citation.name); } if (evidence.biologicalContext != null) { // create any annotation columns that do not already exist BiologicalContext bc = evidence.biologicalContext; for (String varyingKey : bc.variedAnnotations.keySet()) { getOrCreateColumn(varyingKey, String.class, false, table); } // set annotation values row.set(SPECIES, bc.speciesCommonName); Map<String, Object> varying = bc.variedAnnotations; for (Entry<String, Object> entry : varying.entrySet()) { row.set(entry.getKey(), getOrEmptyString(entry.getKey(), varying)); } } }
private void guessHumanReadableName(final CyRow row) { boolean found = false; // Special handler for STRING. This is a hack... if (row.getTable().getColumn(STRING_ATTR_NAME) != null) { final List<String> stringList = row.getList(STRING_ATTR_NAME, String.class); if (stringList != null) found = findHumanReadableName(row, stringList, ncbiPattern, true); } if (found) return; // try NCBI if (row.getTable().getColumn(ENTREZ_GENE_ATTR_NAME) != null) { final List<String> ncbiList = row.getList(ENTREZ_GENE_ATTR_NAME, String.class); if (ncbiList != null) found = findHumanReadableName(row, ncbiList, ncbiPattern, true); } if (found) return; // Try Uniprot List<String> uniprotList = null; if (row.getTable().getColumn(UNIPROT_ATTR_NAME) != null) { uniprotList = row.getList(UNIPROT_ATTR_NAME, String.class); if (uniprotList != null) found = findHumanReadableName(row, uniprotList, exact1Pattern, true); } if (found) return; if (uniprotList != null) found = findHumanReadableName(row, uniprotList, uniprotPattern, false); if (found) return; // Unknown if (row.getTable().getColumn("unknown") != null) { final List<String> unknownList = row.getList("unknown", String.class); if (unknownList != null) found = findHumanReadableName(row, unknownList, uniprotPattern, false); } if (found) return; if (found == false) { // Give up. Use primary key row.set(PREDICTED_GENE_NAME, row.get(CyNetwork.NAME, String.class)); } }
private void mergeRow(String keyName, CyRow sourceRow, CyRow targetRow) { for (CyColumn column : sourceRow.getTable().getColumns()) { if (cancelled) return; String columnName = column.getName(); if (columnName.equals(keyName)) continue; Class<?> type = column.getType(); if (type.equals(List.class)) { Class<?> elementType = column.getListElementType(); List<?> list = sourceRow.getList(columnName, elementType); targetRow.set(columnName, list); } else { Object value = sourceRow.get(columnName, type); targetRow.set(columnName, value); } } }
@Test public void gaReaderTest() throws Exception { File file = new File("./src/test/resources/" + GA_YEAST); GeneAssociationReader reader = new GeneAssociationReader( "dummy dag", file.toURI().toURL().openStream(), "yeast GA", serviceRegistrar); System.out.print("Start read: "); reader.run(tm); final CyTable[] tables = reader.getTables(); assertNotNull(tables); assertEquals(1, tables.length); assertNotNull(tables[0]); // All 22 Columns + NAME primary key + synonyms assertEquals(24, tables[0].getColumns().size()); // For yeast test file. assertEquals(6359, tables[0].getRowCount()); // Check table contents final CyTable table = tables[0]; final CyRow row1 = table.getRow("S000003319"); assertNotNull(row1); final List<String> bpList1 = row1.getList("biological process", String.class); assertNotNull(bpList1); assertFalse(bpList1.contains("GO:0000287")); assertTrue(bpList1.contains("GO:0006067")); assertFalse(bpList1.contains("fake value")); final String taxName = row1.get(GeneAssociationTag.TAXON.toString(), String.class); assertNotNull(taxName); assertEquals("Saccharomyces cerevisiae", taxName); final List<String> referenceList1 = row1.getList("biological process DB Reference", String.class); // assertNotNull(referenceList1); // assertEquals(2, referenceList1.size()); }
public void handleEvent(RowsSetEvent e) { final CyTable local = e.getSource(); synchronized (lock) { final List<CyTable> sharedList = tables.get(local); for (CyTable shared : sharedList) { for (RowSetRecord record : e.getColumnRecords(columnName)) { // assume payload collection is for same column final CyRow r = shared.getRow(record.getRow().get(CyIdentifiable.SUID, Long.class)); if (r != null) { final Object name = record.getValue(); String sharedName = r.get(sharedColumnName, String.class); if (sharedName == null) { r.set(sharedColumnName, name); } } } } } }