-
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.
Merge pull request #121 from sudlab/ns-rse/110-translate-summarise-co…
…unts
- Loading branch information
Showing
14 changed files
with
2,174 additions
and
48 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.