How can we convert a .gr graph file to a .cm graph file?

Viewed 71

I was working on a graph file with .gr extension and came across a relevant dataset with .cm extension. My code is compatible with .gr extension but I wish to use .cm dataset.

Problem: I do not understand the format in which data is represented and thus cannot parse it. In some files there is even text instead of numbers.

The dataset represents protein molecules.

Question: How to parse .cm file into .gr file and how is data represented in .cm file?

This is the content of one of the .cm graph file describing a graph:

5
8
0
1
7
9
-1  -1  -1  1   
1   -1  -1  
1   -1  
1   

Now how to figure out the number of nodes and the edges present in this graph.

This is the content of a .gr file extension.

p cep 4 3
1 2
1 3
1 4
2 Answers

In cm file, which is short for cluster matrix file, the first number denotes the total number of nodes.

The following n lines denote the labels (hence the string) of the nodes.

The matrix then denotes the cost to add an edge between two nodes. Note that the first cell (row=0, column=0) in the matrix denote that the cost to add edge between node n and node n-1. The second cell (row=0, column=1) in the matrix denote the cost to add edge between node n and node n-2 and so on.

-1  -1  -1  1   
1   -1  -1  
1   -1  
1  

This looks like it might be describing a 4 node graph.

but this

5
8
0
1
7
9

looks like something to do with a graph of 6 nodes.

Related