Skip to content

Commit

Permalink
blackify
Browse files Browse the repository at this point in the history
  • Loading branch information
Mittmich committed Oct 7, 2023
1 parent c6acee8 commit fec8644
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/black_lint_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install spoc, black and pylint
run: pip install . && pip install black==23.9.1 && pip install pylint==2.15.5
- name: Run black
run: black --check --extend-exclude .
run: black --check .
- name: Run pylint
run: pylint --fail-under=8 spoc/* tests/test_*.py
- name: Run tests
Expand Down
10 changes: 5 additions & 5 deletions spoc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def expand(fragments_path, expanded_contacts_path, n_fragments):
fragments_path (str): Path to the labelled fragments file.
expanded_contacts_path (str): Path to the output contacts file.
n_fragments (int, optional): Number of fragments per read to expand. Defaults to 3.
"""
expander = FragmentExpander(number_fragments=n_fragments)
file_manager = FileManager()
Expand All @@ -49,7 +49,7 @@ def annotate(fragments_path, label_library_path, labelled_fragments_path):
fragments_path (str): Path to the input fragments file.
label_library_path (str): Path to the label library file.
labelled_fragments_path (str): Path to the output labelled fragments file.
"""
file_manager = FileManager()
label_library = file_manager.load_label_library(label_library_path)
Expand All @@ -71,13 +71,13 @@ def bin_contacts(
same_chromosome,
):
"""Script for binning contacts
Args:
contact_path (str): Path to the input contact file.
pixel_path (str): Path to the output pixel file.
bin_size (int, optional): Size of the bins. Defaults to 10000.
same_chromosome (bool, optional): Only bin contacts on the same chromosome. Defaults to False.
"""
# load data from disk
file_manager = FileManager(use_dask=True)
Expand All @@ -99,7 +99,7 @@ def merge():
@click.option("-o", "--output", help="output path")
def merge_contacts(contact_paths, output):
"""Functionality to merge annotated fragments
Args:
contact_paths (tuple): Paths to the input contact files.
output (str, optional): Path to the output merged contact file.
Expand Down
20 changes: 10 additions & 10 deletions spoc/contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

class Contacts:
"""N-way genomic contacts
Args:
contact_frame (DataFrame): DataFrame containing the contact data.
number_fragments (int, optional): Number of fragments. Defaults to None.
metadata_combi (List[str], optional): List of metadata combinations. Defaults to None.
label_sorted (bool, optional): Whether the labels are sorted. Defaults to False.
binary_labels_equal (bool, optional): Whether the binary labels are equal. Defaults to False.
symmetry_flipped (bool, optional): Whether the symmetry is flipped. Defaults to False.
Attributes:
contains_metadata (bool): Whether the contact data contains metadata.
number_fragments (int): Number of fragments.
Expand Down Expand Up @@ -107,7 +107,7 @@ def data(self):
@data.setter
def data(self, contact_frame):
"""Sets the contact data
Args:
contact_frame (DataFrame): DataFrame containing the contact data.
"""
Expand All @@ -123,7 +123,7 @@ class ContactManipulator:

def merge_contacts(self, merge_list: List[Contacts]) -> Contacts:
"""Merge contacts
Args:
merge_list (List[Contacts]): List of Contacts objects to merge.
Expand Down Expand Up @@ -274,7 +274,7 @@ def _flip_labelled_contacts(

def sort_labels(self, contacts: Contacts) -> Contacts:
"""Sorts labels in ascending, alphabetical order
Args:
contacts (Contacts): Contacts object to sort.
Expand Down Expand Up @@ -367,7 +367,7 @@ def _generate_binary_label_mapping(
def equate_binary_labels(self, contacts: Contacts) -> Contacts:
"""
Equate binary labels.
Binary labels often only carry information about whether
they happen between the same or different fragments. This
method equates these labels be replacing all equivalent binary labels with
Expand Down Expand Up @@ -423,14 +423,14 @@ def subset_on_metadata(
self, contacts: Contacts, metadata_combi: List[str]
) -> Contacts:
"""Subset contacts based on metadata
Args:
contacts (Contacts): Contacts object to subset.
metadata_combi (List[str]): List of metadata combinations to subset on.
Returns:
Contacts: Subsetted Contacts object.
"""
# check if metadata is present
assert contacts.contains_metadata, "Contacts do not contain metadata!"
Expand Down Expand Up @@ -462,14 +462,14 @@ def flip_symmetric_contacts(
self, contacts: Contacts, sort_chromosomes: bool = False
) -> Contacts:
"""Flips contacts based on inherent symmetry
Args:
contacts (Contacts): Contacts object to flip symmetric contacts.
sort_chromosomes (bool, optional): Whether to sort chromosomes. Defaults to False.
Returns:
Contacts: Contacts object with flipped symmetric contacts.
"""
if contacts.contains_metadata:
if not contacts.label_sorted:
Expand Down
14 changes: 7 additions & 7 deletions spoc/dataframe_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

class ContactSchema:
"""Dynamic schema for N-way contacts
Args:
number_fragments (int, optional): Number of fragments. Defaults to 3.
contains_metadata (bool, optional): Whether the contact data contains metadata. Defaults to True.
Expand Down Expand Up @@ -103,7 +103,7 @@ def _expand_contact_fields(
def validate_header(self, data_frame: DataFrame) -> None:
"""Validates only header, needed to validate that dask taskgraph can be built before
evaluation.
Args:
data_frame (DataFrame): The DataFrame to validate.
"""
Expand All @@ -115,7 +115,7 @@ def validate_header(self, data_frame: DataFrame) -> None:

def validate(self, data_frame: DataFrame) -> DataFrame:
"""Validate multiway contact dataframe
Args:
data_frame (DataFrame): The DataFrame to validate.
"""
Expand All @@ -125,7 +125,7 @@ def validate(self, data_frame: DataFrame) -> DataFrame:

class PixelSchema:
"""Dynamic schema for N-way pixels
Args:
number_fragments (int, optional): Number of fragments. Defaults to 3.
same_chromosome (bool, optional): Whether the fragments are on the same chromosome. Defaults to True.
Expand Down Expand Up @@ -172,7 +172,7 @@ def _expand_contact_fields(self, expansions: Iterable = (1, 2, 3)) -> dict:
def validate_header(self, data_frame: DataFrame) -> None:
"""Validates only header, needed to validate that dask taskgraph can be built before
evaluation
Args:
data_frame (DataFrame): The DataFrame to validate.
"""
Expand All @@ -184,9 +184,9 @@ def validate_header(self, data_frame: DataFrame) -> None:

def validate(self, data_frame: DataFrame) -> DataFrame:
"""Validate multiway contact dataframe
Args:
data_frame (DataFrame): The DataFrame to validate.
"""
return self._schema.validate(data_frame)
20 changes: 10 additions & 10 deletions spoc/fragments.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Fragments:
"""Genomic fragments that can be labelled or not.
Args:
fragment_frame (DataFrame): DataFrame containing the fragment data.
"""
Expand All @@ -25,7 +25,7 @@ def __init__(self, fragment_frame: DataFrame) -> None:
@property
def data(self) -> DataFrame:
"""Returns the underlying dataframe.
Returns:
DataFrame: Fragment data.
"""
Expand All @@ -34,7 +34,7 @@ def data(self) -> DataFrame:
@property
def contains_metadata(self) -> bool:
"""Returns whether the dataframe contains metadata.
Returns:
bool: Whether the fragment data contains metadata.
"""
Expand All @@ -43,7 +43,7 @@ def contains_metadata(self) -> bool:
@property
def is_dask(self) -> bool:
"""Returns whether the underlying dataframe is dask.
Returns:
bool: Whether the underlying dataframe is a dask dataframe.
"""
Expand All @@ -53,7 +53,7 @@ def is_dask(self) -> bool:
# TODO: make generic such that label library can hold arbitrary information
class FragmentAnnotator:
"""Responsible for annotating labels and sister identity of mapped read fragments.
Args:
label_library (Dict[str, bool]): Dictionary containing the label library.
"""
Expand Down Expand Up @@ -93,13 +93,13 @@ def annotate_fragments(self, fragments: Fragments) -> Fragments:
"""Takes fragment dataframe and returns a copy of it with its labelling state in a separate
column with name `is_labelled`. If drop_uninformative is true, drops fragments that
are not in label library.
Args:
fragments (Fragments): Fragments object containing the fragment data.
Returns:
Fragments: Fragments object with annotated fragment data.
"""
return Fragments(
fragments.data.assign(is_labelled=self._assign_label_state)
Expand All @@ -112,11 +112,11 @@ def annotate_fragments(self, fragments: Fragments) -> Fragments:
class FragmentExpander:
"""Expands n-way fragments over sequencing reads
to yield contacts.
Args:
number_fragments (int): Number of fragments.
contains_metadata (bool, optional): Whether the fragment data contains metadata. Defaults to True.
"""

def __init__(self, number_fragments: int, contains_metadata: bool = True) -> None:
Expand Down Expand Up @@ -162,7 +162,7 @@ def _expand_single_read(

def expand(self, fragments: Fragments) -> Contacts:
"""expand contacts n-ways
Args:
fragments (Fragments): Fragments object containing the fragment data.
Expand Down
Loading

0 comments on commit fec8644

Please sign in to comment.