Commit 48b1cb18 authored by Romain Feron's avatar Romain Feron
Browse files

Cleaned up old visualization files

parent 37c7bb92
import os
def frequencies(file, output_dir):
scripts_d = ''.join(os.path.split(os.path.realpath(__file__))[:-1])
cmd = ('Rscript ' + os.path.join(scripts_d, 'r_scripts', 'frequencies.R') +
' ' + file + ' ' + output_dir)
os.system(cmd)
def haplotypes(file, output_dir, threshold):
scripts_d = ''.join(os.path.split(os.path.realpath(__file__))[:-1])
cmd = ('Rscript ' + os.path.join(scripts_d, 'r_scripts', 'haplotypes.R') +
' ' + file + ' ' + output_dir + ' ' + str(threshold))
os.system(cmd)
#!/usr/bin/env Rscript
args = commandArgs(trailingOnly=TRUE)
# test if there is at least one argument: if not, return an error
if (length(args)==0) {
stop("At least one argument must be supplied (input file).n", call.=FALSE)
} else if (length(args) != 3){
stop("Usage: R haplotypes.R input_file.tsv output_dir treshold")
}
suppressMessages(library(readr))
suppressMessages(library(ggplot2))
suppressMessages(library(gridExtra))
file = args[1]
output_dir = args[2]
threshold = args[3]
png_name = paste("sex_variable_haplotypes.png", sep='')
data <- suppressMessages(read_delim(file, "\t", col_names = TRUE, escape_double = FALSE, trim_ws = TRUE))
names(data) = c('Locus', 'Male_haplotype', 'Male_haplotype_number',
'Female_haplotype', 'Female_haplotype_number',
'Males', 'Females', 'Male_outliers',
'Female_outliers', 'Consensus')
males = data.frame(table(data$Male_haplotype_number[which(data$Male_haplotype_number > threshold)], data$Female_haplotype_number[which(data$Male_haplotype_number > threshold)]))
names(males) = c('Males', 'Females', 'Count')
females = data.frame(table(data$Male_haplotype_number[which(data$Female_haplotype_number > threshold)], data$Female_haplotype_number[which(data$Female_haplotype_number > threshold)]))
names(females) = c('Males', 'Females', 'Count')
g <- ggplot(males, aes(x = Males, y = Count, fill = Females))
g = g + geom_bar(stat='identity', position=position_dodge(), colour='black')
h <- ggplot(females, aes(x = Females, y = Count, fill = Males))
h = h + geom_bar(stat='identity', position=position_dodge(), colour='black')
png(paste(output_dir, png_name, sep=''), width=1600, height=1000, res=130)
grid.arrange(g, h, ncol=2)
x = dev.off()
import os
from . import r_plots
def run(global_parameters):
results_dir = os.path.join(global_parameters.results_dir, '')
print(' - Plotting frequencies data')
r_plots.frequencies(global_parameters.frequencies_file, results_dir)
print(' - Plotting haplotypes data')
r_plots.haplotypes(global_parameters.haplotypes_file, results_dir, global_parameters.error_threshold)
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