-
Notifications
You must be signed in to change notification settings - Fork 13
/
viva
executable file
·639 lines (442 loc) · 29.6 KB
/
viva
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
#!/usr/bin/env julia
println()
println("Welcome to VIVA.")
println()
println("Loading dependency packages:")
println()
using VariantVisualization
println("...")
using Pkg
try
using GeneticVariation
catch
Pkg.add("GeneticVariation")
using GeneticVariation
end
println()
println("Finished loading packages!")
println()
#=
function test_parse_main(ARGS::Vector{String})
# initialize the settings (the description prints text when help is called)
s = ArgParseSettings(
description = "VIVA VCF Visualization Tool is a tool for creating publication quality plots of data contained within VCF files. For a complete description of features with examples read the docs here https://github.com/compbiocore/VariantVisualization.jl",
suppress_warnings = true,
epilog = "Thank you for using VIVA. Please submit any bugs to https://github.com/compbiocore/VariantVisualization.jl/issues "
)
@add_arg_table s begin
"--vcf_file", "-f"
help = "vcf filename in format: file.vcf"
arg_type = String
required = true
"--output_directory", "-o"
help =" function checks if directory exists and saves there, if not creates and saves here"
arg_type = String
default = "output"
"--save_format", "-s"
help = "file format you wish to save graphics as (eg. pdf, html, png). Defaults to html"
arg_type = String
default = "html"
"--genomic_range", "-r"
help = "select rows within a given chromosome range. Provide chromosome range after this flag in format chr4:20000000-30000000."
arg_type = String
"--pass_filter", "-p"
help = "select rows with PASS in the FILTER field."
action = :store_true
"--positions_list", "-l"
help = "select variants matching list of chromosomal positions. Provide filename of text file formatted with two columns in csv format: 1,2000345."
arg_type = String
"--group_samples", "-g"
help = "group samples by common trait using user generated matrix key of traits and sample names following format guidelines in documentation. Provide file name of .csv file"
nargs = 2
arg_type = String
"--select_samples"
help = "select samples to include in visualization by providing tab delimited list of sample names (eg. samplenames.txt). Works for heatmap visualizations and numeric array generation only (not average dp plots)"
arg_type = String
"--heatmap", "-m"
help = "genotype field to visualize (eg. genotype, read_depth, or 'genotype,read_depth' to visualize each separately)"
arg_type = String
default = "genotype,read_depth"
"--y_axis_labels", "-y"
help = "specify whether to label y-axis with all chromosome positions (options = positions / chromosome) separators. Defaults to chromosome separators."
default = "chromosomes"
arg_type = String
"--x_axis_labels", "-x"
help = "flag to specify whether to label x-axis with sample ids from vcf file. Defaults to FALSE."
action = :store_true
"--num_array", "-n"
help = "flag to save numeric array of categorical genotype values or read depth values before heatmap plotting. Must be used with --heatmap set."
action = :store_true
"--heatmap_title", "-t"
help = "Specify filename for heatmap with underscores for spaces."
arg_type = String
"--avg_dp"
help = "visualize average read depths as line chart. Options: average sample read depth, average variant read depth, or both. eg. =sample, =variant, =sample,variant"
"--save_remotely"
help = "Save html support files online rather than locally so files can be shared between systems. Files saved in this way require internet access to open."
action = :store_true
#nargs = 2
#metavar = ["avg_option", "markers_or_lines"]
#default = ["variant,sample", "markers"]
#default = "sample,variant" #turn on when plotly working
end
parsed_args = parse_args(s)
# can turn off printing parsed args after development"
#println("Parsed args:")
#activate block to show all argument keys
for (key,val) in parsed_args
println(" $key => $(repr(val))")
end
return parsed_args
end
=#
parsed_args = VariantVisualization.test_parse_main(ARGS)
#filter vcf and load matrix of filtered vcf records
vcf_filename = (parsed_args["vcf_file"])
println("Reading $vcf_filename ...")
println()
reader = GeneticVariation.VCF.Reader(open(vcf_filename, "r"))
sample_names = get_sample_names(reader)
save_ext = parsed_args["save_format"]
remote_option = parsed_args["save_remotely"]
VariantVisualization.checkfor_outputdirectory(parsed_args["output_directory"])
output_directory=parsed_args["output_directory"]
#=
#improvement note for developers: implement feature to display VCF summary stats when no plotting options are chosen. This was implemented with VCFTools.jl package which is not supported in Julia v1+. Would need to find new function, perhaps in GeneticVariation.jl
#nrecords() and nsamples() were from VCFTools.jl package which is no longer supported
#can also implement this as flag option to display number variants and samples before filtering
if parsed_args["avg_dp"] == nothing && parsed_args["heatmap"] == nothing
number_records = nrecords((parsed_args["vcf_file"]))
number_samples = nsamples((parsed_args["vcf_file"]))
println("_______________________________________________")
println()
println("Summary Statistics of $(parsed_args["vcf_file"])")
println()
println("number of records: $number_records")
println("number of samples: $number_samples")
println("_______________________________________________")
println()
println("No plotting options specified. Plot data with --heatmap or --avg_dp_plot options")
println()
end
=#
if parsed_args["x_axis_labels"] == true
x_axis_label_option = true
else
x_axis_label_option = false
end
#pass_filter
if parsed_args["pass_filter"] == true && parsed_args["genomic_range"] == nothing && parsed_args["positions_list"] == nothing
println("Only pass filter is applied. Large vcf files with many PASS variants will take a long time to process and heatmap visualizations will lose resolution at this scale unless viewed in interactive html for zooming.")
println()
sub = VariantVisualization.io_pass_filter(vcf_filename)
number_rows = size(sub,1)
println("Selected $number_rows variants with Filter status: PASS")
heatmap_input = "pass_filtered"
end
#chr_range
if parsed_args["genomic_range"] != nothing && parsed_args["pass_filter"] == false && parsed_args["positions_list"] == nothing
sub = VariantVisualization.io_genomic_range_vcf_filter(parsed_args["genomic_range"],vcf_filename)
number_rows = size(sub,1)
println("Selected $number_rows variants within chromosome range: $(parsed_args["genomic_range"])")
heatmap_input = "range_filtered"
end
#list
if parsed_args["positions_list"] != nothing && parsed_args["genomic_range"] == nothing && parsed_args["pass_filter"] == false
sig_list = load_siglist(parsed_args["positions_list"])
sub = VariantVisualization.io_sig_list_vcf_filter(sig_list,vcf_filename)
number_rows = size(sub,1)
println("Selected $number_rows variants that match list of chromosome positions of interest")
heatmap_input = "positions_filtered"
end
#pass_filter and chr_range and list
if parsed_args["pass_filter"] == true && parsed_args["genomic_range"] != nothing && parsed_args["positions_list"] != nothing
sig_list = load_siglist(parsed_args["positions_list"])
sub = VariantVisualization.pass_genomic_range_siglist_filter(vcf_filename, sig_list, parsed_args["genomic_range"])
number_rows = size(sub,1)
println("Selected $number_rows variants with Filter status: PASS, that match list of chromosome positions of interest, and are within chromosome range: $(parsed_args["genomic_range"])")
end
#pass_filter and chr_range
if parsed_args["pass_filter"] == true && parsed_args["genomic_range"] != nothing && parsed_args["positions_list"] == nothing
sub = VariantVisualization.pass_genomic_range_filter(reader, parsed_args["genomic_range"],vcf_filename)
number_rows = size(sub,1)
println("Selected $number_rows variants with Filter status: PASS and are within chromosome range: $(parsed_args["genomic_range"])")
end
#pass_filter and list
if parsed_args["pass_filter"] == true && parsed_args["genomic_range"] == nothing && parsed_args["positions_list"] != nothing
sig_list = load_siglist(parsed_args["positions_list"])
sub = VariantVisualization.pass_siglist_filter(vcf_filename, sig_list)
number_rows = size(sub,1)
println("Selected $number_rows variants with Filter status: PASS and that match list of chromosome positions of interest")
end
#chr_range and list
if parsed_args["pass_filter"] == false && parsed_args["genomic_range"] != nothing && parsed_args["positions_list"] != nothing
sig_list = load_siglist(parsed_args["positions_list"])
sub = VariantVisualization.genomic_range_siglist_filter(vcf_filename, sig_list, parsed_args["genomic_range"])
number_rows = size(sub,1)
println("Selected $number_rows variants that are within chromosome range: $(parsed_args["genomic_range"]) and that match list of chromosome positions of interest")
end
#no filters
if parsed_args["pass_filter"] == false && parsed_args["genomic_range"] == nothing && parsed_args["positions_list"] == nothing
println("No filters applied. Large vcf files will take a long time to process and heatmap visualizations will lose resolution at this scale unless viewed in interactive html for zooming.")
println()
println("Loading VCF file into memory for visualization")
sub = Array{Any}(undef,0)
for record in reader
push!(sub,record)
end
number_rows = size(sub,1)
println("Selected $number_rows variants with no filters applied")
end
y_axis_label_option = parsed_args["y_axis_labels"]
number_rows = size(sub,1)
#convert to numeric array for plotting and generate/save heatmaps and scatter plots
if parsed_args["heatmap"] == "genotype"
gt_num_array,gt_chromosome_labels = combined_all_genotype_array_functions(sub)
if parsed_args["heatmap_title"] != nothing
title = "Genotype_$(parsed_args["heatmap_title"])"
else
bn = Base.Filesystem.basename(parsed_args["vcf_file"])
title = "Genotype_$bn"
end
chr_pos_tuple_list = generate_chromosome_positions_for_hover_labels(gt_chromosome_labels)
chrom_label_info = VariantVisualization.chromosome_label_generator(gt_chromosome_labels[:,1])
if length(parsed_args["group_samples"]) == 2
if parsed_args["select_samples"] != nothing && length(parsed_args["group_samples"]) != 2
println("Selecting samples listed in $(parsed_args["select_samples"])")
gt_num_array,col_selectedcolumns = select_columns(parsed_args["select_samples"],
gt_num_array,
sample_names)
sample_names = col_selectedcolumns
elseif parsed_args["select_samples"] != nothing && length(parsed_args["group_samples"]) == 2
#sample selection occurs in this case during sample grouping step.
#when using sample grouping and selection options, sample metadata matric should have the same sample names as the selection list.
#improvement note for developers: make function to check that sample ids in metadata matrix and sample selection list match. If not, print error and choose to go with metadata matrix sample ids.
end
group_trait_matrix_filename=((parsed_args["group_samples"])[1])
trait_to_group_by = ((parsed_args["group_samples"])[2])
println()
println("Grouping samples by $trait_to_group_by")
println()
ordered_num_array,group_label_pack,pheno,id_list,trait_labels = sortcols_by_phenotype_matrix(group_trait_matrix_filename, trait_to_group_by, gt_num_array, sample_names)
if parsed_args["num_array"] == true
save_numerical_array(ordered_num_array,sample_names,chr_pos_tuple_list,title,output_directory)
end
pheno_num_array,trait_label_array,chrom_label_info=add_pheno_matrix_to_gt_data_for_plotting(ordered_num_array,pheno,trait_labels,chrom_label_info,number_rows)
graphic = VariantVisualization.genotype_heatmap_with_groups(pheno_num_array,title,chrom_label_info,group_label_pack,id_list,chr_pos_tuple_list,y_axis_label_option,trait_label_array,x_axis_label_option,number_rows)
else
if parsed_args["select_samples"] != nothing && length(parsed_args["group_samples"]) != 2
println("Selecting samples listed in $(parsed_args["select_samples"])")
gt_num_array,col_selectedcolumns = select_columns(parsed_args["select_samples"], gt_num_array, sample_names)
sample_names=col_selectedcolumns
elseif parsed_args["select_samples"] != nothing && length(parsed_args["group_samples"]) == 2
#sample selection occurs in this case during sample grouping step.
#when using sample grouping and selection options, sample metadata matric should have the same sample names as the selection list.
#improvement note for developers: make function to check that sample ids in metadata matrix and sample selection list match. If not, print error and choose to go with metadata matrix sample ids.
end
if parsed_args["num_array"] == true
save_numerical_array(gt_num_array,sample_names,chr_pos_tuple_list,title,output_directory)
end
graphic = VariantVisualization.genotype_heatmap2_new_legend(gt_num_array,title,chrom_label_info,sample_names,chr_pos_tuple_list,y_axis_label_option,x_axis_label_option)
end
println("Saving genotype heatmap")
save_graphic(graphic,output_directory,save_ext,title,remote_option)
end
if parsed_args["heatmap"] == "read_depth"
dp_num_array,dp_chromosome_labels = combined_all_read_depth_array_functions(sub)
if parsed_args["heatmap_title"] != nothing
title = "Read_Depth_$(parsed_args["heatmap_title"])"
else
bn = Base.Filesystem.basename(parsed_args["vcf_file"])
title = "Read_Depth_$bn"
end
chr_pos_tuple_list = generate_chromosome_positions_for_hover_labels(dp_chromosome_labels)
chrom_label_info = VariantVisualization.chromosome_label_generator(dp_chromosome_labels[:,1])
if length(parsed_args["group_samples"]) == 2
if parsed_args["select_samples"] != nothing && length(parsed_args["group_samples"]) != 2
println("Selecting samples listed in $(parsed_args["select_samples"])")
dp_num_array,col_selectedcolumns = select_columns(parsed_args["select_samples"], dp_num_array, sample_names)
sample_names=col_selectedcolumns
elseif parsed_args["select_samples"] != nothing && length(parsed_args["group_samples"]) == 2
#sample selection occurs in this case during sample grouping step.
#when using sample grouping and selection options, sample metadata matric should have the same sample names as the selection list.
#improvement note for developers: make function to check that sample ids in metadata matrix and sample selection list match. If not, print error and choose to go with metadata matrix sample ids.
end
group_trait_matrix_filename=((parsed_args["group_samples"])[1])
trait_to_group_by = ((parsed_args["group_samples"])[2])
println()
println("Grouping samples by $trait_to_group_by")
println()
ordered_dp_num_array,group_label_pack,pheno,id_list,trait_labels = sortcols_by_phenotype_matrix(group_trait_matrix_filename, trait_to_group_by, dp_num_array, sample_names)
dp_num_array_limited=read_depth_threshhold(ordered_dp_num_array)
if parsed_args["num_array"] == true
save_numerical_array(ordered_dp_num_array,sample_names,chr_pos_tuple_list,title,output_directory)
end
pheno_num_array,trait_label_array,chrom_label_info = add_pheno_matrix_to_dp_data_for_plotting(dp_num_array_limited,pheno,trait_labels,chrom_label_info,number_rows)
graphic = VariantVisualization.dp_heatmap2_with_groups(pheno_num_array,title,chrom_label_info,group_label_pack,id_list,chr_pos_tuple_list,y_axis_label_option,trait_label_array,x_axis_label_option,number_rows)
else
if parsed_args["select_samples"] != nothing && length(parsed_args["group_samples"]) != 2
println("Selecting samples listed in $(parsed_args["select_samples"])")
dp_num_array,col_selectedcolumns = select_columns(parsed_args["select_samples"], dp_num_array, sample_names)
sample_names=col_selectedcolumns
elseif parsed_args["select_samples"] != nothing && length(parsed_args["group_samples"]) == 2
#sample selection occurs in this case during sample grouping step.
#when using sample grouping and selection options, sample metadata matric should have the same sample names as the selection list.
#improvement note for developers: make function to check that sample ids in metadata matrix and sample selection list match. If not, print error and choose to go with metadata matrix sample ids.
end
if parsed_args["num_array"] == true
save_numerical_array(dp_num_array,sample_names,chr_pos_tuple_list,title,output_directory)
end
dp_num_array_limited=read_depth_threshhold(dp_num_array)
graphic = VariantVisualization.dp_heatmap2(dp_num_array, title, chrom_label_info, sample_names,chr_pos_tuple_list,y_axis_label_option,x_axis_label_option)
end
println("Saving read depth heatmap")
save_graphic(graphic,output_directory,save_ext,title,remote_option)
end
if parsed_args["heatmap"] == "genotype,read_depth" || parsed_args["heatmap"] == "read_depth,genotype"
gt_num_array,gt_chromosome_labels = combined_all_genotype_array_functions(sub)
if parsed_args["heatmap_title"] != nothing
title = "Genotype_$(parsed_args["heatmap_title"])"
else
bn = Base.Filesystem.basename(parsed_args["vcf_file"])
title = "Genotype_$bn"
end
chr_pos_tuple_list = generate_chromosome_positions_for_hover_labels(gt_chromosome_labels)
chrom_label_info = VariantVisualization.chromosome_label_generator(gt_chromosome_labels[:,1])
if length(parsed_args["group_samples"]) == 2
if parsed_args["select_samples"] != nothing && length(parsed_args["group_samples"]) != 2
println("Selecting samples listed in $(parsed_args["select_samples"])")
gt_num_array,col_selectedcolumns = select_columns(parsed_args["select_samples"],
gt_num_array,
sample_names)
sample_names=col_selectedcolumns
elseif parsed_args["select_samples"] != nothing && length(parsed_args["group_samples"]) == 2
#sample selection occurs in this case during sample grouping step.
#when using sample grouping and selection options, sample metadata matric should have the same sample names as the selection list.
#improvement note for developers: make function to check that sample ids in metadata matrix and sample selection list match. If not, print error and choose to go with metadata matrix sample ids.
end
group_trait_matrix_filename=((parsed_args["group_samples"])[1])
trait_to_group_by = ((parsed_args["group_samples"])[2])
println()
println("Grouping samples by $trait_to_group_by")
println()
ordered_num_array,group_label_pack,pheno,id_list,trait_labels = sortcols_by_phenotype_matrix(group_trait_matrix_filename, trait_to_group_by, gt_num_array, sample_names)
if parsed_args["num_array"] == true
save_numerical_array(ordered_num_array,sample_names,chr_pos_tuple_list,title,output_directory)
end
pheno_num_array,trait_label_array,chrom_label_info=add_pheno_matrix_to_gt_data_for_plotting(ordered_num_array,pheno,trait_labels,chrom_label_info,number_rows)
graphic = VariantVisualization.genotype_heatmap_with_groups(pheno_num_array,title,chrom_label_info,group_label_pack,id_list,chr_pos_tuple_list,y_axis_label_option,trait_label_array,x_axis_label_option,number_rows)
else
if parsed_args["select_samples"] != nothing && length(parsed_args["group_samples"]) != 2
println("Selecting samples listed in $(parsed_args["select_samples"])")
gt_num_array,col_selectedcolumns = select_columns(parsed_args["select_samples"], gt_num_array, sample_names)
sample_names=col_selectedcolumns
elseif parsed_args["select_samples"] != nothing && length(parsed_args["group_samples"]) == 2
#sample selection occurs in this case during sample grouping step.
#when using sample grouping and selection options, sample metadata matric should have the same sample names as the selection list.
#improvement note for developers: make function to check that sample ids in metadata matrix and sample selection list match. If not, print error and choose to go with metadata matrix sample ids.
end
graphic = VariantVisualization.genotype_heatmap2_new_legend(gt_num_array,title,chrom_label_info,sample_names,chr_pos_tuple_list,y_axis_label_option,x_axis_label_option)
end
println("Saving genotype heatmap")
if parsed_args["num_array"] == true
save_numerical_array(gt_num_array,sample_names,chr_pos_tuple_list,title,output_directory)
end
save_graphic(graphic,output_directory,save_ext,title,remote_option)
if parsed_args["heatmap_title"] != nothing
title = "Read_Depth_$(parsed_args["heatmap_title"])"
else
bn = Base.Filesystem.basename(parsed_args["vcf_file"])
title = "Read_Depth_$bn"
end
dp_num_array,dp_chromosome_labels = combined_all_read_depth_array_functions(sub)
chr_pos_tuple_list = generate_chromosome_positions_for_hover_labels(dp_chromosome_labels)
chrom_label_info = VariantVisualization.chromosome_label_generator(dp_chromosome_labels[:,1])
if length(parsed_args["group_samples"]) == 2
if parsed_args["select_samples"] != nothing && length(parsed_args["group_samples"]) != 2
println("Selecting samples listed in $(parsed_args["select_samples"])")
dp_num_array,col_selectedcolumns = select_columns(parsed_args["select_samples"], dp_num_array, sample_names)
sample_names=col_selectedcolumns
elseif parsed_args["select_samples"] != nothing && length(parsed_args["group_samples"]) == 2
#sample selection occurs in this case during sample grouping step.
#when using sample grouping and selection options, sample metadata matric should have the same sample names as the selection list.
#improvement note for developers: make function to check that sample ids in metadata matrix and sample selection list match. If not, print error and choose to go with metadata matrix sample ids.
end
group_trait_matrix_filename=((parsed_args["group_samples"])[1])
trait_to_group_by = ((parsed_args["group_samples"])[2])
ordered_dp_num_array,group_label_pack,pheno,id_list,trait_labels = sortcols_by_phenotype_matrix(group_trait_matrix_filename, trait_to_group_by, dp_num_array, sample_names)
dp_num_array_limited=read_depth_threshhold(ordered_dp_num_array)
if parsed_args["num_array"] == true
save_numerical_array(ordered_dp_num_array,sample_names,chr_pos_tuple_list,title,output_directory)
end
pheno_num_array,trait_label_array,chrom_label_info = add_pheno_matrix_to_dp_data_for_plotting(dp_num_array_limited,pheno,trait_labels,chrom_label_info,number_rows)
graphic = VariantVisualization.dp_heatmap2_with_groups(pheno_num_array,title,chrom_label_info,group_label_pack,id_list,chr_pos_tuple_list,y_axis_label_option,trait_label_array,x_axis_label_option,number_rows)
else
if parsed_args["select_samples"] != nothing && length(parsed_args["group_samples"]) != 2
println("Selecting samples listed in $(parsed_args["select_samples"])")
dp_num_array,col_selectedcolumns = select_columns(parsed_args["select_samples"], dp_num_array, sample_names)
sample_names=col_selectedcolumns
elseif parsed_args["select_samples"] != nothing && length(parsed_args["group_samples"]) == 2
#sample selection occurs in this case during sample grouping step.
#when using sample grouping and selection options, sample metadata matric should have the same sample names as the selection list.
#improvement note for developers: make function to check that sample ids in metadata matrix and sample selection list match. If not, print error and choose to go with metadata matrix sample ids.
end
if parsed_args["num_array"] == true
save_numerical_array(dp_num_array,sample_names,chr_pos_tuple_list,title,output_directory)
end
dp_num_array_limited=read_depth_threshhold(dp_num_array)
graphic = VariantVisualization.dp_heatmap2(dp_num_array, title, chrom_label_info, sample_names,chr_pos_tuple_list,y_axis_label_option,x_axis_label_option)
end
println("Saving read depth heatmap")
save_graphic(graphic,output_directory,save_ext,title,remote_option)
end
if parsed_args["avg_dp"] == "sample"
dp_num_array,dp_chromosome_labels=combined_all_read_depth_array_functions_for_avg_dp(sub)
chr_pos_tuple_list = generate_chromosome_positions_for_hover_labels(dp_chromosome_labels)
dp_num_array_limited=read_depth_threshhold(dp_num_array)
avg_list = VariantVisualization.avg_dp_samples(dp_num_array)
list = VariantVisualization.list_sample_names_low_dp(avg_list, sample_names)
#DelimitedFiles.writedlm(joinpath("$(parsed_args["output_directory"])","Samples_with_low_dp.csv"),list, ",") #turn on when create argument for this and add argument for cutoff e.g. list samples with avg dp <30.
#println("The following samples have read depth of under 15: $list")
graphic = avg_sample_dp_scatter(avg_list,sample_names,x_axis_label_option)
bn = Base.Filesystem.basename(parsed_args["vcf_file"])
title = "Average_Sample_Read_Depth_$bn"
save_graphic(graphic,output_directory,save_ext,title,remote_option)
elseif parsed_args["avg_dp"] == "variant"
dp_num_array,dp_chromosome_labels=combined_all_read_depth_array_functions_for_avg_dp(sub)
chr_pos_tuple_list = generate_chromosome_positions_for_hover_labels(dp_chromosome_labels)
chrom_label_info = VariantVisualization.chromosome_label_generator(dp_chromosome_labels[:,1])
dp_num_array_limited=read_depth_threshhold(dp_num_array)
avg_list = VariantVisualization.avg_dp_variant(dp_num_array)
list = VariantVisualization.list_variant_positions_low_dp(avg_list, dp_chromosome_labels)
#DelimitedFiles.writedlm(joinpath("$(parsed_args["output_directory"])","Variant_positions_with_low_dp.csv"),list,",") #turn on when create argument for this and add argument for cutoff e.g. list samples with avg dp <30.
#println("The following variants have read depth of less than 15: $list") #turn on when create argument for this and add argument for cutoff e.g. list samples with avg dp <30.
bn = Base.Filesystem.basename(parsed_args["vcf_file"])
title = "Average_Variant_Read_Depth$bn"
graphic = avg_variant_dp_line_chart(avg_list,chr_pos_tuple_list,y_axis_label_option,chrom_label_info)
save_graphic(graphic,output_directory,save_ext,title,remote_option)
elseif parsed_args["avg_dp"] == "variant,sample" || parsed_args["avg_dp"] == "sample,variant"
dp_num_array,dp_chromosome_labels=combined_all_read_depth_array_functions_for_avg_dp(sub)
chr_pos_tuple_list = generate_chromosome_positions_for_hover_labels(dp_chromosome_labels)
chrom_label_info = VariantVisualization.chromosome_label_generator(dp_chromosome_labels[:,1])
dp_num_array_limited=read_depth_threshhold(dp_num_array)
avg_list = VariantVisualization.avg_dp_variant(dp_num_array)
list = VariantVisualization.list_variant_positions_low_dp(avg_list, dp_chromosome_labels)
#DelimitedFiles.writedlm(joinpath("$(parsed_args["output_directory"])","Variant_positions_with_low_dp.csv"),list,",") #turn on when create argument for this and add argument for cutoff e.g. list samples with avg dp <30.
#println("The following variants have read depth of less than 15: $list")
bn = Base.Filesystem.basename(parsed_args["vcf_file"])
title = "Average_Variant_Read_Depth$bn"
graphic = avg_variant_dp_line_chart(avg_list,chr_pos_tuple_list,y_axis_label_option,chrom_label_info)
save_graphic(graphic,output_directory,save_ext,title,remote_option)
avg_list = VariantVisualization.avg_dp_samples(dp_num_array)
list = VariantVisualization.list_sample_names_low_dp(avg_list, sample_names)
#DelimitedFiles.writedlm(joinpath("$(parsed_args["output_directory"])","Samples_with_low_dp.csv"),list, ",") #turn on when create argument for this and add argument for cutoff e.g. list samples with avg dp <30.
#println("The following samples have read depth of under 15: $list")
bn = Base.Filesystem.basename(parsed_args["vcf_file"])
title = "Average_Sample_Read_Depth_$bn"
graphic = avg_sample_dp_scatter(avg_list,sample_names,x_axis_label_option)
save_graphic(graphic,output_directory,save_ext,title,remote_option)
elseif parsed_args["avg_dp"] != nothing
println("--avg_dp flag did not find expected arguments: sample, variant, or sample,variant. Average read depth plot not saved.")
end
close(reader) #close the VCF.Reader object to remove it from memory - important for running analysis of same file again and clearing memory space when done