Mercurial > repos > iuc > snpfreqplot
annotate heatmap_for_variants.R @ 0:1062d6ad6503 draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
author | iuc |
---|---|
date | Wed, 02 Dec 2020 21:23:06 +0000 |
parents | |
children | e362b3143cde |
rev | line source |
---|---|
0
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
1 #!/usr/bin/env R |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
2 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
3 suppressPackageStartupMessages(library(pheatmap)) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
4 suppressPackageStartupMessages(library(RColorBrewer)) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
5 suppressPackageStartupMessages(library(tidyverse)) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
6 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
7 fapply <- function(vect_ids, func) { |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
8 #' List apply but preserve the names |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
9 res <- lapply(vect_ids, func) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
10 names(res) <- vect_ids |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
11 return(res) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
12 } |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
13 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
14 # M A I N |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
15 stopifnot(exists("samples")) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
16 variant_files <- fapply(samples$ids, read_and_process) # nolint |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
17 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
18 extractall_data <- function(id) { |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
19 variants <- variant_files[[id]] |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
20 tmp <- variants %>% |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
21 mutate(posalt = uni_select) %>% |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
22 select(posalt, AF) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
23 colnames(tmp) <- c("Mutation", id) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
24 return(tmp) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
25 } |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
26 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
27 extractall_annots <- function(id) { |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
28 variants <- variant_files[[id]] |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
29 tmp <- variants %>% |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
30 mutate(posalt = uni_select, |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
31 effect = EFF....EFFECT, gene = EFF....GENE) %>% |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
32 select(posalt, effect, gene) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
33 return(tmp) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
34 } |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
35 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
36 # process allele frequencies |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
37 processed_files <- fapply(samples$ids, extractall_data) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
38 final <- as_tibble( |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
39 processed_files %>% |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
40 reduce(full_join, by = "Mutation", copy = T)) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
41 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
42 final <- final[str_order(final$Mutation, numeric = T), ] %>% |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
43 column_to_rownames("Mutation") ## sort and set rownames |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
44 final[final < variant_frequency] <- NA ## adjust the variant frequency: |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
45 final <- final[rowSums(is.na(final)) != ncol(final), ] |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
46 final <- t(final) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
47 final[is.na(final)] <- 0 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
48 class(final) <- "numeric" |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
49 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
50 # add annotations |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
51 ## readout annotations |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
52 processed_annots <- fapply(samples$ids, extractall_annots) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
53 ann_final <- processed_annots %>% |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
54 reduce(function(x, y) { |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
55 unique(rbind(x, y))}) %>% |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
56 filter(posalt %in% colnames(final)) ## apply frequency filter |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
57 ann_final <- as_tibble(ann_final[str_order( |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
58 ann_final$posalt, numeric = T), ]) %>% |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
59 column_to_rownames("posalt") ## sort |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
60 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
61 # rename annotations |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
62 trans <- function(x, mapping, replace_missing=NULL) { |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
63 # helper function for translating effects |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
64 mapped <- mapping[[x]] |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
65 if (is.null(mapped)) { |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
66 if (is.null(replace_missing)) x else replace_missing |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
67 } else { |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
68 mapped |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
69 } |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
70 } |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
71 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
72 # handle translation of classic SnpEff effects to sequence ontology terms |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
73 # The following list defines the complete mapping between classic and So effect |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
74 # terms even if not all of these are likely to appear in viral variant data. |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
75 classic_snpeff_effects_to_so <- list( |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
76 "coding_sequence_variant", "coding_sequence_variant", "disruptive_inframe_deletion", "disruptive_inframe_insertion", "inframe_deletion", "inframe_insertion", "downstream_gene_variant", "exon_variant", "exon_loss_variant", "frameshift_variant", "gene_variant", "intergenic_variant", "intergenic_region", "conserved_intergenic_variant", "intragenic_variant", "intron_variant", "conserved_intron_variant", "missense_variant", "rare_amino_acid_variant", "splice_acceptor_variant", "splice_donor_variant", "splice_region_variant", "5_prime_UTR_premature_start_codon_variant", "start_lost", "stop_gained", "stop_lost", "synonymous_variant", "start_retained_variant", "stop_retained_variant", "transcript_variant", "upstream_gene_variant", "3_prime_UTR_truncation_+_exon_loss_variant", "3_prime_UTR_variant", "5_prime_UTR_truncation_+_exon_loss_variant", "5_prime_UTR_variant", "initiator_codon_variant", "None", "chromosomal_deletion" |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
77 ) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
78 names(classic_snpeff_effects_to_so) <- c( |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
79 "CDS", "CODON_CHANGE", "CODON_CHANGE_PLUS_CODON_DELETION", "CODON_CHANGE_PLUS_CODON_INSERTION", "CODON_DELETION", "CODON_INSERTION", "DOWNSTREAM", "EXON", "EXON_DELETED", "FRAME_SHIFT", "GENE", "INTERGENIC", "INTERGENIC_REGION", "INTERGENIC_CONSERVED", "INTRAGENIC", "INTRON", "INTRON_CONSERVED", "NON_SYNONYMOUS_CODING", "RARE_AMINO_ACID", "SPLICE_SITE_ACCEPTOR", "SPLICE_SITE_DONOR", "SPLICE_SITE_REGION", "START_GAINED", "START_LOST", "STOP_GAINED", "STOP_LOST", "SYNONYMOUS_CODING", "SYNONYMOUS_START", "SYNONYMOUS_STOP", "TRANSCRIPT", "UPSTREAM", "UTR_3_DELETED", "UTR_3_PRIME", "UTR_5_DELETED", "UTR_5_PRIME", "NON_SYNONYMOUS_START", "NONE", "CHROMOSOME_LARGE_DELETION" |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
80 ) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
81 # translate classic effects into SO terms leaving unknown terms (possibly SO already) as is |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
82 so_effects <- sapply(ann_final$effect, function(x) trans(x, classic_snpeff_effects_to_so)) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
83 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
84 # handle further translation of effects we care about |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
85 so_effects_translation <- list( |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
86 "non-syn", "syn", |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
87 "deletion", "deletion", "deletion", |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
88 "insertion", "insertion", "frame shift", |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
89 "stop gained", "stop lost" |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
90 ) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
91 names(so_effects_translation) <- c( |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
92 "missense_variant", "synonymous_variant", |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
93 "disruptive_inframe_deletion", "inframe_deletion", "chromosomal_deletion", |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
94 "disruptive_inframe_insertion", "inframe_insertion", "frameshift_variant", |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
95 "stop_gained", "stop_lost" |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
96 ) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
97 # translate to our simple terms turning undefined terms into '?' |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
98 simple_effects <- sapply(so_effects, function(x) trans(x, so_effects_translation, replace_missing = "?")) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
99 # complex variant effects (those that do more than one thing) are concatenated |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
100 # with either '+' (for classic terms) or '&' (for SO terms) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
101 simple_effects[grepl("+", so_effects, fixed = TRUE)] <- "complex" |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
102 simple_effects[grepl("&", so_effects, fixed = TRUE)] <- "complex" |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
103 simple_effects[so_effects == ""] <- "non-coding" |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
104 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
105 ann_final$effect <- simple_effects |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
106 ann_final$gene <- sub("^$", "NCR", ann_final$gene) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
107 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
108 ## automatically determine gaps for the heatmap |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
109 gap_vector <- which(!(ann_final$gene[1:length(ann_final$gene) - 1] == # nolint |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
110 ann_final$gene[2:length(ann_final$gene)])) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
111 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
112 # colormanagement |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
113 my_colors <- colorRampPalette(c("grey93", "brown", "black")) #heatmap |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
114 count <- length(unique(ann_final$gene)) #annotations (genes) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
115 gene_color <- c(brewer.pal(brewer_color_gene_annotation, n = count)) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
116 names(gene_color) <- unique(ann_final$gene) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
117 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
118 # colormanagement annotations (effect) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
119 ## Define the full set of colors for each effect that we can encounter |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
120 ## This is not bulletproof. The effect names given here were swapped into the |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
121 ## data (see above substitutions in ann_final$effect) and so are hard-coded, |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
122 ## as well as their preferred colors. |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
123 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
124 all_colors <- data.frame( |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
125 color = c("white", "green", "orange", "red", |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
126 "black", "grey", "yellow", "blue", "purple", "brown"), |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
127 name = c("non-coding", "syn", "non-syn", "deletion", |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
128 "frame shift", "stop gained", "stop lost", "insertion", |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
129 "complex", "?")) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
130 ## Reduce the full set to just those that we want |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
131 detected_effects <- unique(ann_final$effect) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
132 subset_colors <- subset(all_colors, name %in% detected_effects) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
133 effect_color <- subset_colors$color |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
134 names(effect_color) <- subset_colors$name |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
135 color_list <- list(gene_color = gene_color, effect_color = effect_color) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
136 names(color_list) <- c("gene", "effect") |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
137 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
138 # visualize heatmap |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
139 if (pheat_number_of_clusters > length(samples$ids)) { |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
140 print(paste0("[INFO] Number of clusters: User-specified clusters (", |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
141 pheat_number_of_clusters, |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
142 ") is greater than the number of samples (", |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
143 length(samples$ids), ")")) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
144 pheat_number_of_clusters <- length(samples$ids) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
145 print(paste0("[INFO] Number of clusters: now set to ", |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
146 pheat_number_of_clusters)) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
147 } |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
148 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
149 get_plot_dims <- function(heat_map) { |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
150 ## get the dimensions of a pheatmap object |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
151 ## useful for plot formats that can't be written to a file directly, but |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
152 ## for which we need to set up a plotting device |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
153 ## source: https://stackoverflow.com/a/61876386 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
154 plot_height <- sum(sapply(heat_map$gtable$heights, |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
155 grid::convertHeight, "in")) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
156 plot_width <- sum(sapply(heat_map$gtable$widths, |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
157 grid::convertWidth, "in")) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
158 return(list(height = plot_height, width = plot_width)) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
159 } |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
160 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
161 height <- round(max(c(max(c( |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
162 16 * (length(unique(ann_final$effect)) + |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
163 length(unique(ann_final$gene))), 160)) / |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
164 nrow(final), 15))) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
165 width <- round(ratio * height) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
166 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
167 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
168 if (!(out_ext %in% c("svg", "jpeg", "png", "pdf"))) { |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
169 stop("Unknown extension: ", ext, ", aborting.") |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
170 } |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
171 plot_device <- get(out_ext) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
172 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
173 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
174 ## A constant scaling factor based on the calculated dimensions |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
175 ## above does not work for PNG, so we resort to feeding pheatmap |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
176 ## with a direct filename |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
177 plot_filename <- NA |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
178 if (out_ext %in% c("jpeg", "png")) { |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
179 plot_filename <- out_file |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
180 } |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
181 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
182 ## SVG is not a format pheatmap knows how to write to a file directly. |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
183 ## As a workaround we |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
184 ## 1. create the plot object |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
185 ## 2. get its dimensions |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
186 ## 3. set up a svg plotting device with these dimensions |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
187 ## 4. print the heatmap object to the device |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
188 hm <- pheatmap( |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
189 final, |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
190 color = my_colors(100), |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
191 cellwidth = width, |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
192 cellheight = height, |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
193 fontsize_col = round(1 / 3 * width), |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
194 fontsize_row = round(1 / 3 * min(c(height, width))), |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
195 clustering_method = pheat_clustering_method, |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
196 cluster_rows = pheat_clustering, |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
197 cluster_cols = F, |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
198 cutree_rows = pheat_number_of_clusters, |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
199 annotation_col = ann_final, |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
200 annotation_colors = color_list, |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
201 filename = plot_filename, |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
202 gaps_col = gap_vector |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
203 ) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
204 |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
205 if (out_ext %in% c("pdf", "svg")) { |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
206 plot_dims <- get_plot_dims(hm) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
207 plot_device(out_file, |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
208 width = plot_dims$width, |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
209 height = plot_dims$height) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
210 print(hm) |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
211 dev.off() |
1062d6ad6503
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff
changeset
|
212 } |