Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add unit tests #72

Merged
merged 71 commits into from
Apr 29, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
2232d22
ci: add pytest
Apr 18, 2023
81395b4
build: add pysam dependency
Apr 18, 2023
9939b34
build: add pytest and coverage dependencies
Apr 18, 2023
c0251c4
refactor: add necessary things to pass pytest
Apr 18, 2023
8215e29
test: add test for filter_multimappers.py
Apr 18, 2023
b5b4603
test: add test file for filter_multimappers.py
Apr 18, 2023
43c781b
Merge branch 'dev' into 52-unit-tests-filter_multimapperpy
Apr 18, 2023
e67c9e7
refactor: change some lines
Apr 18, 2023
a278770
revert: revert to initial version
Apr 18, 2023
6aa1eae
test: remove test file
Apr 19, 2023
6295932
test: remove test file
Apr 19, 2023
28983c1
test: add test file
Apr 19, 2023
01bcae4
test: modify test_write_output
Apr 19, 2023
748d022
build: add pysam dependencies
Apr 19, 2023
cbdaa54
test: add coverage file
Apr 19, 2023
4cfb0d0
Delete snakemake_report.html
deliaBlue Apr 19, 2023
8be6c3f
build: delete unused import
Apr 19, 2023
b00b4f2
Merge branch '52-unit-tests-filter_multimapperpy' of https://github.c…
Apr 19, 2023
7402a9b
Merge branch 'dev' into 52-unit-tests-filter_multimapperpy
deliaBlue Apr 25, 2023
b53b1f1
build: remove pysam dependency
Apr 25, 2023
951e236
build: remove pytest-cov and add pysam dependency
Apr 25, 2023
9dc606d
ci: remove .coverage
Apr 25, 2023
32deaa0
refacor: change path to files
Apr 25, 2023
6405449
ci: ypdate unit tests call
Apr 25, 2023
f82577d
test: add files for testing
Apr 25, 2023
2eb3de2
test: add test for secondary and supp. alingments
Apr 25, 2023
dd8629f
test: add pragma to avoid testing
Apr 25, 2023
df55d5a
ci: update codecov-actions to v3
Apr 25, 2023
20b159a
ci: update pytest call
Apr 25, 2023
4539b26
build: add pytest-cov dependency
Apr 25, 2023
1afdb11
ci: update pytest call
Apr 25, 2023
3c8178e
ci: update pytest call
Apr 25, 2023
4f06661
ci: update pytest call
Apr 25, 2023
3e0b86d
ci: update pytest call
Apr 25, 2023
2c2ed1d
ci: update pytest call
Apr 25, 2023
1cdf676
ci: update coverage report call
Apr 25, 2023
3af61b9
ci: update coverage report call
Apr 25, 2023
8ddf80c
ci: update coverage report call
Apr 25, 2023
67d812c
ci: update coverage report and pytest call
Apr 25, 2023
81c4047
ci: update coverage report call
Apr 25, 2023
e8576ad
ci: update coverage report call
Apr 25, 2023
81357c1
ci: update coverage report call
Apr 25, 2023
8095d10
ci: update coverage report call
Apr 25, 2023
8a461ea
ci: update coverage report call
Apr 25, 2023
404ba52
ci: update coverage report call
Apr 25, 2023
040c6e1
ci: update coverage report call
Apr 25, 2023
0558b5d
ci: update coverage report call
Apr 25, 2023
821a309
ci: update coverage report call
Apr 25, 2023
702f547
ci: update coverage report call
Apr 26, 2023
fd93b50
ci: update coverage report call
Apr 26, 2023
881e168
ci: update coverage report call
Apr 26, 2023
096dbec
ci: update coverage call
Apr 26, 2023
0735209
ci: update coverage call
Apr 26, 2023
d5e12a8
ci: update coverage call
Apr 26, 2023
97a100b
ci: update coverage call
Apr 26, 2023
bc16bb3
ci: update submit coverage call
Apr 27, 2023
a80753c
style: correct whitespaces in pragma
Apr 27, 2023
1277ead
refactor: change first iteration
Apr 27, 2023
ce4f90c
refactor: delete unuseful tests
Apr 27, 2023
1340b4e
refactor: modify functions
Apr 27, 2023
e735a2b
test: modify output file
Apr 27, 2023
43e6e91
refactor: remove skip secondary alns
Apr 27, 2023
5cbe091
test: add codecov.yml
Apr 27, 2023
ceb40b0
test: add codecov.yml
Apr 27, 2023
aef3e2e
test: add codecov.yml
Apr 27, 2023
af1a423
test: update path on codecov.yml
Apr 27, 2023
d59ff2f
refactor: remove first assignment
Apr 27, 2023
ae9f36e
test: add token in coverage call
Apr 28, 2023
0d872da
build: remove codecov.yml
Apr 28, 2023
d7eaa4c
test: delete coverage call
Apr 28, 2023
28f12eb
style: remove whitespaces
Apr 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .coverage
deliaBlue marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
38 changes: 38 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
defaults:
run:
shell: bash -l {0}

steps:

- name: Checkout Repository
Expand Down Expand Up @@ -43,3 +44,40 @@ jobs:

- name: Run local test
run: bash test/test_workflow_local.sh

unit-testing:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Setup environment
uses: conda-incubator/setup-miniconda@v2
with:
mamba-version: "*"
activate-environment: mirflowz
environment-file: environment.yml
auto-activate-base: false

- name: Update mirflowz env with root packages
run: mamba env update -n mirflowz -f environment.root.yml

- name: Update mirflowz env with dev packages
run: mamba env update -n mirflowz -f environment.dev.yml

- name: run unit tests
run: |
coverage run --source scripts -m pytest
deliaBlue marked this conversation as resolved.
Show resolved Hide resolved
coverage xml

- name: submit coverage report
uses: codecov/codecov-action@v2
deliaBlue marked this conversation as resolved.
Show resolved Hide resolved
with:
token: ${{ secrets.CODECOV_TOKEN }}
deliaBlue marked this conversation as resolved.
Show resolved Hide resolved
files: ./coverage.xml
fail_ci_if_error: true
verbose: true
4 changes: 4 additions & 0 deletions environment.dev.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: mirflowz
channels:
- bioconda
- defaults
dependencies:
- coverage>=7.2
- pytest>=7.1.2
- pytest-cov
deliaBlue marked this conversation as resolved.
Show resolved Hide resolved
- snakefmt
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ channels:
dependencies:
- graphviz=7.1.0
- python=3.9.16
- pysam>=0.21.0
deliaBlue marked this conversation as resolved.
Show resolved Hide resolved
- snakemake=7.24.0
16 changes: 12 additions & 4 deletions scripts/filter_multimappers.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
filter_multimappers.py SAM > SAM
"""
import argparse
from itertools import chain
from pathlib import Path
import sys
from typing import List
Expand Down Expand Up @@ -67,7 +68,7 @@ def parse_arguments():
return parser


def count_indels(aln: pysam.AlignedSegment) -> int:
def count_indels(aln: pysam.libcalignedsegment.AlignedSegment) -> int:
"""Count the number of indels in an alignment based on its CIGAR string.

This function counts the number of indels in the alignment based on the
Expand Down Expand Up @@ -101,7 +102,7 @@ def find_best_alignments(alns: List[pysam.AlignedSegment]) -> List[pysam.Aligned
Retrns:
best_alignments: alignments with the less indels
"""
aln_indels = [(aln, count_indels(alignment=aln)) for aln in alns]
aln_indels = [(aln, count_indels(aln=aln)) for aln in alns]
min_indels = min(aln_indels, key=lambda x: x[1])[1]
best_alignments = [aln for i, (aln, indels) in enumerate(aln_indels) if indels == min_indels]

Expand All @@ -121,7 +122,7 @@ def write_output(alignments: List[pysam.AlignedSegment]) -> None:
if len(alignments) == 1:
sys.stdout.write(alignments[0].to_string() + '\n')
else:
best_alignments = find_best_alignments(alignments=alignments)
best_alignments = find_best_alignments(alns=alignments)
for alignment in best_alignments:
sys.stdout.write(alignment.to_string() + '\n')

Expand All @@ -133,13 +134,20 @@ def main(sam_file: Path) -> None:
sam_file: Path to the input SAM file.
"""
with pysam.AlignmentFile(sam_file, "r") as samfile:

try:
first_alignment = next(samfile)

except StopIteration:
sys.stdout.write(str(samfile.header))
return
deliaBlue marked this conversation as resolved.
Show resolved Hide resolved

sys.stdout.write(str(samfile.header))

current_query = None
current_alignments: list[pysam.AlignedSegment] = []

for alignment in samfile:
for alignment in chain([first_alignment],samfile):
deliaBlue marked this conversation as resolved.
Show resolved Hide resolved

if alignment.is_secondary or alignment.is_supplementary:
continue
deliaBlue marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
4 changes: 4 additions & 0 deletions scripts/tests/files/in_sam_diff_multimappers.sam
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@HD VN:1.0 SO:queryname
@SQ SN:19 LN:600000 M5:f9635dbff42b16049de830a7a121fa12 UR:NA
1-1 16 19 77595 255 14M1D8M * 0 0 GCAGGAGAATCACTGATGTCAG * MD:Z:14^T2A1C3 NH:i:2 NM:i:3 XA:Z:Q XI:i:1
1-1 0 19 330456 255 4M1D1M1I3M1D13M * 0 0 CTGACATCAGTGATTCTCCTGC * MD:Z:4^G4^A13 NH:i:2 NM:i:3 XA:Z:Q XI:i:0
3 changes: 3 additions & 0 deletions scripts/tests/files/in_sam_empty.sam
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@HD VN:1.0 SO:queryname
@SQ SN:19 LN:600000 M5:f9635dbff42b16049de830a7a121fa12 UR:NA
@PG ID:samtools PN:samtools VN:1.16.1 CL:samtools sort -n -o results/test_lib/header_sorted_catMappings.sam results/test_lib/concatenated_header_catMappings.sam
5 changes: 5 additions & 0 deletions scripts/tests/files/in_sam_equal_multimappers.sam
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@HD VN:1.0 SO:queryname
@SQ SN:19 LN:600000 M5:f9635dbff42b16049de830a7a121fa12 UR:NA
1-1 0 19 142777 255 15M1I5M * 0 0 GCTAGGTGGGAGGCTTGAAGC * MD:Z:4C0T14 NH:i:3 NM:i:3 XA:Z:Q XI:i:0
1-1 16 19 270081 255 6M1I14M * 0 0 GCTTCAAGCCTCCCACCTAGC * MD:Z:14G0G4 NH:i:3 NM:i:3 XA:Z:Q XI:i:2
1-1 16 19 545543 255 6M1I14M * 0 0 GCTTCAAGCCTCCCACCTAGC * MD:Z:14A0G4 NH:i:3 NM:i:3 XA:Z:Q XI:i:1
13 changes: 13 additions & 0 deletions scripts/tests/files/in_sam_multimappers.sam
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@HD VN:1.0 SO:queryname
@SQ SN:19 LN:600000 M5:f9635dbff42b16049de830a7a121fa12 UR:NA
1-1 0 19 7589 255 24M * 0 0 ATTTCAAGCCAGGTGGCGTTTTTC * MD:Z:13G10 NH:i:1 NM:i:1
2-1 0 19 63250 255 22M * 0 0 GAAAGCGCTTCGCTTCAGAGTG * MD:Z:11C10 NH:i:1 NM:i:1
3-1 0 19 63251 255 22M * 0 0 AAAGCGCTTCCCTTCAGAGTGA * MD:Z:21T NH:i:1 NM:i:1
4-1 0 19 63250 255 22M * 0 0 TAAAGCGCTTCCCTTCAGAGTG * MD:Z:G21 NH:i:1 NM:i:1
5-1 0 19 7589 255 24M * 0 0 CTTTCAAGCCAGGGGGCGTTTTTC * MD:Z:A23 NH:i:1 NM:i:1
6-1 0 19 7590 255 24M * 0 0 TTTCAAGCCAGGTGGCGTTTTTCT * MD:Z:12G11 NH:i:1 NM:i:1
7-1 0 19 142777 255 15M1I5M * 0 0 GCTAGGTGGGAGGCTTGAAGC * MD:Z:4C0T14 NH:i:3 NM:i:3 XA:Z:Q XI:i:0
7-1 16 19 270081 255 6M1I14M * 0 0 GCTTCAAGCCTCCCACCTAGC * MD:Z:14G0G4 NH:i:3 NM:i:3 XA:Z:Q XI:i:2
7-1 16 19 545543 255 6M1I14M * 0 0 GCTTCAAGCCTCCCACCTAGC * MD:Z:14A0G4 NH:i:3 NM:i:3 XA:Z:Q XI:i:1
8-1 16 19 77595 255 14M1D8M * 0 0 GCAGGAGAATCACTGATGTCAG * MD:Z:14^T2A1C3 NH:i:2 NM:i:3 XA:Z:Q XI:i:1
8-1 0 19 330456 255 4M1D1M1I3M1D13M * 0 0 CTGACATCAGTGATTCTCCTGC * MD:Z:4^G4^A13 NH:i:2 NM:i:3 XA:Z:Q XI:i:0
1 change: 1 addition & 0 deletions scripts/tests/files/out_sam_diff_multimappers.sam
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1-1 16 19 77595 255 14M1D8M * 0 0 GCAGGAGAATCACTGATGTCAG * MD:Z:14^T2A1C3 NM:i:3 XA:Z:Q XI:i:1 NH:i:1 HI:i:1
3 changes: 3 additions & 0 deletions scripts/tests/files/out_sam_empty.sam
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@HD VN:1.0 SO:queryname
@SQ SN:19 LN:600000 M5:f9635dbff42b16049de830a7a121fa12 UR:NA
@PG ID:samtools PN:samtools VN:1.16.1 CL:samtools sort -n -o results/test_lib/header_sorted_catMappings.sam results/test_lib/concatenated_header_catMappings.sam
3 changes: 3 additions & 0 deletions scripts/tests/files/out_sam_equal_multimappers.sam
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1-1 0 19 142777 255 15M1I5M * 0 0 GCTAGGTGGGAGGCTTGAAGC * MD:Z:4C0T14 NM:i:3 XA:Z:Q XI:i:0 NH:i:3 HI:i:1
1-1 16 19 270081 255 6M1I14M * 0 0 GCTTCAAGCCTCCCACCTAGC * MD:Z:14G0G4 NM:i:3 XA:Z:Q XI:i:2 NH:i:3 HI:i:2
1-1 16 19 545543 255 6M1I14M * 0 0 GCTTCAAGCCTCCCACCTAGC * MD:Z:14A0G4 NM:i:3 XA:Z:Q XI:i:1 NH:i:3 HI:i:3
12 changes: 12 additions & 0 deletions scripts/tests/files/out_sam_multimappers.sam
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@HD VN:1.0 SO:queryname
@SQ SN:19 LN:600000 M5:f9635dbff42b16049de830a7a121fa12 UR:NA
1-1 0 19 7589 255 24M * 0 0 ATTTCAAGCCAGGTGGCGTTTTTC * MD:Z:13G10 NH:i:1 NM:i:1
2-1 0 19 63250 255 22M * 0 0 GAAAGCGCTTCGCTTCAGAGTG * MD:Z:11C10 NH:i:1 NM:i:1
3-1 0 19 63251 255 22M * 0 0 AAAGCGCTTCCCTTCAGAGTGA * MD:Z:21T NH:i:1 NM:i:1
4-1 0 19 63250 255 22M * 0 0 TAAAGCGCTTCCCTTCAGAGTG * MD:Z:G21 NH:i:1 NM:i:1
5-1 0 19 7589 255 24M * 0 0 CTTTCAAGCCAGGGGGCGTTTTTC * MD:Z:A23 NH:i:1 NM:i:1
6-1 0 19 7590 255 24M * 0 0 TTTCAAGCCAGGTGGCGTTTTTCT * MD:Z:12G11 NH:i:1 NM:i:1
7-1 0 19 142777 255 15M1I5M * 0 0 GCTAGGTGGGAGGCTTGAAGC * MD:Z:4C0T14 NM:i:3 XA:Z:Q XI:i:0 NH:i:3 HI:i:1
7-1 16 19 270081 255 6M1I14M * 0 0 GCTTCAAGCCTCCCACCTAGC * MD:Z:14G0G4 NM:i:3 XA:Z:Q XI:i:2 NH:i:3 HI:i:2
7-1 16 19 545543 255 6M1I14M * 0 0 GCTTCAAGCCTCCCACCTAGC * MD:Z:14A0G4 NM:i:3 XA:Z:Q XI:i:1 NH:i:3 HI:i:3
8-1 16 19 77595 255 14M1D8M * 0 0 GCAGGAGAATCACTGATGTCAG * MD:Z:14^T2A1C3 NM:i:3 XA:Z:Q XI:i:1 NH:i:1 HI:i:1
7 changes: 7 additions & 0 deletions scripts/tests/files/sam_no_multimappers.sam
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@HD VN:1.0 SO:queryname
@SQ SN:19 LN:600000 M5:f9635dbff42b16049de830a7a121fa12 UR:NA
1-1 0 19 44414 255 21M * 0 0 GAAGGCGCTTCCCTTTGGAGT * MD:Z:21 NH:i:1 NM:i:0
2-1 0 19 44377 255 11M3I11M * 0 0 CTACAAAGGGAGGTAGCACTTTCTC * MD:Z:22 NH:i:1 NM:i:3 XA:Z:Q XI:i:0
3-1 0 19 7590 255 20M3I3M * 0 0 TTTCAAGCCAGGGGGCGTTTCCGTTC * MD:Z:23 NH:i:1 NM:i:3 XA:Z:Q XI:i:0
4-1 0 19 7590 255 23M * 0 0 TTTCAAGTCAGGGGGCGTTTTTC * MD:Z:7C15 NH:i:1 NM:i:1
5-1 0 19 30893 255 32M2I53M * 0 0 CTCAAGCTGTGACTCTCCAGAGGGATGCACTTGATCTCTTATGTGAAAAAAAAGAAGGCGCTTCCCTTTAGAGCGTTACGGTTTGGG * MD:Z:85 NH:i:1 NM:i:2 XA:Z:Q XI:i:0
Loading