Extracting data from edgeR R package
2
2
Entering edit mode
4.6 years ago
Sara ▴ 240

I am using edgeR package in R and here the code I used

library(edgeR)
target <-read.delim("metadata.txt", header=T)
x <- read.csv('data4.txt', row.names = 1)
group <- factor(target$group)
design <- model.matrix(~0+group)

when I print the design variable I would get the following results:

> design
   group1 group2
1       1      0
2       1      0
3       0      1
4       1      0
5       0      1
6       1      0
7       1      0
8       1      0
9       0      1
10      0      1
11      1      0
12      0      1
attr(,"assign")
[1] 1 1
attr(,"contrasts")
attr(,"contrasts")$group
[1] "contr.treatment"

I would like to make a new variable called comparison like this:

comparison = "group1-group2"

I actually do not know how to do that because group1 and group2 are not headers or separated sections. do you guys know how to that?

R edgeR • 1.2k views
ADD COMMENT
1
Entering edit mode
4.6 years ago
zx8754 11k

Get the dimnames:

#example data
group <- factor(1:2)
design <- model.matrix(~0+group)
design 
#   group1 group2
# 1      1      0
# 2      0      1
# attr(,"assign")
# [1] 1 1
# attr(,"contrasts")
# attr(,"contrasts")$group
# [1] "contr.treatment"

paste(dimnames(design)[[2]], collapse = "-")
# [1] "group1-group2"
ADD COMMENT
0
Entering edit mode
4.6 years ago
russhh 5.7k

Hi are you trying to subtract the second column of the design from the first, you could do that with matrix manipulation: as.matrix(design) %*% c(1, -1). However, I suspect you're trying to define an experimental comparison (contrast) for use in the edgeR workflow. As such you're probably looking for limma::makeContrasts https://www.rdocumentation.org/packages/limma/versions/3.28.14/topics/makeContrasts ;

contrasts <- limma::makeContrasts(comparison = "group1 - group2", levels = design)
ADD COMMENT
0
Entering edit mode

@russhh: in your solution I have to type manually but I want to make "group1 - group2" automatically. because instead of "group1 - group2" I can have: "groupA- groupB".

ADD REPLY
0
Entering edit mode

Sorry, that wasn't clear

ADD REPLY

Login before adding your answer.

Traffic: 2574 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6