Question: Filling expr matrix for igraph
0
gravatar for Spacebio
3.2 years ago by
Spacebio180
Spacebio180 wrote:

Hello,

I have a file containing 11300 genes, looking like this:

A   active      B
B   inactive    C
C   unknown     E
D   active      D
E   inactive    A
A   active      C
B   unknown     A
C   inactive    D
D   active      E
E   active      B

After I stack the genes, I get a matrix like this:

A   active
B   inactive
C   unknown
D   active
E   inactive
A   active
B   unknown
C   inactive
D   active
E   active
B   active
C   inactive
E   unknown
D   active
A   inactive
C   active
A   unknown
D   inactive
E   active
B   active

Then, I remove the duplicates and I get the following output:

A   active
B   inactive
C   unknown
D   active
E   inactive
B   unknown
C   inactive
E   active
B   active
E   unknown
A   inactive
C   active
A   unknown
D   inactive

After that, I would like to have a matrix like this:

    Active  Inactive    Unknown
A      1        1          1
B      1        1          1
C      1        1          1
D      1        1          0
E      1        1          1

I tried with the followong syntax:

m <- matrix(nrow = 1467, ncol = 4)
for(column in 1){
  m[, column] <- nodes$values
}

But with that I just construct the matrix without filling it. The 1467 is the total number of uniquegenes in my file. Can someone help me?

matrix igraph R • 751 views
ADD COMMENTlink modified 3.2 years ago by Michael Dondrup48k • written 3.2 years ago by Spacebio180
3
gravatar for Michael Dondrup
3.2 years ago by
Bergen, Norway
Michael Dondrup48k wrote:
> bla
   V1       V4
1   A   active
2   B inactive
3   C  unknown
4   D   active
5   E inactive
6   B  unknown
7   C inactive
8   E   active
9   B   active
10  E  unknown
11  A inactive
12  C   active
13  A  unknown
14  D inactive
> table(bla)
   V4
V1  active inactive unknown
  A      1        1       1
  B      1        1       1
  C      1        1       1
  D      1        1       0
  E      1        1       1
ADD COMMENTlink modified 3.2 years ago • written 3.2 years ago by Michael Dondrup48k

Thank you so much! I hate when the answer is so obvious that makes me feel dumb.

ADD REPLYlink written 3.2 years ago by Spacebio180
1
gravatar for cpad0112
3.2 years ago by
cpad011214k
Hyderabad India
cpad011214k wrote:

with datamash:

$ datamash crosstab 1,2 --filler 0 < file.txt 
    active  inactive    unknown
A   1   1   1
B   1   1   1
C   1   1   1
D   1   1   0
E   1   1   1

input:

$ cat file.txt 
A   active
B   inactive
C   unknown
D   active
E   inactive
B   unknown
C   inactive
E   active
B   active
E   unknown
A   inactive
C   active
A   unknown
D   inactive
ADD COMMENTlink modified 3.2 years ago • written 3.2 years ago by cpad011214k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2070 users visited in the last hour
_