comparison select_optimal_cluster.R @ 2:7edf4d48a350 draft default tip

Uploaded
author morinlab
date Sun, 04 Dec 2016 15:57:18 -0500
parents
children
comparison
equal deleted inserted replaced
1:7717e4a7ca07 2:7edf4d48a350
1 library(argparse)
2
3 parser <- ArgumentParser(description="Select the best TITAN cluster");
4
5 parser$add_argument(
6 '--input_params', "-ip",
7 nargs="+",
8 required="True",
9 help="Input parameter files from TITAN"
10 );
11
12 parser$add_argument(
13 '--input_segments', "-is",
14 nargs="+",
15 required="True",
16 help="Input segment files from TITAN"
17 );
18
19 parser$add_argument(
20 "--method", "-m",
21 choices=c('validity_index', 'validity_index_and_pga'),
22 required="True",
23 help="Algorithm to use for cluster selection"
24 );
25
26 parser$add_argument(
27 "--percent_genome_alteration", "-pga",
28 metavar="PGA",
29 type="double",
30 default="0.8",
31 help="Maximum percent genome alteration to accept in a cluster"
32 );
33
34 parser$add_argument(
35 "--output_param", "-op",
36 required="True",
37 help="Output file to store optimal parameter file"
38 );
39
40 parser$add_argument(
41 "--output_segment", "-os",
42 required="True",
43 help="Output file to store optimal segment file"
44 );
45
46 parser$add_argument(
47 "--cancer_genomics_functions_path", "-cgfp",
48 required="True",
49 help="Path to cancer genomics functions in R"
50 )
51
52 args <- parser$parse_args();
53
54 source(paste(args$cancer_genomics_functions_path, "functions.R", sep="/"));
55
56 current_index <- 0;
57 current_val_index <- 1;
58 genome_frame <- generate_common_genome_frame();
59 for (i in 1:length(args$input_params)) {
60 if (args$method == "validity_index_and_pga") {
61 titan_segs <- read_titan_cnv_file(args$input_segments[i]);
62 pga <- calculate_percent_genome_alteration(titan_segs, genome_frame);
63 if (pga >= args$percent_genome_alteration) {
64 next;
65 }
66 }
67
68 titan_params <- read_titan_params_file(args$input_params[i]);
69 val_index <- fetch_validity_index(titan_params)
70 if (current_val_index > val_index) {
71 current_val_index <- val_index;
72 current_index <- i;
73 }
74 }
75
76 command_params <- paste(
77 "cp",
78 args$input_params[current_index],
79 args$output_param,
80 sep=" "
81 );
82
83 system(command_params);
84
85
86 command_segments <- paste(
87 "cp",
88 args$input_segments[current_index],
89 args$output_segment,
90 sep=" "
91 );
92
93 system(command_params);