Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
khalid
radsex
Commits
b059c12b
Commit
b059c12b
authored
Aug 30, 2017
by
Romain Feron
Browse files
Implemented input file detection for visualize module
parent
48b1cb18
Changes
1
Hide whitespace changes
Inline
Side-by-side
radseq_analysis/modules/visualize.py
View file @
b059c12b
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
\t
Count
\n
'
:
return
'frequencies'
elif
line
.
startswith
(
'Stack_ID
\t
Haplotype_ID
\t
Sequence
\t
Matches
\t
Mismatches
\t
Gaps'
):
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
(
'
\n
Error: 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
'
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment