annotate MannWhitney_DE.R @ 5:a7eb04240b8b draft default tip

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
author artbio
date Thu, 07 Nov 2024 21:37:11 +0000
parents 6916ac5a9ef0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
6916ac5a9ef0 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit c394391dcf541d91ee1dfdc0c3d80cd7a21942ff
artbio
parents: 3
diff changeset
1 # Perform a differential analysis between 2 groups of cells.
0
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
2
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
3 # Example of command
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
4 # Rscript MannWhitney_DE.R --input <input.tsv> --sep <tab> --colnames <TRUE> --metadata <signature.tsv> --column_name <rate> --fdr <0.01> --output <diff_analysis.tsv>
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
5
5
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
6 options(
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
7 show.error.messages = FALSE,
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
8 error = function() {
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
9 cat(geterrmessage(), file = stderr())
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
10 q("no", 1, FALSE)
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
11 }
4
6916ac5a9ef0 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit c394391dcf541d91ee1dfdc0c3d80cd7a21942ff
artbio
parents: 3
diff changeset
12 )
6916ac5a9ef0 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit c394391dcf541d91ee1dfdc0c3d80cd7a21942ff
artbio
parents: 3
diff changeset
13
0
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
14 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
15
4
6916ac5a9ef0 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit c394391dcf541d91ee1dfdc0c3d80cd7a21942ff
artbio
parents: 3
diff changeset
16 suppressPackageStartupMessages({
5
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
17 library(optparse)
4
6916ac5a9ef0 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit c394391dcf541d91ee1dfdc0c3d80cd7a21942ff
artbio
parents: 3
diff changeset
18 })
6916ac5a9ef0 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit c394391dcf541d91ee1dfdc0c3d80cd7a21942ff
artbio
parents: 3
diff changeset
19
6916ac5a9ef0 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit c394391dcf541d91ee1dfdc0c3d80cd7a21942ff
artbio
parents: 3
diff changeset
20 sessionInfo()
6916ac5a9ef0 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit c394391dcf541d91ee1dfdc0c3d80cd7a21942ff
artbio
parents: 3
diff changeset
21
6916ac5a9ef0 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit c394391dcf541d91ee1dfdc0c3d80cd7a21942ff
artbio
parents: 3
diff changeset
22 option_list <- list(
5
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
23 make_option(
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
24 "--input",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
25 default = NA,
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
26 type = "character",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
27 help = "Input file that contains log2(CPM +1) values"
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
28 ),
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
29 make_option(
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
30 "--sep",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
31 default = "\t",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
32 type = "character",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
33 help = "File separator [default : '%default' ]"
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
34 ),
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
35 make_option(
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
36 "--colnames",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
37 default = TRUE,
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
38 type = "logical",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
39 help = "Consider first line as header ? [default : '%default' ]"
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
40 ),
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
41 make_option(
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
42 "--comparison_factor_file",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
43 default = NA,
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
44 type = "character",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
45 help = " A two column table : cell identifiers and a comparison factor that split cells in two categories (high/low, HOM/HET,...)"
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
46 ),
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
47 make_option(
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
48 "--factor1",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
49 type = "character",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
50 help = "level associated to the control condition in the factor file"
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
51 ),
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
52 make_option(
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
53 "--factor2",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
54 type = "character",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
55 help = "level associated to the test condition in the factor file"
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
56 ),
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
57 make_option(
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
58 "--fdr",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
59 default = 0.01,
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
60 type = "numeric",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
61 help = "FDR threshold [default : '%default' ]"
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
62 ),
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
63 make_option(
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
64 "--log",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
65 default = FALSE,
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
66 action = "store_true",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
67 type = "logical",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
68 help = "Expression data are log-transformed [default : '%default' ]"
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
69 ),
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
70 make_option(
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
71 "--output",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
72 default = "results.tsv",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
73 type = "character",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
74 help = "Output name [default : '%default' ]"
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
75 )
0
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
76 )
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
77
4
6916ac5a9ef0 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit c394391dcf541d91ee1dfdc0c3d80cd7a21942ff
artbio
parents: 3
diff changeset
78 opt <- parse_args(OptionParser(option_list = option_list),
5
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
79 args = commandArgs(trailingOnly = TRUE)
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
80 )
0
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
81
4
6916ac5a9ef0 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit c394391dcf541d91ee1dfdc0c3d80cd7a21942ff
artbio
parents: 3
diff changeset
82 if (opt$sep == "tab") {
5
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
83 opt$sep <- "\t"
4
6916ac5a9ef0 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit c394391dcf541d91ee1dfdc0c3d80cd7a21942ff
artbio
parents: 3
diff changeset
84 }
6916ac5a9ef0 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit c394391dcf541d91ee1dfdc0c3d80cd7a21942ff
artbio
parents: 3
diff changeset
85 if (opt$sep == "comma") {
5
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
86 opt$sep <- ","
4
6916ac5a9ef0 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit c394391dcf541d91ee1dfdc0c3d80cd7a21942ff
artbio
parents: 3
diff changeset
87 }
0
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
88
5
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
89 # Open files
0
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
90 data.counts <- read.table(
5
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
91 opt$input,
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
92 h = opt$colnames,
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
93 row.names = 1,
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
94 sep = opt$sep,
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
95 check.names = FALSE
0
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
96 )
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
97
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
98 metadata <- read.table(
5
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
99 opt$comparison_factor_file,
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
100 header = TRUE,
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
101 stringsAsFactors = FALSE,
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
102 sep = "\t",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
103 check.names = FALSE,
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
104 row.names = 1
0
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
105 )
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
106
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
107 metadata <- subset(metadata, rownames(metadata) %in% colnames(data.counts))
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
108
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
109 # Create two logical named vectors for each factor level of cell signature
4
6916ac5a9ef0 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit c394391dcf541d91ee1dfdc0c3d80cd7a21942ff
artbio
parents: 3
diff changeset
110 factor1_cells <- setNames(metadata[, 1] == opt$factor1, rownames(metadata))
6916ac5a9ef0 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit c394391dcf541d91ee1dfdc0c3d80cd7a21942ff
artbio
parents: 3
diff changeset
111 factor2_cells <- setNames(metadata[, 1] == opt$factor2, rownames(metadata))
0
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
112
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
113 ## Mann-Whitney test (Two-sample Wilcoxon test)
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
114 MW_test <- data.frame(t(apply(data.counts, 1, function(x) {
5
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
115 do.call("cbind", wilcox.test(x[names(factor1_cells)[factor1_cells]], x[names(factor2_cells)[factor2_cells]]))[, 1:2]
4
6916ac5a9ef0 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit c394391dcf541d91ee1dfdc0c3d80cd7a21942ff
artbio
parents: 3
diff changeset
116 })), stringsAsFactors = FALSE)
0
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
117
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
118 # Benjamini-Hochberg correction and significativity
4
6916ac5a9ef0 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit c394391dcf541d91ee1dfdc0c3d80cd7a21942ff
artbio
parents: 3
diff changeset
119 MW_test$p.adjust <- p.adjust(as.numeric(MW_test$p.value), method = "BH", n = nrow(MW_test))
0
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
120 MW_test$Significant <- MW_test$p.adjust < opt$fdr
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
121
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
122 ## Descriptive Statistics Function
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
123 descriptive_stats <- function(InputData) {
5
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
124 SummaryData <- data.frame(
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
125 mean = rowMeans(InputData),
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
126 SD = apply(InputData, 1, sd),
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
127 Variance = apply(InputData, 1, var),
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
128 Percentage_Detection = apply(InputData, 1, function(x, y = InputData) {
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
129 (sum(x != 0) / ncol(y)) * 100
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
130 }),
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
131 mean_condition2 = rowMeans(InputData[, factor2_cells]),
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
132 mean_condition1 = rowMeans(InputData[, factor1_cells])
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
133 )
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
134 if (opt$log) {
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
135 SummaryData$log2FC <- SummaryData$mean_condition2 - SummaryData$mean_condition1
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
136 } else {
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
137 SummaryData$log2FC <- log2(SummaryData$mean_condition2 / SummaryData$mean_condition1)
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
138 }
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
139 return(SummaryData)
0
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
140 }
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
141
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
142 gene_stats <- descriptive_stats(data.counts)
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
143
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
144 results <- merge(gene_stats, MW_test, by = "row.names")
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
145 colnames(results)[1] <- "genes"
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
146
3
3d86c89f15bf "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit fab41058cef186159d746c55808d0e69f252af2f"
artbio
parents: 0
diff changeset
147 ## Annotate Significant column
4
6916ac5a9ef0 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit c394391dcf541d91ee1dfdc0c3d80cd7a21942ff
artbio
parents: 3
diff changeset
148 results$Significant[results$Significant == TRUE & !is.na(results$Significant)] <- ifelse(subset(results, Significant == TRUE)$log2FC > 0, "UP", "DOWN")
6916ac5a9ef0 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit c394391dcf541d91ee1dfdc0c3d80cd7a21942ff
artbio
parents: 3
diff changeset
149 results$Significant[results$Significant == FALSE & !is.na(results$Significant)] <- "NS"
3
3d86c89f15bf "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit fab41058cef186159d746c55808d0e69f252af2f"
artbio
parents: 0
diff changeset
150
3d86c89f15bf "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit fab41058cef186159d746c55808d0e69f252af2f"
artbio
parents: 0
diff changeset
151
0
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
152 # Save files
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
153 write.table(
5
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
154 results[order(results$p.adjust), ],
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
155 opt$output,
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
156 sep = "\t",
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
157 quote = FALSE,
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
158 col.names = TRUE,
a7eb04240b8b planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/gsc_mannwhitney_de commit 9286176209be97cd4b972c034345cf060bd7783e
artbio
parents: 4
diff changeset
159 row.names = FALSE
0
c67dba545a37 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_mannwhitney_de commit 09dcd74dbc01f448518cf3db3e646afb0675a6fe
artbio
parents:
diff changeset
160 )