-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(summary_counts): Translates R code to Python
Closes #110 - Updates `isoslam/default_config.yaml` and `processing` argparse to be consistent. - In turn the `utils.update_config()` function has been corrected with additional tests to correctly update nested dictionaries from the configuration. - Logging is setup and `loguru` used with formatted output and level set from configuration or command line optoins. - Translates the R code that counted and summarised the transcripts to Python code (using Pandas) along with tests. - Necessary updates to `pyproject.toml`. The output from IsoSLAM can now be summarised using... ```bash isoslam --output-dir output summary-counts --file-pattern "tests/**/*.tsv" ``` Rather than calling `Rscript` to do the work. This will serve as a template for translating the other R code.
- Loading branch information
Showing
14 changed files
with
2,169 additions
and
45 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,61 @@ | ||
"""Functions for summarising output.""" | ||
|
||
import pandas as pd | ||
|
||
from isoslam import io | ||
|
||
|
||
def append_files(pattern: str = "**/*.tsv", separator: str = "\t") -> pd.DataFrame: | ||
""" | ||
Append a set of files into a Pandas DataFrames. | ||
Parameters | ||
---------- | ||
pattern : str | ||
File name pattern to search for. | ||
separator : str | ||
Separator/delimiter used in files. | ||
Returns | ||
------- | ||
pd.DataFrame | ||
A Pandas DataFrames of each file found. | ||
""" | ||
_data = io.load_files(pattern, separator) | ||
all_data = [data.assign(filename=key) for key, data in _data.items()] | ||
return pd.concat(all_data) | ||
|
||
|
||
def summary_counts( | ||
file_pattern: str = "**/*.tsv", | ||
separator: str = "\t", | ||
groupby: list[str] | None = None, | ||
dropna: bool = True, | ||
) -> pd.DataFrame: | ||
""" | ||
Count the number of assigned read pairs. | ||
Groups the data by | ||
Parameters | ||
---------- | ||
file_pattern : str | ||
File name pattern to search for. | ||
separator : str | ||
Separator/delimiter used in files. | ||
groupby : list[str] | ||
List of variables to group the counts by. | ||
dropna : book | ||
Whether to drop rows with ``NA`` values. | ||
Returns | ||
------- | ||
pd.DataFrame | ||
A Pandas DataFrames of each file found. | ||
""" | ||
if groupby is None: | ||
groupby = ["Transcript_id", "Chr", "Strand", "Start", "End", "Assignment", "Conversions", "filename"] | ||
_data = append_files(file_pattern, separator) | ||
_data["one_or_more_conversion"] = _data["Conversions"] >= 1 | ||
groupby.append("one_or_more_conversion") | ||
return _data.value_counts(subset=groupby, dropna=dropna).reset_index() |
Oops, something went wrong.