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
37c7bb92
Commit
37c7bb92
authored
Aug 30, 2017
by
Romain Feron
Browse files
Implemented frequencies visualization
parent
abdc7e9c
Changes
4
Hide whitespace changes
Inline
Side-by-side
radseq_analysis/modules/visualize.py
View file @
37c7bb92
...
...
@@ -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
)
radseq_analysis/visualization/__init__.py
View file @
37c7bb92
from
radseq_analysis.visualization.haplotypes
import
haplotypes
from
radseq_analysis.visualization.clustering
import
clustering
from
radseq_analysis.visualization.frequencies
import
frequencies
radseq_analysis/visualization/frequencies.py
0 → 100644
View file @
37c7bb92
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
)
radseq_analysis/visualization/r_scripts/frequencies.R
View file @
37c7bb92
...
...
@@ -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: "
,
di
m
(
data
)[
1
]
,
sep
=
''
))
+
theme
(
plot.title
=
element_text
(
hjust
=
0.5
))
+
ggtitle
(
paste
(
"Total tags: "
,
su
m
(
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
()
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