Converting Adjacency Matrices to Edge Lists in R

From OpenWetWare
Revision as of 13:08, 9 March 2016 by Tessa A. Morris (talk | contribs) (Undo revision 933934 by Tessa A. Morris (Talk))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

This page provides a script that can be used in the statistical software R to convert adjacency matrices to edge lists. The tutorial below applies this script to a specific case for GRNmap.

Formatting the Data for R

  1. Open the GRNmap output sheet.
  2. Navigate to the worksheet entitled "network_optimized_weights".
  3. Delete the text in cell A1 (cols regulators/rows targets).
  4. Save the worksheet as a "Tab Delimited Text (.txt)" file.
    • In the first warning window that this triggers, select "Save Active Sheet".
    • In the second warning window, select "Continue".

Running the Script

This script relies on commands present in the R package igraph. To download this package, complete the following steps:

  1. Run the software R.
  2. Type the following into the R command line and press enter:
install.packages("igraph")
  • This should automatically install igraph. If it does not, the package can be manually selected from the menu triggered by the command: install.packages().

With igraph installed, the script will now be able to work as intended. Download the script from this GitHub page. To do so, right-click on the "Raw" button above the code and select "Download Linked File As..." to save this script as a text file. To use the script, follow these steps:

  1. Type the following into the R command line and press enter:
     souce("pathway to script .txt file") 
  2. This will trigger the prompt "Provide a Pathway to the Adjacency Matrix:". In the command line, type in the pathway to the .txt file containing the adjacency matrix to be converted to an edge list (this can be done manually, or by dragging the .txt file icon into the R command line) and press enter.
  3. R will output the resultant edge list. This information will be saved to a .csv file the name "Edge Weights" followed by a unique timestamp in the form "YYYYMMDD_hh.mm.ss". File saved under your R working directory (to determine where this is, use the command getwd).