Author: kono
Date: 2011-05-04 15:27:29 -0700 (Wed, 04 May 2011)
New Revision: 24928
Modified:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/quickstart/subnetworkbuilder/CreateSubnetworkTask.java
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/quickstart/subnetworkbuilder/NCBISearchClient.java
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/quickstart/subnetworkbuilder/SearchRelatedGenesTask.java
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/quickstart/subnetworkbuilder/NCBISearchClientTest.java
Log:
First version supporting other ID sets (gene symbol/ensemble) in subnetwork
builder.
Modified:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/quickstart/subnetworkbuilder/CreateSubnetworkTask.java
===================================================================
---
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/quickstart/subnetworkbuilder/CreateSubnetworkTask.java
2011-05-04 21:33:15 UTC (rev 24927)
+++
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/quickstart/subnetworkbuilder/CreateSubnetworkTask.java
2011-05-04 22:27:29 UTC (rev 24928)
@@ -1,7 +1,10 @@
package org.cytoscape.task.internal.quickstart.subnetworkbuilder;
+import java.io.IOException;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Set;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode;
@@ -9,99 +12,129 @@
import org.cytoscape.model.CyTableEntry;
import org.cytoscape.model.events.RowsAboutToChangeEvent;
import org.cytoscape.model.events.RowsFinishedChangingEvent;
+import org.cytoscape.task.internal.quickstart.IDType;
import org.cytoscape.task.internal.select.SelectFirstNeighborsTask;
import org.cytoscape.work.AbstractTask;
import org.cytoscape.work.Task;
import org.cytoscape.work.TaskMonitor;
import org.cytoscape.work.Tunable;
+import org.cytoscape.work.util.ListSingleSelection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CreateSubnetworkTask extends AbstractTask {
- private static final Logger logger =
LoggerFactory.getLogger(CreateSubnetworkTask.class);
+ private static final Logger logger =
LoggerFactory.getLogger(CreateSubnetworkTask.class);
- static final String QUERY_GENE_ATTR_NAME = "Gene Type";
- static final String SEARCH_GENE_ATTR_NAME = "Search Term";
+ static final String QUERY_GENE_ATTR_NAME = "Gene Type";
+ static final String SEARCH_GENE_ATTR_NAME = "Search Term";
- @Tunable(description = "Enter list of genes you are interested in (NCBI
Entrez Gene ID)")
- public String queryGenes;
+ @Tunable(description = "Enter list of genes you are interested in
(should be separated by space)")
+ public String queryGenes;
- private final SubnetworkBuilderUtil util;
- private final SubnetworkBuilderState state;
+ @Tunable(description = "Select ID Type")
+ public ListSingleSelection<IDType> selection = new
ListSingleSelection<IDType>(IDType.GENE_SYMBOL, IDType.ENSEMBL,
+ IDType.ENTREZ_GENE, IDType.UNIPROT);
- CreateSubnetworkTask(final SubnetworkBuilderUtil util, final
SubnetworkBuilderState state) {
- this.util = util;
- this.state = state;
- }
+ private final SubnetworkBuilderUtil util;
+ private final SubnetworkBuilderState state;
- @Override
- public void run(TaskMonitor taskMonitor) throws Exception {
- taskMonitor.setStatusMessage("Searching related genes in parent
network...");
- taskMonitor.setProgress(0.0);
- final String[] genes = queryGenes.split("\\s+");
- logger.debug("Got gene list: " + genes.length);
- for (final String gene : genes) {
- logger.debug("Gene: " + gene);
+ CreateSubnetworkTask(final SubnetworkBuilderUtil util, final
SubnetworkBuilderState state) {
+ this.util = util;
+ this.state = state;
}
- selectGenes(genes);
-
- taskMonitor.setProgress(1.0);
+ @Override
+ public void run(TaskMonitor taskMonitor) throws Exception {
+ taskMonitor.setStatusMessage("Searching related genes in parent
network...");
+ taskMonitor.setProgress(-1);
- }
+ final IDType selected = selection.getSelectedValue();
- private void selectGenes(final String[] genes) {
- final CyNetwork target = util.appManager.getCurrentNetwork();
- final CyTable nodeTable = target.getDefaultNodeTable();
+ final List<String> geneList;
+
+ if (selected == IDType.ENTREZ_GENE) {
+ final String[] genes = queryGenes.split("\\s+");
+ logger.debug("Got gene list: " + genes.length);
+ for (final String gene : genes) {
+ logger.debug("Gene: " + gene);
+ }
+ geneList = Arrays.asList(genes);
+ } else {
+ geneList = new ArrayList<String>(convert(selected));
+ }
- if (nodeTable.getColumn(QUERY_GENE_ATTR_NAME) == null)
- nodeTable.createColumn(QUERY_GENE_ATTR_NAME, String.class, false);
- if (nodeTable.getColumn(SEARCH_GENE_ATTR_NAME) == null)
- nodeTable.createColumn(SEARCH_GENE_ATTR_NAME, String.class, false);
+
+ selectGenes(geneList);
- boolean found = false;
- final List<String> geneList = Arrays.asList(genes);
- try {
- util.eventHelper.fireSynchronousEvent(new
RowsAboutToChangeEvent(this, nodeTable));
+ taskMonitor.setProgress(1.0);
- List<CyNode> nodeList = target.getNodeList();
- for (final CyNode node : nodeList) {
- final String nodeName = node.getCyRow().get(CyTableEntry.NAME,
String.class);
-
- if(geneList.contains(nodeName) &&
state.getDiseaseGenes().contains(nodeName)) {
- node.getCyRow().set(CyNetwork.SELECTED, true);
- node.getCyRow().set(QUERY_GENE_ATTR_NAME, "query and
disease");
- node.getCyRow().set(SEARCH_GENE_ATTR_NAME,
state.getSearchTerms());
- found = true;
- } else if (geneList.contains(nodeName)) {
- node.getCyRow().set(CyNetwork.SELECTED, true);
- node.getCyRow().set(QUERY_GENE_ATTR_NAME, "query");
- found = true;
- } else if (state.getDiseaseGenes().contains(nodeName)) {
- node.getCyRow().set(CyNetwork.SELECTED, true);
- node.getCyRow().set(QUERY_GENE_ATTR_NAME, "disease");
- node.getCyRow().set(SEARCH_GENE_ATTR_NAME,
state.getSearchTerms());
- }
- }
- } finally {
- util.eventHelper.fireSynchronousEvent(new
RowsFinishedChangingEvent(this, nodeTable));
}
- if (!found) {
- logger.error("Query genes were not found in the interactome.");
- return;
+ private Set<String> convert(IDType selected) throws IOException {
+ final boolean isGeneSymbol;
+
+ if (selected == IDType.GENE_SYMBOL)
+ isGeneSymbol = true;
+ else
+ isGeneSymbol = false;
+
+ final NCBISearchClient client = new NCBISearchClient();
+
+ return client.convert(queryGenes, isGeneSymbol);
}
- this.insertTasksAfterCurrentTask(new BuildVisualStyleTask(util));
-
- this.insertTasksAfterCurrentTask(util.getApplLayoutTask());
-
- Task createNetworkTask =
util.getNewNetworkSelectedNodesOnlyTask(target);
- this.insertTasksAfterCurrentTask(createNetworkTask);
+ private void selectGenes(final List<String> geneList) {
+ final CyNetwork target = util.appManager.getCurrentNetwork();
+ final CyTable nodeTable = target.getDefaultNodeTable();
- SelectFirstNeighborsTask nextTask = new
SelectFirstNeighborsTask(target, util.networkViewManager,
- util.eventHelper);
- this.insertTasksAfterCurrentTask(nextTask);
- }
+ if (nodeTable.getColumn(QUERY_GENE_ATTR_NAME) == null)
+ nodeTable.createColumn(QUERY_GENE_ATTR_NAME,
String.class, false);
+ if (nodeTable.getColumn(SEARCH_GENE_ATTR_NAME) == null)
+ nodeTable.createColumn(SEARCH_GENE_ATTR_NAME,
String.class, false);
+
+ boolean found = false;
+
+ try {
+ util.eventHelper.fireSynchronousEvent(new
RowsAboutToChangeEvent(this, nodeTable));
+
+ List<CyNode> nodeList = target.getNodeList();
+ for (final CyNode node : nodeList) {
+ final String nodeName =
node.getCyRow().get(CyTableEntry.NAME, String.class);
+
+ if (geneList.contains(nodeName) &&
state.getDiseaseGenes().contains(nodeName)) {
+ node.getCyRow().set(CyNetwork.SELECTED,
true);
+
node.getCyRow().set(QUERY_GENE_ATTR_NAME, "query and disease");
+
node.getCyRow().set(SEARCH_GENE_ATTR_NAME, state.getSearchTerms());
+ found = true;
+ } else if (geneList.contains(nodeName)) {
+ node.getCyRow().set(CyNetwork.SELECTED,
true);
+
node.getCyRow().set(QUERY_GENE_ATTR_NAME, "query");
+ found = true;
+ } else if
(state.getDiseaseGenes().contains(nodeName)) {
+ node.getCyRow().set(CyNetwork.SELECTED,
true);
+
node.getCyRow().set(QUERY_GENE_ATTR_NAME, "disease");
+
node.getCyRow().set(SEARCH_GENE_ATTR_NAME, state.getSearchTerms());
+ }
+ }
+ } finally {
+ util.eventHelper.fireSynchronousEvent(new
RowsFinishedChangingEvent(this, nodeTable));
+ }
+
+ if (!found) {
+ logger.error("Query genes were not found in the
interactome.");
+ return;
+ }
+
+ this.insertTasksAfterCurrentTask(new
BuildVisualStyleTask(util));
+
+ this.insertTasksAfterCurrentTask(util.getApplLayoutTask());
+
+ Task createNetworkTask =
util.getNewNetworkSelectedNodesOnlyTask(target);
+ this.insertTasksAfterCurrentTask(createNetworkTask);
+
+ SelectFirstNeighborsTask nextTask = new
SelectFirstNeighborsTask(target, util.networkViewManager,
+ util.eventHelper);
+ this.insertTasksAfterCurrentTask(nextTask);
+ }
}
Modified:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/quickstart/subnetworkbuilder/NCBISearchClient.java
===================================================================
---
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/quickstart/subnetworkbuilder/NCBISearchClient.java
2011-05-04 21:33:15 UTC (rev 24927)
+++
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/quickstart/subnetworkbuilder/NCBISearchClient.java
2011-05-04 22:27:29 UTC (rev 24928)
@@ -2,6 +2,7 @@
import java.io.IOException;
import java.io.InputStream;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;
@@ -10,83 +11,122 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class NCBISearchClient {
+
+ private static final Logger logger =
LoggerFactory.getLogger(NCBISearchClient.class);
- private static final String BASE_URL =
"http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=gene&retmax=100000&term=";
+ private static final String BASE_URL =
"http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=gene&retmax=100000&term=";
- private static final String DISEASE = "[dis]";
- private static final String GO = "[gene%20ontology]";
+ private static final String DISEASE = "[dis]";
+ private static final String GO = "[gene%20ontology]";
+ private static final String OFFICIAL_SYMBOL = "[sym]";
- private static final String SEPARATOR = ",";
+ private static final String SEPARATOR = ",";
- Set<String> search(final String disease, final String go) throws
IOException {
+ Set<String> search(final String disease, final String go) throws
IOException {
- final URL url = createURL(disease, go);
+ final URL url = createURL(disease, go);
- try {
- final Set<String> result = getIDSet(url);
- return result;
- } catch (Exception e) {
- throw new IOException("Could not parse the result.", e);
+ try {
+ final Set<String> result = getIDSet(url);
+ return result;
+ } catch (Exception e) {
+ throw new IOException("Could not parse the result.", e);
+ }
}
- }
+
+ Set<String> convert(final String idList, boolean isSymbol) throws
IOException {
+ final URL url = createURLForIDConversion(idList, isSymbol);
- private URL createURL(final String disease, final String go) throws
IOException {
- final String[] dTerms = disease.split(SEPARATOR);
- final String[] gTerms = go.split(SEPARATOR);
+ try {
+ final Set<String> result = getIDSet(url);
+ return result;
+ } catch (Exception e) {
+ throw new IOException("Could not parse the result.", e);
+ }
+ }
+
+ private URL createURLForIDConversion(final String idList, boolean
isSymbol) throws IOException {
+ final String[] ids = idList.split("\\s+");
+
+ if(ids == null || ids.length == 0)
+ throw new IllegalArgumentException("Could not find
ID.");
+
+ final StringBuilder builder = new StringBuilder();
+ for (String id : ids) {
+ final String trimed = id.trim();
+ if(isSymbol)
+ builder.append(trimed + OFFICIAL_SYMBOL +
"+OR+");
+ else
+ builder.append(trimed + "+OR+");
+ }
+
+ String urlString = BASE_URL + builder.toString();
+ urlString = urlString.substring(0, urlString.length() - 4);
+
+ System.out.println("URL = " + urlString);
+
+ return new URL(urlString);
+ }
- StringBuilder builder = new StringBuilder();
+ private URL createURL(final String disease, final String go) throws
IOException {
+ final String[] dTerms = disease.split(SEPARATOR);
+ final String[] gTerms = go.split(SEPARATOR);
- if (dTerms.length != 0) {
- for (String dTerm : dTerms) {
- final String trimed = dTerm.trim();
- builder.append(trimed.replaceAll("\\s", "+"));
- builder.append(DISEASE + "+OR+");
- }
- }
+ StringBuilder builder = new StringBuilder();
- String urlString = BASE_URL + builder.toString();
+ if (dTerms.length != 0) {
+ for (String dTerm : dTerms) {
+ final String trimed = dTerm.trim();
+ builder.append(trimed.replaceAll("\\s", "+"));
+ builder.append(DISEASE + "+OR+");
+ }
+ }
- builder = new StringBuilder();
+ String urlString = BASE_URL + builder.toString();
- if (gTerms.length != 0) {
- for (String gTerm : gTerms) {
- final String trimed = gTerm.trim();
- builder.append(trimed.replaceAll("\\s", "+"));
- builder.append(GO + "+OR+");
- }
+ builder = new StringBuilder();
+
+ if (gTerms.length != 0) {
+ for (String gTerm : gTerms) {
+ final String trimed = gTerm.trim();
+ builder.append(trimed.replaceAll("\\s", "+"));
+ builder.append(GO + "+OR+");
+ }
+ }
+
+ urlString = urlString + builder.toString();
+ urlString = urlString.substring(0, urlString.length() - 4);
+ return new URL(urlString);
}
- urlString = urlString + builder.toString();
- urlString = urlString.substring(0, urlString.length() - 4);
- return new URL(urlString);
- }
+ private Set<String> getIDSet(final URL url) throws
ParserConfigurationException, IOException, SAXException {
- private Set<String> getIDSet(final URL url) throws
ParserConfigurationException, IOException, SAXException {
+ final DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
+ final DocumentBuilder builder = factory.newDocumentBuilder();
+ InputStream is = url.openStream();
- final DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
- final DocumentBuilder builder = factory.newDocumentBuilder();
- InputStream is = url.openStream();
+ final Document result = builder.parse(is);
- final Document result = builder.parse(is);
+ final Set<String> idSet = new HashSet<String>();
+ final NodeList ids = result.getElementsByTagName("Id");
+ final int dataSize = ids.getLength();
- final Set<String> idSet = new HashSet<String>();
- final NodeList ids = result.getElementsByTagName("Id");
- final int dataSize = ids.getLength();
+ for (int i = 0; i < dataSize; i++) {
+ Node id = ids.item(i);
+ idSet.add(id.getTextContent());
+ }
- for (int i = 0; i < dataSize; i++) {
- Node id = ids.item(i);
- idSet.add(id.getTextContent());
+ is.close();
+ is = null;
+
+ return idSet;
}
-
- is.close();
- is = null;
-
- return idSet;
- }
}
Modified:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/quickstart/subnetworkbuilder/SearchRelatedGenesTask.java
===================================================================
---
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/quickstart/subnetworkbuilder/SearchRelatedGenesTask.java
2011-05-04 21:33:15 UTC (rev 24927)
+++
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/quickstart/subnetworkbuilder/SearchRelatedGenesTask.java
2011-05-04 22:27:29 UTC (rev 24928)
@@ -10,36 +10,36 @@
public class SearchRelatedGenesTask extends AbstractTask {
- private static final Logger logger =
LoggerFactory.getLogger(SearchRelatedGenesTask.class);
+ private static final Logger logger =
LoggerFactory.getLogger(SearchRelatedGenesTask.class);
- @Tunable(description = "Gene Ontology")
- public String go;
+ @Tunable(description = "Gene Ontology")
+ public String go;
- @Tunable(description = "Disease/Phynotype")
- public String phynotype;
+ @Tunable(description = "Disease/Phynotype")
+ public String phynotype;
- private final SubnetworkBuilderState state;
- private final SubnetworkBuilderUtil util;
+ private final SubnetworkBuilderState state;
+ private final SubnetworkBuilderUtil util;
- SearchRelatedGenesTask(final SubnetworkBuilderUtil util, final
SubnetworkBuilderState state) {
- this.state = state;
- this.util = util;
- }
+ SearchRelatedGenesTask(final SubnetworkBuilderUtil util, final
SubnetworkBuilderState state) {
+ this.state = state;
+ this.util = util;
+ }
- @Override
- public void run(TaskMonitor tm) throws Exception {
- tm.setStatusMessage("Searching NCBI Gene Database...");
+ @Override
+ public void run(TaskMonitor tm) throws Exception {
+ tm.setStatusMessage("Searching NCBI Gene Database...");
- tm.setProgress(0.0);
-
- insertTasksAfterCurrentTask(new CreateSubnetworkTask(util, state));
-
- final NCBISearchClient client = new NCBISearchClient();
+ tm.setProgress(0.0);
- final Set<String> idSet = client.search(phynotype, go);
- state.setDiseaseGenes(idSet);
- state.setSearchTerms(phynotype + "," + go);
-
- logger.info("NCBI Gene database returns " + idSet.size() + " gene
IDs.");
- }
+ insertTasksAfterCurrentTask(new CreateSubnetworkTask(util,
state));
+
+ final NCBISearchClient client = new NCBISearchClient();
+
+ final Set<String> idSet = client.search(phynotype, go);
+ state.setDiseaseGenes(idSet);
+ state.setSearchTerms(phynotype + "," + go);
+
+ logger.info("NCBI Gene database returns " + idSet.size() + "
gene IDs.");
+ }
}
Modified:
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/quickstart/subnetworkbuilder/NCBISearchClientTest.java
===================================================================
---
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/quickstart/subnetworkbuilder/NCBISearchClientTest.java
2011-05-04 21:33:15 UTC (rev 24927)
+++
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/quickstart/subnetworkbuilder/NCBISearchClientTest.java
2011-05-04 22:27:29 UTC (rev 24928)
@@ -10,34 +10,54 @@
public class NCBISearchClientTest {
- private NCBISearchClient client;
+ private NCBISearchClient client;
- @Before
- public void setUp() throws Exception {
- client = new NCBISearchClient();
- }
+ @Before
+ public void setUp() throws Exception {
+ client = new NCBISearchClient();
+ }
- @After
- public void tearDown() throws Exception {
- }
+ @After
+ public void tearDown() throws Exception {
+ }
- @Test
- public void testSearchClient() throws Exception {
+ @Test
+ public void testSearchClient() throws Exception {
- final String disease = "Rheumatoid Arthritis";
- final String go1 = "neurogenesis";
- final String go2 = "Rho GTPase activity";
-
- // Enable this for client test.
-// final Set<String> result1 = client.search(disease, go1);
-//
-// assertNotNull(result1);
-// assertEquals(322, result1.size());
-//
-// final Set<String> result2 = client.search(disease, go1 + ", " + go2);
-//
-// assertNotNull(result2);
-// assertEquals(391, result2.size());
- }
+ final String disease = "Rheumatoid Arthritis";
+ final String go1 = "neurogenesis";
+ final String go2 = "Rho GTPase activity";
+ // Enable this for client test.
+ // final Set<String> result1 = client.search(disease, go1);
+ //
+ // assertNotNull(result1);
+ // assertEquals(322, result1.size());
+ //
+ // final Set<String> result2 = client.search(disease, go1 + ",
" + go2);
+ //
+ // assertNotNull(result2);
+ // assertEquals(391, result2.size());
+ }
+
+ @Test
+ public void testIDConversion() throws Exception {
+
+ final String symbols = "yap1 yap2 yap3";
+ final String symbols2 = "YGL122C YGL097W YOR204W YPR080W
YBR118W YGL097W YDR429C YFL017C " +
+ "YAL003W YAL003W YGL044C YGR014W YGL229C
YGL229C YOL123W YJL030W YJL013C YIL061C " +
+ "YBR112C YCL067C YOR167C YNR050C YNL050C
YEL015W YOR167C YLR264W YNR053C YDL013W " +
+ "YAL038W YCR012W YGR254W YHR174W YIL133C
YLR044C YOL120C YNL301C YCL030C YDR171W " +
+ "YBR093C YER074W YIL069C YAL038W YOL127W
YDR050C YOL086C YER143W";
+
+ final Set<String> result1 = client.convert(symbols, true);
+ final Set<String> result2= client.convert(symbols2, true);
+
+ System.out.println("Value = " + result1.size());
+ System.out.println("Value = " + result2.size());
+
+ assertNotNull(result1);
+
+ }
+
}
--
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.