ChiLiubio / meconetcomp

Compare microbial co-occurrence networks based on the trans_network class of microeco package
GNU General Public License v3.0
4 stars 0 forks source link

Exporting node and edge tables #6

Open Madi784 opened 7 months ago

Madi784 commented 7 months ago

Hello,

I have trouble exporting the node and edge files. I assume that the node and edge tables are stored within the result network ($res_network) of each network in my DNA_network list. DNA_network is a list created by meconetcomp R package including my four networks. correct? after running these codes I get all node and edge files empty! Could you please take a look at the following codes and give me your thoughts on it?

output_directory <- ""

for (i in seq_along(DNA_network)) {

Get the current network

current_network <- DNA_network[[i]]

Extract the result network

result_network <- current_network$res_network

Extract node and edge tables from the result network

node_table <- result_network$node_table edge_table <- result_network$edge_table

Export node table to CSV

node_filename <- file.path(output_directory, paste0("node_table_network", i, ".csv")) write.csv(node_table, file = node_filename, row.names = FALSE)

Export edge table to CSV

edge_filename <- file.path(output_directory, paste0("edge_table_network", i, ".csv")) write.csv(edge_table, file = edge_filename, row.names = FALSE) }

ChiLiubio commented 7 months ago

Hi. The object name is wrong in your node_table and edge_table. For example, the result_network$node_table should be result_network$res_node_table. Generally, the object name has a prefix 'res_' for the quick input and prompt in Rstudio. A strategy is to check the first file before running the whole cycle.

Madi784 commented 7 months ago

Thank you for your response. I get blank csv files after changing the object name using the codes below.

for (i in seq_along(DNA_network)) {

Get the current network

current_network <- DNA_network[[i]]

Extract the result network

result_network <- current_network$res_network

Extract node and edge tables from the result network

node_table <- result_network$res_node_table edge_table <- result_network$res_edge_table

Export node table to CSV

node_filename <- file.path(output_directory, paste0("node_table_network", i, ".csv")) write.csv(node_table, file = node_filename, row.names = FALSE)

Export edge table to CSV

edge_filename <- file.path(output_directory, paste0("edge_table_network", i, ".csv")) write.csv(edge_table, file = edge_filename, row.names = FALSE) }

ChiLiubio commented 7 months ago

Hi. Your current_network is an R6 object, not the result_network. You should use current_network$res_node_table, not the result_network$res_node_table. Another thing is to make sure there is a res_node_table in your current_network. If not, first use get_node_table function to do that.

Madi784 commented 7 months ago

Thank you so much!