Skip to content

Commit af65216

Browse files
rMATS processing function receiving one-group tables
1 parent b943ee4 commit af65216

1 file changed

Lines changed: 57 additions & 24 deletions

File tree

R/processrMATS.R

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,30 +53,63 @@ filterrMATS <- function(incTable){
5353
# Remove "\"" from some gene symbols (probably not needed if read.table/read.delim is done with quote = "\"")
5454
commonCols$geneSymbol <- gsub(pattern = "\"", replacement = "", x = commonCols$geneSymbol)
5555

56-
# Infer number of samples from the first row in "SJC columns" by summing 1 to the number of ","
57-
Nsamples_Group1 <- length(gregexpr(",", incTable$SJC_SAMPLE_1[1], fixed = TRUE)[[1]])+1
58-
Nsamples_Group2 <- length(gregexpr(",", incTable$SJC_SAMPLE_2[1], fixed = TRUE)[[1]])+1
59-
60-
# Name samples from groups 1 and 2
61-
Samples_Group1 <- paste0("G1_S",1:Nsamples_Group1)
62-
Samples_Group2 <- paste0("G2_S",1:Nsamples_Group2)
63-
64-
# psiTable
65-
psiRM <- cbind(commonCols,
66-
apply(matrix(unlist(strsplit(incTable$IncLevel1, ",")),ncol=Nsamples_Group1,byrow=T), 2, as.numeric),
67-
apply(matrix(unlist(strsplit(incTable$IncLevel2, ",")),ncol=Nsamples_Group2,byrow=T), 2, as.numeric))
68-
colnames(psiRM) <- c("GENE","EVENT","COORD","LENGTH","FullCO","COMPLEX",Samples_Group1,Samples_Group2)
69-
70-
# qualTable
71-
inc <- cbind(apply(matrix(unlist(strsplit(incTable$IJC_SAMPLE_1, ",")),ncol=Nsamples_Group1,byrow=T), 2, as.numeric)/incTable$IncFormLen,
72-
apply(matrix(unlist(strsplit(incTable$IJC_SAMPLE_2, ",")),ncol=Nsamples_Group1,byrow=T), 2, as.numeric)/incTable$IncFormLen)
73-
exc <- cbind(apply(matrix(unlist(strsplit(incTable$SJC_SAMPLE_1, ",")),ncol=Nsamples_Group1,byrow=T), 2, as.numeric)/incTable$SkipFormLen,
74-
apply(matrix(unlist(strsplit(incTable$SJC_SAMPLE_2, ",")),ncol=Nsamples_Group1,byrow=T), 2, as.numeric)/incTable$SkipFormLen)
75-
76-
qualRM <- cbind(commonCols,
77-
# Mimicking vast-tools INCLUSION table ".Q" columns to facilitate the compatibility with other betAS functions
78-
matrix(paste0("A,A,0=0=0,A,",rep(eventType,nrow(incTable)),"@", inc , ",", exc ), nrow = nrow(inc)))
79-
colnames(qualRM) <- c("GENE","EVENT","COORD","LENGTH","FullCO","COMPLEX",paste0(Samples_Group1,".Q"),paste0(Samples_Group2,".Q"))
56+
# Check if rMATS table was done with one or two groups
57+
if(all(is.na(c(incTable$IncLevel2, incTable$IJC_SAMPLE_2, incTable$SJC_SAMPLE_2)))){
58+
59+
# If Group2 does not exist in rMATS table:
60+
# ::::::::::::::::::::::::::::::::::::::::
61+
62+
# Infer number of samples from the first row in "SJC columns" by summing 1 to the number of ","
63+
Nsamples_Group1 <- length(gregexpr(",", incTable$SJC_SAMPLE_1[1], fixed = TRUE)[[1]])+1
64+
65+
# Name samples from groups 1 and 2
66+
Samples_Group1 <- paste0("G1_S",1:Nsamples_Group1)
67+
68+
# psiTable
69+
psiRM <- cbind(commonCols,
70+
apply(matrix(unlist(strsplit(incTable$IncLevel1, ",")),ncol=Nsamples_Group1,byrow=T), 2, as.numeric))
71+
colnames(psiRM) <- c("GENE","EVENT","COORD","LENGTH","FullCO","COMPLEX",Samples_Group1)
72+
73+
# qualTable
74+
inc <- cbind(apply(matrix(unlist(strsplit(incTable$IJC_SAMPLE_1, ",")),ncol=Nsamples_Group1,byrow=T), 2, as.numeric)/incTable$IncFormLen)
75+
exc <- cbind(apply(matrix(unlist(strsplit(incTable$SJC_SAMPLE_1, ",")),ncol=Nsamples_Group1,byrow=T), 2, as.numeric)/incTable$SkipFormLen)
76+
77+
qualRM <- cbind(commonCols,
78+
# Mimicking vast-tools INCLUSION table ".Q" columns to facilitate the compatibility with other betAS functions
79+
matrix(paste0("A,A,0=0=0,A,",rep(eventType,nrow(incTable)),"@", inc , ",", exc ), nrow = nrow(inc)))
80+
colnames(qualRM) <- c("GENE","EVENT","COORD","LENGTH","FullCO","COMPLEX",paste0(Samples_Group1,".Q"))
81+
82+
}else{
83+
84+
# If Group2 exists in rMATS table:
85+
# ::::::::::::::::::::::::::::::::
86+
87+
# Infer number of samples from the first row in "SJC columns" by summing 1 to the number of ","
88+
Nsamples_Group1 <- length(gregexpr(",", incTable$SJC_SAMPLE_1[1], fixed = TRUE)[[1]])+1
89+
Nsamples_Group2 <- length(gregexpr(",", incTable$SJC_SAMPLE_2[1], fixed = TRUE)[[1]])+1
90+
91+
# Name samples from groups 1 and 2
92+
Samples_Group1 <- paste0("G1_S",1:Nsamples_Group1)
93+
Samples_Group2 <- paste0("G2_S",1:Nsamples_Group2)
94+
95+
# psiTable
96+
psiRM <- cbind(commonCols,
97+
apply(matrix(unlist(strsplit(incTable$IncLevel1, ",")),ncol=Nsamples_Group1,byrow=T), 2, as.numeric),
98+
apply(matrix(unlist(strsplit(incTable$IncLevel2, ",")),ncol=Nsamples_Group2,byrow=T), 2, as.numeric))
99+
colnames(psiRM) <- c("GENE","EVENT","COORD","LENGTH","FullCO","COMPLEX",Samples_Group1,Samples_Group2)
100+
101+
# qualTable
102+
inc <- cbind(apply(matrix(unlist(strsplit(incTable$IJC_SAMPLE_1, ",")),ncol=Nsamples_Group1,byrow=T), 2, as.numeric)/incTable$IncFormLen,
103+
apply(matrix(unlist(strsplit(incTable$IJC_SAMPLE_2, ",")),ncol=Nsamples_Group1,byrow=T), 2, as.numeric)/incTable$IncFormLen)
104+
exc <- cbind(apply(matrix(unlist(strsplit(incTable$SJC_SAMPLE_1, ",")),ncol=Nsamples_Group1,byrow=T), 2, as.numeric)/incTable$SkipFormLen,
105+
apply(matrix(unlist(strsplit(incTable$SJC_SAMPLE_2, ",")),ncol=Nsamples_Group1,byrow=T), 2, as.numeric)/incTable$SkipFormLen)
106+
107+
qualRM <- cbind(commonCols,
108+
# Mimicking vast-tools INCLUSION table ".Q" columns to facilitate the compatibility with other betAS functions
109+
matrix(paste0("A,A,0=0=0,A,",rep(eventType,nrow(incTable)),"@", inc , ",", exc ), nrow = nrow(inc)))
110+
colnames(qualRM) <- c("GENE","EVENT","COORD","LENGTH","FullCO","COMPLEX",paste0(Samples_Group1,".Q"),paste0(Samples_Group2,".Q"))
111+
112+
}
80113

81114
# Remove events containing at least one NA
82115
psiRM$AnyNA <- apply(psiRM, 1, anyNA)

0 commit comments

Comments
 (0)