Answers.Body: <p>The simplest way is to calculate the correlation matrix of genes in the module you want and use that as input to <code>exportNetworkToCytoscape</code>. Something like this:</p>
  <pre class="lang-r prettyprint-override"><code>inMod = moduleColors==&quot;blue&quot;  ## replace 'blue' with the color or module label you want
  modExpr = datExpr[, inMod];
  modCor = cor(modExpr)
  cytoData = exportNetworkToCytoscape(modCor, threshold = 0, ...)
  ## Replace ... above with appropriate arguments
  </code></pre>
  <p>Then add the p-values to the edge data frame returned within <code>cytoData</code> using function <code>corPvalueStudent</code>, for example as</p>
  <pre class="lang-r prettyprint-override"><code>edgeDF = cytoData$edgeData
  nSamples = nrow(datExpr);
  edgeDF$pValue = corPvalueStudent(edgeDF$weight, nSamples)
  </code></pre>
  <p>You can then manipulate the correlations and p-values further as necessary, e.g. export them into a csv file.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-18T14:21:49.263Z
Answers.Text: Thank you,  @Peter. I will try your method, and if it works well, I'll come back to let you know. Thank you in advance.
Answers.UserDisplayName: Mozart
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-18T16:13:15.503Z
Answers.Text: @Mozart simply mark as "accepted" if this post has been helpful. This looks like good network theory BTW.
Answers.UserDisplayName: M__
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-18T18:06:06.427Z
Answers.Text: Thanks Peter, everything seems to work fine!
Answers.UserDisplayName: Mozart
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-18T14:04:10.937Z
Answers.LastActivityDate: 2024-02-19T15:55:01.820Z
Answers.LastEditDate: 2024-02-19T15:55:01.820Z
Answers.UserDisplayName: Peter Langfelder
Body: <p>I'm facing a challenge regarding the extraction of co-expressing genes from each module. After identifying modules, I've been using exportNetworkToCytoscape to visualize genes that co-express together. However, I solely seek the p-values of the co-expressed genes in each module, similar to the format below:</p>
  <pre><code>fromNode        toNode      corr-value      p-value
  ENSG234        ENSG567       0.90           0.001
  ENSG987        ENSG456       0.55           0.03
  </code></pre>
  <p>While the exported data provides useful information such as &quot;fromNode,&quot; &quot;toNode,&quot;  &quot;weight&quot;, it lacks the p-values (more important) and corr-value  I require for my analysis.</p>
  <p>I attempted to use tomSimilarityFromExpr with 'corType = &quot;pearson&quot;' to calculate pairwise correlations between genes, but I'm uncertain about the subsequent steps to obtain the desired p-values.
  My goal is to export the co-expression genes of each module, as facilitated by exportNetworkToCytoscape, while also having the corresponding p-values for these co-expressed genes within each module. I'm not interested in linking the modules to external variables; rather, I solely seek the p-values of the co-expressed genes in each module.</p>
  <p>Even if there is another way to obtain what I want without going through tomSimilarityFromExpr and exportNetworkToCytoscape, this suggestion would be welcome!</p>
  <p>Could you kindly offer guidance on how to proceed in obtaining this information?
  Thanks in advance!</p>
  
Tags: <r><wgcna>
Title: Extracting P-Values for Co-Expressed Genes Within WGCNA Modules
ThreadText: # Extracting P-Values for Co-Expressed Genes Within WGCNA Modules
  
  (Asked by: username_0 on 2024-02-18)
  
  I'm facing a challenge regarding the extraction of co-expressing genes from each module. After identifying modules, I've been using exportNetworkToCytoscape to visualize genes that co-express together. However, I solely seek the p-values of the co-expressed genes in each module, similar to the format below:
  
  ```
  fromNode        toNode      corr-value      p-value
  ENSG234        ENSG567       0.90           0.001
  ENSG987        ENSG456       0.55           0.03
  
  ```
  
  While the exported data provides useful information such as "fromNode," "toNode," "weight", it lacks the p-values (more important) and corr-value I require for my analysis.
  
  I attempted to use tomSimilarityFromExpr with 'corType = "pearson"' to calculate pairwise correlations between genes, but I'm uncertain about the subsequent steps to obtain the desired p-values.
  My goal is to export the co-expression genes of each module, as facilitated by exportNetworkToCytoscape, while also having the corresponding p-values for these co-expressed genes within each module. I'm not interested in linking the modules to external variables; rather, I solely seek the p-values of the co-expressed genes in each module.
  
  Even if there is another way to obtain what I want without going through tomSimilarityFromExpr and exportNetworkToCytoscape, this suggestion would be welcome!
  
  Could you kindly offer guidance on how to proceed in obtaining this information?
  Thanks in advance!
  
  **Tags:** r, wgcna
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-02-18. Score: 2 | Accepted answer
  
  The simplest way is to calculate the correlation matrix of genes in the module you want and use that as input to `exportNetworkToCytoscape`. Something like this:
  
  ```r
  inMod = moduleColors=="blue"  ## replace 'blue' with the color or module label you want
  modExpr = datExpr[, inMod];
  modCor = cor(modExpr)
  cytoData = exportNetworkToCytoscape(modCor, threshold = 0, ...)
  ## Replace ... above with appropriate arguments
  
  ```
  
  Then add the p-values to the edge data frame returned within `cytoData` using function `corPvalueStudent`, for example as
  
  ```r
  edgeDF = cytoData$edgeData
  nSamples = nrow(datExpr);
  edgeDF$pValue = corPvalueStudent(edgeDF$weight, nSamples)
  
  ```
  
  You can then manipulate the correlations and p-values further as necessary, e.g. export them into a csv file.
  
  > **Comments:**
  > **username_0**: Thank you,  @username_1. I will try your method, and if it works well, I'll come back to let you know. Thank you in advance.  
  > **username_2**: @username_0 simply mark as "accepted" if this post has been helpful. This looks like good network theory BTW.  
  > **username_0**: Thanks username_1, everything seems to work fine!  
  
  ---
  
  