Commit 37c7bb92 authored by Romain Feron's avatar Romain Feron
Browse files

Implemented frequencies visualization

parent abdc7e9c
......@@ -2,7 +2,7 @@ from radseq_analysis import visualization
def detect_plot_type(input_file):
return 'clustering'
return 'frequencies'
def analysis(input_file_path, popmap_file_path, output_file_path, parameters):
......@@ -10,6 +10,13 @@ def analysis(input_file_path, popmap_file_path, output_file_path, parameters):
plot_type = detect_plot_type(input_file_path)
if plot_type == 'haplotypes':
visualization.haplotypes(input_file_path, output_file_path, parameters.species)
visualization.haplotypes(input_file_path,
output_file_path,
parameters.species)
elif plot_type == 'clustering':
visualization.clustering(input_file_path, popmap_file_path, output_file_path)
visualization.clustering(input_file_path,
popmap_file_path,
output_file_path)
elif plot_type == 'frequencies':
visualization.frequencies(input_file_path,
output_file_path)
from radseq_analysis.visualization.haplotypes import haplotypes
from radseq_analysis.visualization.clustering import clustering
from radseq_analysis.visualization.frequencies import frequencies
import os
def frequencies(input_file_path, output_file_path):
scripts_d = ''.join(os.path.split(os.path.realpath(__file__))[:-1])
cmd = ('Rscript ' + os.path.join(scripts_d, 'r_scripts', 'frequencies.R') +
' ' + input_file_path +
' ' + output_file_path)
os.system(cmd)
......@@ -5,7 +5,7 @@ args = commandArgs(trailingOnly=TRUE)
if (length(args)==0) {
stop("At least one argument must be supplied (input file).", call.=FALSE)
} else if (length(args) != 2){
stop("Usage: R frequencies.R input_file.tsv output_dir")
stop("Usage: R frequencies.R input_file.tsv output_file.png")
}
suppressMessages(library(readr))
......@@ -13,20 +13,18 @@ suppressMessages(library(ggplot2))
suppressMessages(library(svglite))
suppressMessages(library(scales))
file = args[1]
output_dir = args[2]
input_file_path = args[1]
output_file_path = args[2]
png_name = paste("tags_distribution.png", sep='')
data = suppressMessages(read_delim(file, "\t", escape_double = FALSE, col_names = TRUE, trim_ws = TRUE))
data = suppressMessages(read_delim(input_file_path, "\t", escape_double = FALSE, col_names = TRUE, trim_ws = TRUE))
colnames(data) = c("Frequency", "Count")
g = ggplot(data, aes(x=Frequency, y=Count/sum(Count))) +
geom_bar(stat="identity", colour="black", fill="#CCCCCC") +
ggtitle(paste("Total tags: ", dim(data)[1], sep='')) + theme(plot.title = element_text(hjust = 0.5)) +
ggtitle(paste("Total tags: ", sum(data$Count), sep='')) + theme(plot.title = element_text(hjust = 0.5)) +
xlab("Number of individuals in which a tag is present") + ylab("Frequency (%)") +
scale_y_continuous(labels=percent)
png(paste(output_dir, png_name, sep=''), width=1600, height=1000, res=130)
png(output_file_path, width=1600, height=1000, res=130)
print(g)
x = dev.off()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment