Author: kono
Date: 2012-07-26 19:42:10 -0700 (Thu, 26 Jul 2012)
New Revision: 30016
Modified:
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/InteractionClusterMapper.java
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/MergedNetworkBuilder.java
Log:
Human readable name generator ported from 2.
Modified:
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/InteractionClusterMapper.java
===================================================================
---
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/InteractionClusterMapper.java
2012-07-27 00:30:23 UTC (rev 30015)
+++
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/InteractionClusterMapper.java
2012-07-27 02:42:10 UTC (rev 30016)
@@ -4,18 +4,21 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.regex.Pattern;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import org.cytoscape.model.CyEdge;
+import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyRow;
import org.cytoscape.webservice.psicquic.miriam.Miriam;
import org.cytoscape.webservice.psicquic.miriam.Miriam.Datatype;
@@ -33,6 +36,20 @@
private static final String SCHEMA_NAMESPACE =
"org.cytoscape.webservice.psicquic.miriam";
+ static final String PREDICTED_GENE_NAME = "Human Readable Gene Name";
+ static final String PUB_ID = "publication id";
+ static final String PUB_DB = "publication db";
+
+ static final String EXPERIMENT = "experiment";
+
+ private final static Pattern exact1Pattern =
Pattern.compile("^[A-Z][A-Z][A-Z]\\d");
+ private final static Pattern ncbiPattern =
Pattern.compile("^[A-Za-z].+");
+ private final static Pattern uniprotPattern =
Pattern.compile("^[a-zA-Z]\\d.+");
+
+ private static final String ENTREZ_GENE_ATTR_NAME = "entrez
gene/locuslink";
+ private static final String UNIPROT_ATTR_NAME = "uniprot";
+ private static final String STRING_ATTR_NAME = "string";
+
private final Set<String> namespaceSet;
private final Map<String, String> name2ns;
private final Map<String, String> synonym2ns;
@@ -79,44 +96,70 @@
processSpecies(targetRow, speciesTargetFirst);
}
+ // Try to find hjuman-readable gene name
+ guessHumanReadableName(sourceRow);
+ guessHumanReadableName(targetRow);
}
public void mapEdgeColumn(final EncoreInteraction interaction, final
CyRow row) {
-
+
+ final Set<String> exp =
interaction.getExperimentToPubmed().keySet();
+ row.set(EXPERIMENT, new ArrayList<String>(exp));
+
+ final List<CrossReference> pubIDs =
interaction.getPublicationIds();
+ final List<String> pubIdList = new ArrayList<String>();
+ final List<String> pubDBList = new ArrayList<String>();
+ for (CrossReference pub : pubIDs) {
+ pubIdList.add(pub.getIdentifier());
+ pubDBList.add(pub.getDatabase());
+ }
+ if (pubIdList.isEmpty() == false)
+ row.set(PUB_ID, pubIdList);
+ if (pubDBList.isEmpty() == false)
+ row.set(PUB_DB, pubDBList);
+
// Interaction (use DB names)
row.set(CyEdge.INTERACTION, interaction.getMappingIdDbNames());
-
+
final List<Confidence> scores =
interaction.getConfidenceValues();
- for(Confidence c: scores) {
+ for (Confidence c : scores) {
String type = c.getType();
- String value =c.getValue();
-
+ String value = c.getValue();
+
if (row.getTable().getColumn(type) == null)
row.getTable().createColumn(type, Double.class,
true);
-
+
try {
double doubleVal = Double.parseDouble(value);
row.set(type, doubleVal);
- } catch(NumberFormatException e) {
- //logger.warn("Invalid number string: " +
value);
+ } catch (NumberFormatException e) {
+ // logger.warn("Invalid number string: " +
value);
// Ignore invalid number
}
-
+
}
-
+
}
private void processNames(CyRow row, final Map<String, String> accs) {
for (String originalDBName : accs.keySet()) {
-
+
final String dbName = validateNamespace(originalDBName);
-
+
if (row.getTable().getColumn(dbName) == null)
- row.getTable().createColumn(dbName,
String.class, true);
-
- row.set(dbName, accs.get(originalDBName));
+ row.getTable().createListColumn(dbName,
String.class, true);
+
+ List<String> currentList = row.getList(dbName,
String.class);
+ if (currentList == null)
+ currentList = new ArrayList<String>();
+
+ final Set<String> nameSet = new
HashSet<String>(currentList);
+
+ final String entry = accs.get(originalDBName);
+ nameSet.add(entry);
+
+ row.set(dbName, new ArrayList<String>(nameSet));
}
-
}
private void processOtherNames(CyRow row, final Map<String,
List<String>> accs) {
@@ -125,16 +168,16 @@
final String dbName = validateNamespace(originalDBName);
if (row.getTable().getColumn(dbName) == null)
- row.getTable().createColumn(dbName,
String.class, true);
+ row.getTable().createListColumn(dbName,
String.class, false);
+ List<String> currentList = row.getList(dbName,
String.class);
+ if (currentList == null)
+ currentList = new ArrayList<String>();
+
+ final Set<String> nameSet = new
HashSet<String>(currentList);
final List<String> names = accs.get(originalDBName);
- StringBuilder builder = new StringBuilder();
- for (String name : names) {
- builder.append(name + ",");
- }
- String longName = builder.toString();
- longName = longName.substring(0, longName.length() - 2);
- row.set(dbName, longName);
+ nameSet.addAll(names);
+ row.set(dbName, new ArrayList<String>(nameSet));
}
}
@@ -192,11 +235,11 @@
}
private String validateNamespace(final String columnName) {
-
+
// This is a hack for db's bug
- if(columnName.equals("entrezgene/locuslink"))
+ if (columnName.equals("entrezgene/locuslink"))
return "entrez gene/locuslink";
-
+
if (namespaceSet.contains(columnName.toLowerCase()))
return columnName;
@@ -210,4 +253,83 @@
return columnName;
}
+
+ 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 boolean findHumanReadableName(final CyRow row, final
List<String> attrList, Pattern pattern, boolean exist) {
+ String candidateString = null;
+ for (final String geneID : attrList) {
+ if (pattern.matcher(geneID).find() == exist) {
+ candidateString = geneID;
+ break;
+ }
+ }
+ if (candidateString != null) {
+ if(candidateString.contains("_")) {
+ final String firstPart =
candidateString.split("_")[0];
+ for(String candidate: attrList) {
+
if(candidate.equalsIgnoreCase(firstPart)) {
+ candidateString = firstPart;
+ break;
+ }
+ }
+
+ }
+ row.set(PREDICTED_GENE_NAME, candidateString);
+ return true;
+ }
+
+ return false;
+ }
}
Modified:
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/MergedNetworkBuilder.java
===================================================================
---
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/MergedNetworkBuilder.java
2012-07-27 00:30:23 UTC (rev 30015)
+++
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/MergedNetworkBuilder.java
2012-07-27 02:42:10 UTC (rev 30016)
@@ -42,7 +42,6 @@
public MergedNetworkBuilder(final CyNetworkFactory networkFactory) {
this.networkFactory = networkFactory;
mapper = new InteractionClusterMapper();
-
}
public CyNetwork buildNetwork(final InteractionCluster iC) throws
IOException {
@@ -50,28 +49,28 @@
process(iC, network, null, null);
return network;
}
-
- public Map<String, CyNode> addToNetwork(final InteractionCluster iC,
CyNetworkView networkView, final View<CyNode> hubNode) {
+
+ public Map<String, CyNode> addToNetwork(final InteractionCluster iC,
CyNetworkView networkView,
+ final View<CyNode> hubNode) {
return process(iC, networkView.getModel(), networkView,
hubNode);
}
-
- private final Map<String, CyNode> process(final InteractionCluster iC,
CyNetwork network, CyNetworkView netView, final View<CyNode> hubNode) {
+
+ private final Map<String, CyNode> process(final InteractionCluster iC,
CyNetwork network, CyNetworkView netView,
+ final View<CyNode> hubNode) {
nodeMap = new HashMap<String, CyNode>();
- if(hubNode != null) {
+ if (hubNode != null) {
nodeMap.put(network.getRow(hubNode.getModel()).get(CyNetwork.NAME,
String.class), hubNode.getModel());
- if(netView != null)
+ if (netView != null)
network.getRow(hubNode.getModel()).set(CyNetwork.SELECTED, true);
}
-
- if(network.getNodeCount() != 0) {
- for(CyNode existingNode: network.getNodeList())
+
+ if (network.getNodeCount() != 0) {
+ for (CyNode existingNode : network.getNodeList())
nodeMap.put(network.getRow(existingNode).get(CyNetwork.NAME, String.class),
existingNode);
}
-
- Map<Integer, EncoreInteraction> interactions =
iC.getInteractionMapping();
- Map<String, List<Integer>> interactorMapping =
iC.getInteractorMapping();
- Map<String, String> interactorSynonyms = iC.getSynonymMapping();
+ final Map<Integer, EncoreInteraction> interactions =
iC.getInteractionMapping();
+
prepareColumns(network);
for (final Integer interactionKey : interactions.keySet()) {
@@ -81,13 +80,13 @@
}
final EncoreInteraction interaction =
interactions.get(interactionKey);
-
+
final String source = interaction.getInteractorA();
CyNode sourceNode = nodeMap.get(source);
if (sourceNode == null) {
sourceNode = network.addNode();
network.getRow(sourceNode).set(CyNetwork.NAME,
source);
- if(netView != null)
+ if (netView != null)
network.getRow(sourceNode).set(CyNetwork.SELECTED, true);
nodeMap.put(source, sourceNode);
}
@@ -96,12 +95,12 @@
if (targetNode == null) {
targetNode = network.addNode();
network.getRow(targetNode).set(CyNetwork.NAME,
target);
- if(netView != null)
+ if (netView != null)
network.getRow(targetNode).set(CyNetwork.SELECTED, true);
nodeMap.put(target, targetNode);
}
mapper.mapNodeColumn(interaction,
network.getRow(sourceNode), network.getRow(targetNode));
-
+
final CyEdge newEdge = network.addEdge(sourceNode,
targetNode, true);
mapper.mapEdgeColumn(interaction,
network.getRow(newEdge));
}
@@ -118,6 +117,19 @@
nodeTable.createColumn(TAXNOMY_NAME, String.class,
false);
if (nodeTable.getColumn(TAXNOMY_DB) == null)
nodeTable.createColumn(TAXNOMY_DB, String.class, false);
+
+ // Prepare label column
+ if
(nodeTable.getColumn(InteractionClusterMapper.PREDICTED_GENE_NAME) == null)
+
nodeTable.createColumn(InteractionClusterMapper.PREDICTED_GENE_NAME,
String.class, false);
+
+ // Prepare edge column
+ if (edgeTable.getColumn(InteractionClusterMapper.PUB_DB) ==
null)
+
edgeTable.createListColumn(InteractionClusterMapper.PUB_DB, String.class,
false);
+ if (edgeTable.getColumn(InteractionClusterMapper.PUB_ID) ==
null)
+
edgeTable.createListColumn(InteractionClusterMapper.PUB_ID, String.class,
false);
+ if (edgeTable.getColumn(InteractionClusterMapper.EXPERIMENT) ==
null)
+
edgeTable.createListColumn(InteractionClusterMapper.EXPERIMENT, String.class,
false);
+
}
public void cancel() {
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.