Answers.Body: <p>I think the easiest way is to download the graph using <code>STRINGdb</code>.</p>
  
  
  
  <pre><code>library(STRINGdb)
  string_db &lt;- STRINGdb$new(version="10", species=9606,
                            score_threshold=400, input_directory="" )
  full.graph &lt;- string_db$get_graph()
  </code></pre>
  
  <p>Now you can use <a href="http://igraph.org/r/" rel="nofollow noreferrer"><code>igraph</code></a>, to manipulate the graph. Let's assume you want to take 200 proteins with the highest degree, i.e. number of edges they have.</p>
  
  
  
  <pre><code>library(igraph)
  
  # see how many proteins do you have    
  vcount(full.graph)
  
  # find top 200 proteins with the highest degree
  top.degree.verticies &lt;- names(tail(sort(degree(full.graph)), 200))
  
  # extract the relevant subgraph
  top.subgraph &lt;- induced_subgraph(full.graph, top.degree.verticies)
  
  # count the number of proteins in it
  vcount(top.subgraph)
  </code></pre>
  
  <p><strong>How to get disease specific genes?</strong></p>
  
  <p>There's no GO annotation for cancer or Alzheimer's disease. It is out of scope of the GO consortium.</p>
  
  <p>What you can do, you can either take KEGG Pathways annotation, or manually select list of relevant GO-terms. Or acquire the list from one of the papers. For example annotation term <code>05200</code> corresponds to the cancer KEGG pathway. You can easily retrieve proteins associated with the annotation:</p>
  
  
  
  <pre><code>cancer.pathway.proteins &lt;-
      string_db$get_term_proteins('05200')$STRING_id
  </code></pre>
  
  <p>And then perform subgraphing as described above.</p>
  
  <p>Alternatively you can try to get an enrichment score for an every gene given it's neighbors (the way enrichment is shown on the string-db website). Then you can keep only those having top enrichment scores. Probably <code>get_ppi_enrichment_full</code> or <code>get_ppi_enrichment</code> functions will help you to do that.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-31T11:29:57.047Z
Answers.Text: If we want to keep tumor , cancer , alzheimer data , I mean filtering by disease. can we do that ? knowing that we want to keep the maximum of nodes
Answers.UserDisplayName: A M
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-31T12:35:06.757Z
Answers.Text: @I'm getting errors Error in induced_subgraph(graph, top.degree.verticies) : Not a graph object
Answers.UserDisplayName: A M
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-31T12:38:47.913Z
Answers.Text: That's probably because `graph` is a function in `igraph` package. Make sure you're using a correct variable name.
Answers.UserDisplayName: Iakov Davydov
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-31T12:47:22.167Z
Answers.Text: is there a way to export the graph is csv ?
Answers.UserDisplayName: A M
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-31T12:57:36.223Z
Answers.Text: Please, check the very good documentation of the `igraph` package. You can export graph using `write_graph`. Also, as you can notice `STRINGdb` downloads the full graph to your computer, therefore you probably can download it directly from the database website.
Answers.UserDisplayName: Iakov Davydov
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-31T13:00:53.997Z
Answers.Text: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/59614/discussion-between-a-m-and-iakov-davydov).
Answers.UserDisplayName: A M
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-31T11:12:06.970Z
Answers.LastActivityDate: 2017-06-08T08:20:19.730Z
Answers.LastEditDate: 2017-06-08T08:20:19.730Z
Answers.UserDisplayName: Iakov Davydov
Body: <p>How can I manipulate protein-interaction network graph from the String database using <code>STRINGdb</code> bioconductor package and R?</p>
  
  <p>I have downloaded the whole graph for <em>Homo sapiens</em> from STRING, which has about 20.000 proteins.</p>
  
  <ol>
  <li>How do I read the file using that package? </li>
  <li>How do I filter things I don't need? Supposing that I want to keep tumor data, as an example.</li>
  </ol>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-30T12:17:13.207Z
Comments.Text: Cross-posted [on biostars](https://www.biostars.org/p/255227/)...again
Comments.UserDisplayName: Devon Ryan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-30T15:24:03.870Z
Comments.Text: I don't think it is a problem to cross-post. It would be good to post a link to the best answer on the other site when such an answer is defined.
Comments.UserDisplayName: bli
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-31T09:52:50.047Z
Comments.Text: @bli that what I'm going to do once an answer is found
Comments.UserDisplayName: A M
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-31T10:50:16.683Z
Comments.Text: That's the question how do I do to filter things I don't need I already downloaded the whole graph for homosapiens from the download section in STRING .
Comments.UserDisplayName: A M
Tags: <r><bioconductor><database><networks>
Title: How to manipulate protein interaction network from String database in R?
ThreadText: # How to manipulate protein interaction network from String database in R?
  
  (Asked by: username_0 on 2017-05-30)
  
  How can I manipulate protein-interaction network graph from the String database using `STRINGdb` bioconductor package and R?
  
  I have downloaded the whole graph for *Homo sapiens* from STRING, which has about 20.000 proteins.
  
  1. How do I read the file using that package?
  2. How do I filter things I don't need? Supposing that I want to keep tumor data, as an example.
  
  **Tags:** r, bioconductor, database, networks
  
  > **Comments:**
  > **username_1**: Cross-posted [on biostars](https://www.biostars.org/p/255227/)...again  
  > **username_2**: I don't think it is a problem to cross-post. It would be good to post a link to the best answer on the other site when such an answer is defined.  
  > **username_0**: @username_2 that what I'm going to do once an answer is found  
  > **username_0**: That's the question how do I do to filter things I don't need I already downloaded the whole graph for homosapiens from the download section in STRING .  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2017-05-31. Score: 4 | Accepted answer
  
  I think the easiest way is to download the graph using `STRINGdb`.
  
  ```
  library(STRINGdb)
  string_db <- STRINGdb$new(version="10", species=9606,
                            score_threshold=400, input_directory="" )
  full.graph <- string_db$get_graph()
  
  ```
  
  Now you can use [`igraph`](http://igraph.org/r/), to manipulate the graph. Let's assume you want to take 200 proteins with the highest degree, i.e. number of edges they have.
  
  ```
  library(igraph)
  
  # see how many proteins do you have    
  vcount(full.graph)
  
  # find top 200 proteins with the highest degree
  top.degree.verticies <- names(tail(sort(degree(full.graph)), 200))
  
  # extract the relevant subgraph
  top.subgraph <- induced_subgraph(full.graph, top.degree.verticies)
  
  # count the number of proteins in it
  vcount(top.subgraph)
  
  ```
  
  **How to get disease specific genes?**
  
  There's no GO annotation for cancer or Alzheimer's disease. It is out of scope of the GO consortium.
  
  What you can do, you can either take KEGG Pathways annotation, or manually select list of relevant GO-terms. Or acquire the list from one of the papers. For example annotation term `05200` corresponds to the cancer KEGG pathway. You can easily retrieve proteins associated with the annotation:
  
  ```
  cancer.pathway.proteins <-
      string_db$get_term_proteins('05200')$STRING_id
  
  ```
  
  And then perform subgraphing as described above.
  
  Alternatively you can try to get an enrichment score for an every gene given it's neighbors (the way enrichment is shown on the string-db website). Then you can keep only those having top enrichment scores. Probably `get_ppi_enrichment_full` or `get_ppi_enrichment` functions will help you to do that.
  
  > **Comments:**
  > **username_0**: If we want to keep tumor , cancer , alzheimer data , I mean filtering by disease. can we do that ? knowing that we want to keep the maximum of nodes  
  > **username_0**: @I'm getting errors Error in induced_subgraph(graph, top.degree.verticies) : Not a graph object  
  > **username_3**: That's probably because `graph` is a function in `igraph` package. Make sure you're using a correct variable name.  
  > **username_0**: is there a way to export the graph is csv ?  
  > **username_3**: Please, check the very good documentation of the `igraph` package. You can export graph using `write_graph`. Also, as you can notice `STRINGdb` downloads the full graph to your computer, therefore you probably can download it directly from the database website.  
  > **username_0**: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/59614/discussion-between-a-m-and-username_3-username_3).  
  
  ---
  
  