Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
panacota
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Amandine PERRIN
panacota
Commits
724f505a
Commit
724f505a
authored
4 years ago
by
Amandine PERRIN
Browse files
Options
Downloads
Patches
Plain Diff
Finish unit tests for general_format_functions
parent
b738da95
No related branches found
No related tags found
No related merge requests found
Pipeline
#39167
passed
4 years ago
Stage: test
Stage: coverage
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitlab-ci.yml
+2
-4
2 additions, 4 deletions
.gitlab-ci.yml
test/test_unit/test_annotate/test_format_func.py
+56
-67
56 additions, 67 deletions
test/test_unit/test_annotate/test_format_func.py
with
58 additions
and
71 deletions
.gitlab-ci.yml
+
2
−
4
View file @
724f505a
...
@@ -83,10 +83,8 @@ unit-test-ubuntu:
...
@@ -83,10 +83,8 @@ unit-test-ubuntu:
-
py.test test/test_unit/test_utils-argparse.py -vx
-
py.test test/test_unit/test_utils-argparse.py -vx
-
py.test test/test_unit/test_prepare -v -x
-
py.test test/test_unit/test_prepare -v -x
-
py.test test/test_unit/test_annotate/test_genome_func.py -vx
-
py.test test/test_unit/test_annotate/test_genome_func.py -vx
-
py.test test/test_unit/test_annotate/test_annotation_* -vx
-
py.test test/test_unit/test_annotate/test_annotation* -vx
# - py.test test/test_unit/test_apnnotate/test_format_func.py -v -x
-
py.test test/test_unit/test_annotate/test_format* -v -x
-
py.test test/test_unit/test_annotate/test_format_prokka.py -vx
-
py.test test/test_unit/test_annotate/test_format_prodigal.py -vx
-
py.test test/test_unit/test_pangenome -vx
-
py.test test/test_unit/test_pangenome -vx
-
py.test test/test_unit/test_corepers -vx
-
py.test test/test_unit/test_corepers -vx
-
py.test test/test_unit/test_align -vx
-
py.test test/test_unit/test_align -vx
...
...
This diff is collapsed.
Click to expand it.
test/test_unit/test_annotate/test_format_func.py
+
56
−
67
View file @
724f505a
...
@@ -39,7 +39,7 @@ def setup_teardown_module():
...
@@ -39,7 +39,7 @@ def setup_teardown_module():
print
(
"
setup
"
)
print
(
"
setup
"
)
yield
yield
#
shutil.rmtree(GENEPATH)
shutil
.
rmtree
(
GENEPATH
)
print
(
"
teardown
"
)
print
(
"
teardown
"
)
# Define variables and functions used by several tests
# Define variables and functions used by several tests
...
@@ -355,6 +355,53 @@ def test_format_all_prodigal(caplog):
...
@@ -355,6 +355,53 @@ def test_format_all_prodigal(caplog):
assert
"
Formatting all genomes
"
in
caplog
.
text
assert
"
Formatting all genomes
"
in
caplog
.
text
def
test_format_allpb_prokka
(
caplog
):
"""
Test that when giving a list of genomes, 1 that is correctly formatted, and 1 has a pb,
it returns the last one in skipped_format
"""
caplog
.
set_level
(
logging
.
DEBUG
)
# Create empty original sequence files
genomes
=
[
"
wrong.fasta
"
,
"
error.fasta
"
]
gpaths
=
[
os
.
path
.
join
(
GENEPATH
,
name
)
for
name
in
genomes
]
for
file
in
gpaths
:
open
(
file
,
"
w
"
).
close
()
# Add prokka (empty) result files to prokkaRes directory
prok_paths
=
[
gpath
+
"
-prokkaRes
"
for
gpath
in
gpaths
]
for
prok_path
in
prok_paths
:
os
.
makedirs
(
prok_path
)
tbl_res
=
os
.
path
.
join
(
prok_path
,
"
toto.tbl
"
)
gff_res
=
os
.
path
.
join
(
prok_path
,
"
toto.gff
"
)
ffn_res
=
os
.
path
.
join
(
prok_path
,
"
toto.ffn
"
)
faa_res
=
os
.
path
.
join
(
prok_path
,
"
toto.faa
"
)
for
file
in
[
tbl_res
,
gff_res
,
ffn_res
,
faa_res
]:
open
(
file
,
"
w
"
).
close
()
# Create output directory for .fna files
rep_dir
=
os
.
path
.
join
(
GENEPATH
,
"
Replicons
"
)
os
.
makedirs
(
rep_dir
)
# genomes = {genome: [name, gpath, to_annot, size, nbcont, l90]}
genomes
=
{
genomes
[
0
]:
[
"
test_wrong-fasta
"
,
gpaths
[
0
],
gpaths
[
0
],
12656
,
3
,
1
],
genomes
[
1
]:
[
"
test_error-fasta
"
,
gpaths
[
1
],
gpaths
[
1
],
456464645
,
5
,
1
]
}
res_path
=
GENEPATH
annotated_path
=
GENEPATH
# Try to format both genomes
skipped_format
=
ffunc
.
format_genomes
(
genomes
,
res_path
,
annotated_path
,
False
,
threads
=
1
)
assert
skipped_format
==
[
"
wrong.fasta
"
,
"
error.fasta
"
]
# Get all names of expected output files
exp_folders
=
[
"
LSTINFO
"
,
"
Proteins
"
,
"
Genes
"
,
"
Replicons
"
,
"
gff3
"
]
for
res_folder
in
[
os
.
path
.
join
(
res_path
,
folder
)
for
folder
in
exp_folders
]:
assert
len
(
os
.
listdir
(
res_folder
))
==
0
# Check log
assert
"
Formatting all genomes
"
in
caplog
.
text
assert
(
"
Your genome test/data/annotate/generated_by_unit-tests/wrong.fasta does not
"
"
contain any sequence, or is not in fasta format.
"
)
in
caplog
.
text
assert
(
"
Your genome test/data/annotate/generated_by_unit-tests/error.fasta does not
"
"
contain any sequence, or is not in fasta format.
"
)
in
caplog
.
text
assert
"
Problems while generating Replicon file for test_wrong-fasta
"
in
caplog
.
text
assert
"
Problems while generating Replicon file for test_error-fasta
"
in
caplog
.
text
def
test_format_1pb_prodigal
(
caplog
):
def
test_format_1pb_prodigal
(
caplog
):
"""
"""
Test that when giving a list of genomes, 1 that is correctly formatted, and 1 has a pb,
Test that when giving a list of genomes, 1 that is correctly formatted, and 1 has a pb,
...
@@ -385,7 +432,7 @@ def test_format_1pb_prodigal(caplog):
...
@@ -385,7 +432,7 @@ def test_format_1pb_prodigal(caplog):
shutil
.
copytree
(
orig_res_files
,
used_res_path
)
shutil
.
copytree
(
orig_res_files
,
used_res_path
)
# genomes = {genome: [name, gpath, to_annot, size, nbcont, l90]}
# genomes = {genome: [name, gpath, to_annot, size, nbcont, l90]}
genomes
=
{
genome1
:
[
"
test_genome1
"
,
gpath1
,
gpath1
,
12656
,
3
,
1
],
genomes
=
{
genome1
:
[
"
test_genome1
"
,
gpath1
,
gpath1
,
12656
,
3
,
1
],
genome2
:
[
"
test_
H299_H561
"
,
gpath2
,
gpath2
,
456464645
,
5
,
1
]
genome2
:
[
"
test_
runprokka_H299
"
,
gpath2
,
gpath2
,
456464645
,
5
,
1
]
}
}
res_path
=
GENEPATH
res_path
=
GENEPATH
annotated_path
=
GENEPATH
annotated_path
=
GENEPATH
...
@@ -398,70 +445,12 @@ def test_format_1pb_prodigal(caplog):
...
@@ -398,70 +445,12 @@ def test_format_1pb_prodigal(caplog):
exp_extensions
=
[
"
.lst
"
,
"
.prt
"
,
"
.gen
"
,
"
.fna
"
,
"
.gff
"
]
exp_extensions
=
[
"
.lst
"
,
"
.prt
"
,
"
.gen
"
,
"
.fna
"
,
"
.gff
"
]
# Check that output files are created, and contain what is expected
# Check that output files are created, and contain what is expected
for
fol
,
ext
in
zip
(
exp_folders
,
exp_extensions
):
for
fol
,
ext
in
zip
(
exp_folders
,
exp_extensions
):
exp_files
=
[
os
.
path
.
join
(
exp_dir
,
fol
,
name
+
ext
)
for
name
in
onames
]
exp_file
=
os
.
path
.
join
(
exp_dir
,
fol
,
"
test_runprokka_H299
"
+
ext
)
res_files
=
[
os
.
path
.
join
(
res_path
,
fol
,
name
+
ext
)
for
name
in
onames
]
res_file
=
os
.
path
.
join
(
res_path
,
fol
,
"
test_runprokka_H299
"
+
ext
)
for
res
,
exp
in
zip
(
res_files
,
exp_files
):
assert
os
.
path
.
isfile
(
res_file
)
assert
os
.
path
.
isfile
(
res
)
assert
tutil
.
compare_order_content
(
res_file
,
exp_file
)
assert
tutil
.
compare_order_content
(
res
,
exp
)
# Check log
# Check log
assert
"
Formatting all genomes
"
in
caplog
.
text
assert
"
Formatting all genomes
"
in
caplog
.
text
assert
(
"
Your genome test/data/annotate/generated_by_unit-tests/wrong.fasta does not
"
# def test_format_all_error():
"
contain any sequence, or is not in fasta format.
"
)
in
caplog
.
text
# """
assert
"
Problems while generating Replicon file for test_genome1
"
in
caplog
.
text
# Test that when giving a list of 2 genomes, prokka ran without problem for both.
# But a problem appears while formatting the 2nd one. So, the 2nd one is not formatted,
# and appears in skipped_format. The first one is formated, and check that all
# output files are created.
# """
# # genomes = {genome: [name, gpath, size, nbcont, l90]}
# name = "test.0417.00002"
# initnames = ["H299_H561.fasta", "B2_A3_5.fasta-changeName.fna"]
# initpaths = [os.path.join("test", "data", "annotate", "genomes", name) for name in initnames]
# gnames = ["H299_H561.fasta-short-contig.fna", "B2_A3_5.fasta-problems.fna-short-contig.fna"]
# onames = ["test_runprokka_H299", "test.0417.00002"]
# gpaths = [os.path.join("test", "data", "annotate", "genomes", name) for name in gnames]
# for f1, f2 in zip(initpaths, gpaths):
# shutil.copyfile(f1, f2)
# genomes = {gnames[0]: [onames[0], gpaths[0], 12656, 3, 1],
# gnames[1]: [onames[1], gpaths[1], 456464645, 5, 1]
# }
# prok_path = os.path.join("test", "data", "annotate", "exp_files")
# res_path = os.path.join("test", "data", "annotate")
# tbl_init = os.path.join(prok_path, "B2_A3_5.fasta-split5N.fna-short-contig.fna-prokkaRes",
# name + ".tbl")
# tblout = os.path.join(prok_path, "B2_A3_5.fasta-problems.fna-short-contig.fna-prokkaRes",
# name + ".tbl")
# shutil.copyfile(tbl_init, tblout)
# gff_init = os.path.join(prok_path, "B2_A3_5.fasta-split5N.fna-short-contig.fna-prokkaRes",
# name + ".gff")
# gffout = os.path.join(prok_path, "B2_A3_5.fasta-problems.fna-short-contig.fna-prokkaRes",
# name + ".gff")
# shutil.copyfile(gff_init, gffout)
# results = {gnames[0]: True, gnames[1]: True}
# skipped, skipped_format = ffunc.format_genomes(genomes, results, res_path, prok_path)
# assert skipped == []
# assert skipped_format == ["B2_A3_5.fasta-problems.fna-short-contig.fna"]
# lstfiles = os.path.join(res_path, "LSTINFO")
# prtfiles = os.path.join(res_path, "Proteins")
# genfiles = os.path.join(res_path, "Genes")
# repfiles = os.path.join(res_path, "Replicons")
# gfffiles = os.path.join(res_path, "gff3")
# assert os.path.isfile(os.path.join(lstfiles, onames[0] + ".lst"))
# assert not os.path.isfile(os.path.join(lstfiles, onames[1] + ".lst"))
# assert os.path.isfile(os.path.join(prtfiles, onames[0] + ".prt"))
# assert not os.path.isfile(os.path.join(prtfiles, onames[1] + ".prt"))
# assert os.path.isfile(os.path.join(genfiles, onames[0] + ".gen"))
# assert not os.path.isfile(os.path.join(genfiles, onames[1] + ".gen"))
# assert os.path.isfile(os.path.join(repfiles, onames[0] + ".fna"))
# assert not os.path.isfile(os.path.join(repfiles, onames[1] + ".fna"))
# assert os.path.isfile(os.path.join(gfffiles, onames[0] + ".gff"))
# assert not os.path.isfile(os.path.join(gfffiles, onames[1] + ".gff"))
# shutil.rmtree(os.path.join(res_path, "LSTINFO"))
# shutil.rmtree(os.path.join(res_path, "Proteins"))
# shutil.rmtree(os.path.join(res_path, "Genes"))
# shutil.rmtree(os.path.join(res_path, "Replicons"))
# shutil.rmtree(os.path.join(res_path, "gff3"))
# os.remove(tblout)
# os.remove(gffout)
# for f in gpaths:
# os.remove(f)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment