-
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.
Adds a new option --group-by-weights and some additional options to support the new feature.
- Loading branch information
Showing
7 changed files
with
208 additions
and
3 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
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,37 @@ | ||
import csv | ||
import pandas as pd | ||
from textwrap import dedent | ||
from augur.errors import AugurError | ||
|
||
|
||
WEIGHTS_COLUMN = 'weight' | ||
|
||
|
||
class InvalidWeightsFile(AugurError): | ||
def __init__(self, file, error_message): | ||
super().__init__(f"Bad weights file {file!r}.\n{error_message}") | ||
|
||
|
||
def read_weights_file(weights_file): | ||
weights = pd.read_csv(weights_file, delimiter='\t') | ||
|
||
if not pd.api.types.is_numeric_dtype(weights[WEIGHTS_COLUMN]): | ||
non_numeric_weight_lines = [index + 2 for index in weights[~weights[WEIGHTS_COLUMN].str.isnumeric()].index.tolist()] | ||
raise InvalidWeightsFile(weights_file, dedent(f"""\ | ||
Found non-numeric weights on the following lines: {non_numeric_weight_lines} | ||
{WEIGHTS_COLUMN!r} column must be numeric.""")) | ||
|
||
if any(weights[WEIGHTS_COLUMN] < 0): | ||
negative_weight_lines = [index + 2 for index in weights[weights[WEIGHTS_COLUMN] < 0].index.tolist()] | ||
raise InvalidWeightsFile(weights_file, dedent(f"""\ | ||
Found negative weights on the following lines: {negative_weight_lines} | ||
{WEIGHTS_COLUMN!r} column must be non-negative.""")) | ||
|
||
return weights | ||
|
||
|
||
def get_weighted_columns(weights_file): | ||
with open(weights_file) as f: | ||
weighted_columns = next(csv.reader(f, delimiter='\t')) | ||
weighted_columns.remove('weight') | ||
return weighted_columns |
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 |
---|---|---|
|
@@ -17,3 +17,4 @@ Submodules | |
augur.filter.io | ||
augur.filter.subsample | ||
augur.filter.validate_arguments | ||
augur.filter.weights_file |
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,7 @@ | ||
augur.filter.weights\_file module | ||
================================= | ||
|
||
.. automodule:: augur.filter.weights_file | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |