-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate read_strains from utils, move to io
- Loading branch information
Showing
7 changed files
with
61 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from augur.utils import read_entries | ||
|
||
|
||
def read_strains(*files, comment_char="#"): | ||
"""Reads strain names from one or more plain text files and returns the | ||
set of distinct strains. | ||
Strain names can be commented with full-line or inline comments. For | ||
example, the following is a valid strain names file:: | ||
# this is a comment at the top of the file | ||
strain1 # exclude strain1 because it isn't sequenced properly | ||
strain2 | ||
# this is an empty line that will be ignored. | ||
Parameters | ||
---------- | ||
files : iterable of str | ||
one or more names of text files with one strain name per line | ||
Returns | ||
------- | ||
set : | ||
strain names from the given input files | ||
""" | ||
return set(read_entries(*files, comment_char=comment_char)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from pathlib import Path | ||
|
||
from augur.io.strains import read_strains | ||
|
||
|
||
def test_read_strains(tmpdir): | ||
# Write one list of filenames with some unnecessary whitespace. | ||
strains1 = Path(tmpdir) / Path("strains1.txt") | ||
with open(strains1, "w") as oh: | ||
oh.write("strain1 # this is an inline comment about strain 1\nstrain2\n # this is a comment preceded by whitespace.\n") | ||
|
||
# Write another list of filenames with a comment. | ||
strains2 = Path(tmpdir) / Path("strains2.txt") | ||
with open(strains2, "w") as oh: | ||
oh.write("# this is a comment. ignore this.\nstrain2\nstrain3\n") | ||
|
||
strains = read_strains(strains1, strains2) | ||
assert len(strains) == 3 | ||
assert "strain1" in strains |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters