Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unpin igraph version #4

Merged
merged 3 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,259 changes: 1,156 additions & 1,103 deletions poetry.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[tool]
[tool.poetry]
name = "pixelgen-pixelator"
name = "pixelator"
version = "0.0.0"
homepage = "https://github.com/PixelgenTechnologies/pixelator"
repository = "https://github.com/PixelgenTechnologies/pixelator"
documentation = ""
description = "Software package to process sequencing FASTQ from Molecular Pixelation (MPX) assays"
documentation = "https://software.pixelgen.com"
description = "A commandline tool and library to process and analyze sequencing data from Molecular Pixelation (MPX) assays."
authors = ["Pixelgen Technologies AB <developers@pixelgen.com>",]
maintainers = [
"Alvaro Martinez Barrio <alvaro.martinez.barrio@pixelgen.com>"
Expand Down Expand Up @@ -36,14 +36,14 @@ cutadapt = ">=4.2"
umi_tools = "<=1.1.4"
pyfastx = "*"
yappi = "*"
igraph = "0.10.2"
pandas = ">=2.0.0"
igraph = "0.10.*"
pandas = "^2.0.0"
numpy = "<1.24.0"
annoy = "<=1.17.0"
esda = "*"
libpysal = "*"
xopen = "*"
anndata = "*"
anndata = ">=0.8.0"
numba = ">=0.56.4"
scanpy = "*"
leidenalg = "*"
Expand All @@ -52,7 +52,7 @@ cssselect = "*"
typing_extensions = "*"
scipy = "*"
pyarrow = "*"
semver = "*"
semver = "^3.0.0"
ruamel-yaml = "^0.17.21"
pydantic = "^1.10.7"
polars = "^0.17.12"
Expand Down Expand Up @@ -80,9 +80,9 @@ pytest-snapshot = "*"
pytest-cov = "*"
pytest-mock = "*"
pytest-dependency = "*"
sphinx-copybutton = "^0.5.2"
sphinx-design = "^0.4.1"
sphinx-inline-tabs = "^2023.4.21"
sphinx-copybutton = ">=0.5.2"
sphinx-design = ">=0.4.1"
sphinx-inline-tabs = ">=2023.4.21"
myst-parser = "^2.0.0"
furo = "^2023.5.20"

Expand Down
20 changes: 10 additions & 10 deletions src/pixelator/graph/community_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import json
import logging
from pathlib import Path
from typing import Dict, List, Optional, Tuple
from typing import Dict, List, Optional, Set, Tuple

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -158,7 +158,7 @@ def community_detection_crossing_edges(
graph: Graph,
leiden_iterations: int = 10,
beta: float = 0,
) -> List[Tuple[str]]:
) -> List[Set[str]]:
"""Detect spurious edges connecting components by community detection.

Use the Leiden [1]_ community detection algorithm to detect communities in a graph.
Expand All @@ -174,8 +174,8 @@ def community_detection_crossing_edges(
:param beta: parameter to control the randomness on cluster selection when Leiden
merges clustering (0 - maximize objective function i.e. modularity;
inf - uniform distribution to merge with any other cluster)
:returns: a list of tuples with the edges between communities (edges ids)
:rtype: List[Tuple[str]]
:returns: a list of sets with the edges between communities (edges ids)
:rtype: List[Set[str]]
:raises AssertionError: if the method is not supported
"""
logger.debug(
Expand Down Expand Up @@ -203,8 +203,8 @@ def community_detection_crossing_edges(
# get the crossing edges
graph.es["is_crossing"] = vertex_clustering.crossing()
edges = graph.es.select(is_crossing_eq=True)
# translate the edges to tuples of their corresponding vertex names
edges = [(e.vertex_tuple[0]["name"], e.vertex_tuple[1]["name"]) for e in edges]
# translate the edges to sets of their corresponding vertex names
edges = [{e.vertex_tuple[0]["name"], e.vertex_tuple[1]["name"]} for e in edges]
logger.debug(
"Community detection detected %i crossing edges in %i communities with a "
"modularity of %f",
Expand All @@ -220,16 +220,16 @@ def community_detection_crossing_edges(
def detect_edges_to_remove(
edgelist: pd.DataFrame,
leiden_iterations: int = 10,
) -> List[Tuple[str]]:
) -> List[Set[str]]:
"""Use Leiden algorithm to detect communities from an edgelist.

This method uses the community detection Leiden algorithm to detect
communities in the whole graph corresponding to the edge list given as input.
Edges connecting the communities are computed and returned.
:param edgelist: The edge list used to create the graph
:param leiden_iterations: the number of iterations for the leiden algorithm
:return: A list of edges (tuple) that are connecting communities
:rtype: List[Tuple[str]]
:return: A list of edges (sets) that are connecting communities
:rtype: List[Set[str]]
"""
logger.debug(
"Detecting edges to remove using the leiden algorithm"
Expand Down Expand Up @@ -320,7 +320,7 @@ def recover_technical_multiplets(
"""

def vertex_name_pairs_to_upis(
edge_tuples: List[Tuple[str]],
edge_tuples: List[Set[str]],
) -> List[str]:
"""Translate each pair of vertices into full UPI info.

Expand Down
7 changes: 6 additions & 1 deletion src/pixelator/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ def from_edgelist(
edgelist.shape[0],
)

graph = igraph.Graph.DataFrame(edgelist, directed=False, use_vids=False)
vertices = pd.DataFrame(
set(edgelist["upia"].unique()).union(set(edgelist["upib"].unique()))
)
graph = igraph.Graph.DataFrame(
edgelist, vertices=vertices, directed=False, use_vids=False
)
if "sequence" in edgelist.columns:
all_sequences = edgelist["sequence"].unique()
logger.debug(
Expand Down
4 changes: 3 additions & 1 deletion src/pixelator/graph/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ def create_node_markers_counts(
if "markers" not in graph.vs.attributes():
raise AssertionError("Could not find 'markers' in vertex attributes")
markers = list(sorted(graph.vs[0]["markers"].keys()))
node_marker_counts = pd.DataFrame.from_records(graph.vs["markers"], columns=markers)
node_marker_counts = pd.DataFrame.from_records(
graph.vs["markers"], columns=markers, index=graph.vs["name"]
)
node_marker_counts = node_marker_counts.reindex(
sorted(node_marker_counts.columns), axis=1
)
Expand Down
4 changes: 2 additions & 2 deletions tests/analysis/colocalization/test_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def test_prepare_from_graph_and_edgelist_eq_for_no_neigbours(edgelist):
# We drop the indexes since whey will be named differently depending on the
# method.
assert_frame_equal(
graph_result.reset_index(drop=True),
edgelist_result.reset_index(drop=True),
graph_result.sort_index().reset_index(drop=True),
edgelist_result.sort_index().reset_index(drop=True),
check_dtype=False,
check_names=False,
check_column_type=False,
Expand Down
2 changes: 0 additions & 2 deletions tests/data/param_files/test_data_pe_T1.annotate.meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"--min-size": 1,
"--max-size": 10000,
"--dynamic-filter": null,
"--cell-type-assignments": false,
"--majority-vote": false,
"--aggregate-calling": true,
"--output": "."
}
Expand Down
2 changes: 0 additions & 2 deletions tests/data/param_files/test_data_pe_T2.annotate.meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"--min-size": 1,
"--max-size": 10000,
"--dynamic-filter": null,
"--cell-type-assignments": false,
"--majority-vote": false,
"--aggregate-calling": true,
"--output": "."
}
Expand Down
4 changes: 2 additions & 2 deletions tests/graph/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_community_detection_crossing_edges(graph_with_communities):
graph=graph_with_communities,
leiden_iterations=2,
)
assert result == [("CTCGTACCTGGGACTGATACT", "TGTAAGTCAGTTGCAGGTTGG")]
assert result == [{"CTCGTACCTGGGACTGATACT", "TGTAAGTCAGTTGCAGGTTGG"}]


def test_community_detection_crossing_edges_no_communities(graph_without_communities):
Expand All @@ -176,4 +176,4 @@ def test_community_detection_crossing_edges_no_communities(graph_without_communi
def test_detect_edges_to_remove(edgelist_with_communities):
"""Test discovery of edges to remove from edgelist."""
result = detect_edges_to_remove(edgelist_with_communities, leiden_iterations=2)
assert result == [("CTCGTACCTGGGACTGATACT", "TGTAAGTCAGTTGCAGGTTGG")]
assert result == [{"CTCGTACCTGGGACTGATACT", "TGTAAGTCAGTTGCAGGTTGG"}]
5 changes: 1 addition & 4 deletions tests/graph/test_graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ def pentagram_graph_fixture():
(4, 1),
(4, 2),
]
edgelist = pd.DataFrame(edges)
# add dummy upia/upib data since the creation methods requires it
edgelist["upia"] = "a"
edgelist["upib"] = "a"
edgelist = pd.DataFrame(edges, columns=["upia", "upib"])
g = Graph.from_edgelist(
edgelist=edgelist,
add_marker_counts=False,
Expand Down
Loading