Skip to content

Commit

Permalink
Applied formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
chaplin89 committed May 20, 2024
1 parent 9887022 commit a2c9bd7
Show file tree
Hide file tree
Showing 114 changed files with 763 additions and 588 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/add-a-new-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ assignees: chaplin89

Hi.
I'd like WGSE-NG to support a new reference:
- [URL](https://url to FASTA here):
- [URL](https://url to FASTA here):
- Build (e.g., 37, 38)

Thank you,
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-pyinstaller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ jobs:
- uses: actions/upload-artifact@v2
with:
name: WGSE
path: ./dist/windows/WGSE-NG.exe
path: ./dist/windows/WGSE-NG.exe
retention-days: 1
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ dist
configuration/main.ini
_build
_static
_templates
_templates
wgse/VERSION.py
8 changes: 0 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,3 @@ repos:
hooks:
- id: isort
name: isort (python)

- repo: local
hooks:
- id: run-tests
name: Run Tests
entry: pytest test
language: system
types: [python]
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"preLaunchTask": "Compile UI"
}
]
}
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@
],
"cmake.configureOnOpen": false,
"git.ignoreLimitWarning": true
}
}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
}
}
]
}
}
4 changes: 2 additions & 2 deletions docs/basic-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ python -m venv .venv
python -m pip install -r requirements.txt
python -m pip install -e .
python main.py
# If this is run from the terminal of an IDE,
# If this is run from the terminal of an IDE,
# at this point you should restart the IDE as
# there are some executables that are installed
# by pip that otherwise won't be found by the IDE.
Expand Down Expand Up @@ -73,4 +73,4 @@ temporary = repository\temp
[alignment_stats]
skip = 40000
samples = 20000
```
```
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.intersphinx",
"myst_parser"
"myst_parser",
]

intersphinx_mapping = {
Expand Down Expand Up @@ -61,4 +61,4 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]
html_static_path = ["_static"]
1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ Indices and tables
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

2 changes: 1 addition & 1 deletion docs/reference-genome.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ manager.genomes.append(
GenomeMetadataLoader().save(manager.genomes)
```

A GUI/CLI way will be added in the future.
A GUI/CLI way will be added in the future.
2 changes: 1 addition & 1 deletion docs/requirements.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Sphinx>=5,<6
sphinx_rtd_theme
myst_parser
myst_parser
2 changes: 1 addition & 1 deletion docs/wgse-library.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# WGSE Library
# WGSE Library
12 changes: 12 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies = [
"jinja2",
"vcf_parser",
"WGSE-NG-3rd-party",
"sentry-sdk"
]

[project.urls]
Expand Down Expand Up @@ -67,3 +68,14 @@ wgse = "wgse.main:main"

[tool.setuptools_scm]
version_file = "wgse/VERSION.py"

[tool.isort]
profile = "black"
line_length = 88

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "--strict-markers"
testpaths = [
"test"
]
12 changes: 0 additions & 12 deletions requirements.txt

This file was deleted.

24 changes: 14 additions & 10 deletions test/test_buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ def test_single_bucket():
assert 0 in sut
assert len(sut) == 1
assert sut[0] == 99



def test_more_run_in_single_bucket():
# Arrange
sequence = LetterRunCollection("Foo", 1000)
sequence.open_run(0)
sequence.close_run(50)

sequence.open_run(51)
sequence.close_run(60)
# Act
Expand All @@ -32,7 +33,8 @@ def test_more_run_in_single_bucket():
assert 0 in sut
assert len(sut) == 1
assert sut[0] == 59



def test_run_in_multiple_buckets():
# Arrange
sequence = LetterRunCollection("Foo", 1000)
Expand All @@ -45,9 +47,10 @@ def test_run_in_multiple_buckets():
assert 0 in sut
assert 1 in sut
assert len(sut) == 2
assert sut[0] == 99 # 0 -> 99
assert sut[1] == 50 # 99 -> 151

assert sut[0] == 99 # 0 -> 99
assert sut[1] == 50 # 99 -> 151


def test_too_many_buckets():
sequence = LetterRunCollection("Foo", 1000)

Expand All @@ -59,7 +62,8 @@ def test_too_many_buckets():

sut = LetterRunBuckets(sequence, 1001, 0).buckets
assert len(sut) == 0



def test_run_end_to_end_divisible():
sequence = LetterRunCollection("Foo", 1000)

Expand All @@ -79,11 +83,11 @@ def test_run_end_to_end_non_divisible():
sut = LetterRunBuckets(sequence, 3, 0).buckets
assert 0 in sut
assert 1 in sut
assert 2 in sut
assert 2 in sut
assert 3 in sut

assert len(sut) == 4
assert sut[0] == 332
assert sut[1] == 332
assert sut[2] == 332
assert sut[3] == 1
assert sut[3] == 1
30 changes: 15 additions & 15 deletions test/test_fasta.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ def test_no_dictionary():
"@HD\tVN:1.0\tSO:unsorted",
"@SQ\tSN:1\tLN:10\tM5:dummy\tUR:file://c:/foo.fa.gz",
]

with pytest.raises(RuntimeError) as e:
genome = MockGenome(MockPath(fa_lines), MockPath(None,False))
genome = MockGenome(MockPath(fa_lines), MockPath(None, False))
sut = FASTALetterCounter(genome)
assert "Unable to find dictionary" in str(e.value)


def test_sequence_not_in_dictionary():
fa_lines = [
">1 irrelevant\n",
Expand All @@ -44,12 +45,13 @@ def test_sequence_not_in_dictionary():
"@SQ\tSN:1\tLN:10\tM5:dummy\tUR:file://c:/foo.fa.gz",
]
pytest.MonkeyPatch().setattr("gzip.open", gzip_open)

with pytest.raises(ValueError) as e:
genome = MockGenome(MockPath(fa_lines), MockPath(dict_lines))
FASTALetterCounter(genome).count_letters()
assert "not present in dictionary" in str(e.value)



def test_fastq():
fa_lines = [
">1 irrelevant\n",
Expand All @@ -62,12 +64,13 @@ def test_fastq():
"@SQ\tSN:1\tLN:10\tM5:dummy\tUR:file://c:/foo.fa.gz",
]
pytest.MonkeyPatch().setattr("gzip.open", gzip_open)

with pytest.raises(RuntimeError) as e:
genome = MockGenome(MockPath(fa_lines), MockPath(dict_lines))
FASTALetterCounter(genome).count_letters()
assert "Expected a FASTA" in str(e.value)



def test_duplicate_sequence():
fa_lines = [
">1 irrelevant\n",
Expand All @@ -80,25 +83,22 @@ def test_duplicate_sequence():
"@SQ\tSN:1\tLN:10\tM5:dummy\tUR:file://c:/foo.fa.gz",
]
pytest.MonkeyPatch().setattr("gzip.open", gzip_open)

with pytest.raises(RuntimeError) as e:
genome = MockGenome(MockPath(fa_lines), MockPath(dict_lines))
FASTALetterCounter(genome).count_letters()
assert "duplicated sequence" in str(e.value)


def test_only_comments():
fa_lines = [
"#Hello\n",
f"#Foo\n"
]
fa_lines = ["#Hello\n", f"#Foo\n"]
dict_lines = [
"@HD\tVN:1.0\tSO:unsorted",
"@SQ\tSN:1\tLN:10\tM5:dummy\tUR:file://c:/foo.fa.gz",
]
pytest.MonkeyPatch().setattr("gzip.open", gzip_open)

with pytest.raises(RuntimeError) as e:
genome = MockGenome(MockPath(fa_lines), MockPath(dict_lines))
FASTALetterCounter(genome).count_letters()
assert "no sequences" in str(e.value)
assert "no sequences" in str(e.value)
9 changes: 5 additions & 4 deletions test/test_fasta_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def test_header_parsed_correctly():
assert sut.metadata.sorted == Sorting.Coordinate
assert sut.metadata.version == "1.0"


def test_unsorted_parsed_correctly():
lines = [
"@HD\tVN:1.0\tSO:unsorted",
Expand All @@ -19,7 +20,8 @@ def test_unsorted_parsed_correctly():
assert len(sut.sequences) == 0
assert sut.metadata.sorted == Sorting.Unsorted
assert sut.metadata.version == "1.0"



def test_unsorted_parsed_correctly():
lines = [
"@HD\tVN:1.0\tSO:unknown",
Expand All @@ -29,10 +31,9 @@ def test_unsorted_parsed_correctly():
assert sut.metadata.sorted == Sorting.Unknown
assert sut.metadata.version == "1.0"


def test_sequences_parsed_correctly():
lines = [
"@SQ\tSN:Seq1\tLN:123\tM5:abcdefabcdef123123\tUR:/directory/genome.fasta"
]
lines = ["@SQ\tSN:Seq1\tLN:123\tM5:abcdefabcdef123123\tUR:/directory/genome.fasta"]
sut = AlignmentMapHeader(lines)
assert sut.metadata is None
assert len(sut.sequences) == 1
Expand Down
25 changes: 16 additions & 9 deletions test/test_microarray_converter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from pathlib import Path
from test.test_fasta import MockPath
from test.utility import MockFile
Expand All @@ -11,35 +10,43 @@
from wgse.microarray.microarray_converter import MicroarrayConverter
from wgse.microarray.microarray_line_formatter import TARGET_FORMATTER_MAP


# def test_every_target_has_formatter():
# assert all(x in TARGET_FORMATTER_MAP for x in MicroarrayConverterTarget)



def test_inexistent_head_folder_raise():
config = RepositoryConfig()
config.metadata = MockPath(exists=False)
microarray_templates = MockPath(exists=False, name="microarray_templates")
microarray_templates.joinpath = lambda x: MockPath([], False if x=="body" else True, x)
microarray_templates.joinpath = lambda x: MockPath(
[], False if x == "body" else True, x
)
config.metadata.joinpath = lambda _: microarray_templates
with pytest.raises(FileNotFoundError) as e:
MicroarrayConverter(config)
assert "template body"



def test_inexistent_head_folder_raise():
config = RepositoryConfig()
config.metadata = MockPath(exists=False)
microarray_templates = MockPath(exists=False, name="microarray_templates")
microarray_templates.joinpath = lambda x: MockPath([], False if x=="head" else True, x)
microarray_templates.joinpath = lambda x: MockPath(
[], False if x == "head" else True, x
)
config.metadata.joinpath = lambda _: microarray_templates
with pytest.raises(FileNotFoundError) as e:
MicroarrayConverter(config)
assert "template head"


def test_inexistent_head_folder_raise():
config = RepositoryConfig()
config.metadata = MockPath(exists=False)
microarray_templates = MockPath(exists=False, name="microarray_templates")
microarray_templates.joinpath = lambda x: MockPath([], False if x=="body" else True, x)
microarray_templates.joinpath = lambda x: MockPath(
[], False if x == "body" else True, x
)
config.metadata.joinpath = lambda _: microarray_templates
with pytest.raises(FileNotFoundError) as e:
MicroarrayConverter(config)
Expand All @@ -56,7 +63,7 @@ def test_inexistent_head_folder_raise():
# input_file = MockFile(["rs1\t1\t1\tAA"])
# output_file = MockFile([])
# output_file.write = lambda x: output_lines.append(x)

# mock_open.side_effect = [input_file, output_file]
# mock_exists.side_effect = [True, True, True, True]
# mock_gzip_open.side_effect = [template_body]
Expand All @@ -65,4 +72,4 @@ def test_inexistent_head_folder_raise():
# config.metadata = Path("blah")
# sut = MicroarrayConverter(config)
# sut.convert(Path("foo"), MicroarrayConverterTarget.Ancestry_v1)
# pass
# pass
Loading

0 comments on commit a2c9bd7

Please sign in to comment.