-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from peterk87/feature/ct-table
Add option to add Ct values to QC stats table from a Ct values table
- Loading branch information
Showing
11 changed files
with
77 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[bumpversion] | ||
current_version = 0.2.4 | ||
current_version = 0.3.0 | ||
commit = True | ||
tag = True | ||
|
||
|
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
Binary file not shown.
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,4 @@ | ||
sample_id ct | ||
Sample1 23 | ||
Sample2 34.8 | ||
Sample3 0 |
Binary file not shown.
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,14 @@ | ||
from xlavir.io import ct | ||
from pathlib import Path | ||
|
||
dirpath = Path(__file__).parent | ||
|
||
|
||
def test_parse_ct_tables(): | ||
expected = {'Sample1': 23.0, 'Sample2': 34.8, 'Sample3': 0.0} | ||
io_ct_dir = dirpath / 'data/io' | ||
for ext in ['.ods', '.tsv', '.xlsx']: | ||
p = io_ct_dir / f'ct{ext}' | ||
assert ct.read_ct_table(p) == expected, \ | ||
f'Should be able to parse Ct values from table with extension="{ext}". ' \ | ||
f'Filename: {p.absolute()}' |
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,45 @@ | ||
from typing import Dict | ||
|
||
import pandas as pd | ||
from pathlib import Path | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def validate_ct_table(df: pd.DataFrame) -> bool: | ||
if df.empty: | ||
logger.error(f'Ct values table is empty! No Ct values present!') | ||
return False | ||
n_rows, n_cols = df.shape | ||
if n_cols != 2: | ||
logger.error( | ||
f'Ct values table expected to only have 2 columns, but {n_cols} were found with names: {", ".join(df.columns)}') | ||
return False | ||
return True | ||
|
||
|
||
def read_ct_table(ct_path: Path) -> Dict[str, float]: | ||
suffix = ct_path.suffix.lower() | ||
if suffix == '.txt': | ||
logger.warning(f'Trying to read "{ct_path.name}" as tab-delimited file with header.') | ||
df = pd.read_table(ct_path) | ||
elif suffix == '.tsv': | ||
df = pd.read_table(ct_path) | ||
elif suffix == '.ods': | ||
df = pd.read_excel(ct_path, engine='odf') | ||
elif suffix == '.csv': | ||
df = pd.read_csv(ct_path) | ||
elif suffix == '.xlsx': | ||
df = pd.read_excel(ct_path) | ||
else: | ||
logger.error(f'Not sure how to parse Ct values table with extension "{suffix}". ' | ||
f'Please provide a tab-delimited file (".tsv"), CSV (".csv"), ' | ||
f'Excel file (".xlsx") or OpenDocument Spreadsheet (".ods").') | ||
return {} | ||
if validate_ct_table(df): | ||
df.columns = ['sample', 'ct'] | ||
logger.info(f'Read table with shape {df.shape} from "{ct_path}"') | ||
return {row.sample: row.ct for row in df.itertuples()} | ||
else: | ||
return {} |
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