process.R 2.02 KB
Newer Older
Sascha Herzinger's avatar
Sascha Herzinger committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
workDir <- "/root/rdconnect"

library(tidyr)

fraserTsvPath <- "./Output/processed_results/aberrant_splicing/results/v29/fraser/fraser/results_per_junction.tsv"
fraserRdsPath <- "./Output/processed_results/aberrant_splicing/datasets/savedObjects/fraser--v29/fds-object.RDS"

setwd(workDir)


# helper functions

# adds assay to fraser tsv
assayToDenormDF <- function(assayName, assay, tsv, gr, fds) {
  df <- cbind(gr, assay)
  sampleColIndices <- seq(dim(gr)[2]+1, dim(df)[2])
  denorm_df <- pivot_longer(df, cols=all_of(sampleColIndices), names_to="sampleID", values_to=assayName)
  newTsv <- merge(tsv, denorm_df, all.x=TRUE)
  keepCols <- append(colnames(tsv), assayName)
  newTsv[, keepCols]
}

# read original output file
fraserTsv <- read.table(fraserTsvPath, sep="\t", header=TRUE)

# read original binary files
fds <- readRDS(fraserRdsPath)
fds
gr <- as.data.frame(granges(fds))

# add additional assays that we are interested in to fraser tsv
fraserTsv <- assayToDenormDF("predictedMeans_psi3", assays(fds)[["predictedMeans_psi3"]], fraserTsv, gr, fds)
fraserTsv <- assayToDenormDF("pvaluesBetaBinomial_junction_psi3", assays(fds)[["pvaluesBetaBinomial_junction_psi3"]], fraserTsv, gr, fds)
fraserTsv <- assayToDenormDF("junction_count", K(fds, type = 'psi3'), fraserTsv, gr, fds)
fraserTsv <- assayToDenormDF("total_junction_count", N(fds, type = 'psi3'), fraserTsv, gr, fds)

# write new tsv
write.table(fraserTsv, sep = "\t", file = "fraser_complete_output.tsv", row.names=FALSE)


##################
##################


outriderTsvPath <- "./Output/processed_results/aberrant_expression/v29/outrider/outrider/OUTRIDER_results.tsv"
outriderRdsPath <- "./Output/processed_results/aberrant_expression/v29/outrider/outrider/ods.Rds"
Sascha Herzinger's avatar
Sascha Herzinger committed
47

Sascha Herzinger's avatar
Sascha Herzinger committed
48
49
outriderTsv <- read.table(outriderTsvPath, sep="\t", header=TRUE)
ods <- readRDS(outriderRdsPath)
Sascha Herzinger's avatar
Sascha Herzinger committed
50
ods
Sascha Herzinger's avatar
Sascha Herzinger committed
51
gr <- as.data.frame(granges(ods))
Sascha Herzinger's avatar
Sascha Herzinger committed
52
53
54
55
56

sampleRank <- rank(outriderTsv["normcounts"])
outriderTsv <- cbind(outriderTsv, sampleRank)

write.table(outriderTsv, sep = "\t", file = "outrider_complete_output.tsv", row.names=FALSE)