Commit b059c12b authored by Romain Feron's avatar Romain Feron
Browse files

Implemented input file detection for visualize module

parent 48b1cb18
from radseq_analysis import visualization
def detect_plot_type(input_file):
return 'frequencies'
def detect_plot_type(input_file_path):
input_file = open(input_file_path)
line = input_file.readline()
if line == 'Frequency\tCount\n':
return 'frequencies'
elif line.startswith('Stack_ID\tHaplotype_ID\tSequence\tMatches\tMismatches\tGaps'):
return 'clustering'
else:
temp = set()
fields = line[:-1].split('\t')
temp.add(len(fields))
loci_matrix = True
for f in fields:
try:
int(f)
except ValueError:
loci_matrix = False
for line in input_file:
if line:
fields = line[:-1].split('\t')
temp.add(len(fields))
for f in fields:
try:
int(f)
except ValueError:
loci_matrix = False
if loci_matrix and len(temp) == 1:
return 'haplotypes'
else:
return 'error'
def analysis(input_file_path, popmap_file_path, output_file_path, parameters):
......@@ -10,13 +39,21 @@ def analysis(input_file_path, popmap_file_path, output_file_path, parameters):
plot_type = detect_plot_type(input_file_path)
if plot_type == 'haplotypes':
print('Generating plot from haplotypes matrix')
visualization.haplotypes(input_file_path,
output_file_path,
parameters.species)
elif plot_type == 'clustering':
print('Generating plot from alleles file for clustering')
visualization.clustering(input_file_path,
popmap_file_path,
output_file_path)
elif plot_type == 'frequencies':
print('Generating plot from frequencies file')
visualization.frequencies(input_file_path,
output_file_path)
elif plot_type == 'error':
print('\nError: could not detect input file type. Input file should be :\n' +
'\t- a haplotypes matrix generated by the heatmap command\n' +
'\t- an allele file generated by the rescue command\n' +
'\t- a frequencies file generated by the frequencies command\n')
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