Is it possible to calculate expression matrix in R for further use in Cytoscape?

49 Views Asked by At

I have a table containing Fold change data for genes in three conditions (Samples). my data is:

> dput(df2)
structure(list(Samples = c("A-1", "A-2", "A-4", "B-1", "B-2", 
"B-4", "C-1", "C-2", "C-4"), gene1 = c(1.92240792088036, 1.87118633447253, 
1.94158574768122, 0.743982725531221, 0.986224813365175, 0.476215748248648, 
0.731490064245346, 0.596064876825191, 0.571791594329927), gene2 = c(1.38762620120341, 
4.66680898951508, 2.87307760165737, 0.998905293967859, 1.58490494045631, 
1.07311974444822, 4.88661528392309, 3.35118753924545, 6.52812574494532
), gene3 = c(2.75218521855555, 1.96606424938052, 1.26134206679715, 
0.248847419775807, 0.216994140810077, 0.381075639652472, 0.614240099166926, 
0.346259723181132, 0.501984000812794)), class = c("tbl_df", "tbl", 
"data.frame"), row.names = c(NA, -9L))

I want to calculate correlation matrix and p-value in R and then import it to Cytoscape for expression correlation task.

I use the following code:

# Transpose the data frame
transposed_df <- t(df)

# Convert row names to a column
transposed_df <- data.frame(Condition = rownames(transposed_df), transposed_df)

# Make the 'Condition' column as row names
rownames(transposed_df) <- transposed_df$Condition

# Remove the 'Condition' column
transposed_df$Condition <- NULL

# Save the transposed data frame as a .csv file
write.xlsx(transposed_df, file = "TransposedDataFrame.xlsx")

# Calculate the correlation matrix
correlation_matrix <- cor(transposed_df, method = "spearman")

But, But I am facing the following error:

Error in cor(transposed_df, method = "spearman") : 'x' must be numeric

1

There are 1 best solutions below

0
AlexanderPico On

Here's a workflow that performs correlated gene expression and Cytoscape visualization all in a single R script: https://cytoscape.org/cytoscape-automation/for-scripters/R/notebooks/Top-genes-and-coexpression.nb.html.