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

Modify graphs.py to handle insertions when {'insertions': True} #223

Merged
merged 12 commits into from
Dec 8, 2022
Prev Previous commit
Next Next commit
update graphs.py to handle insertions
  • Loading branch information
manon Réau committed Oct 24, 2022
commit b4e150a61877ac1fd333082eb0dd920142dc9e9e
8 changes: 6 additions & 2 deletions graphein/protein/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ def label_node_id(df: pd.DataFrame, granularity: str) -> pd.DataFrame:
+ df["residue_name"]
+ ":"
+ df["residue_number"].apply(str)
+ ":"
+ df["insertion"].apply(str)
)
df["residue_id"] = df["node_id"]
if granularity == "atom":
Expand Down Expand Up @@ -354,7 +356,7 @@ def sort_dataframe(df: pd.DataFrame) -> pd.DataFrame:
:return: Sorted protein dataframe.
:rtype: pd.DataFrame
"""
return df.sort_values(by=["chain_id", "residue_number", "atom_number"])
return df.sort_values(by=["chain_id", "residue_number", "atom_number", "insertion"])


def assign_node_id_to_dataframe(
Expand All @@ -379,6 +381,8 @@ def assign_node_id_to_dataframe(
+ protein_df["residue_name"]
+ ":"
+ protein_df["residue_number"].apply(str)
+ ":"
+ protein_df["insertion"].apply(str)
)
if granularity in {"atom", "rna_atom"}:
protein_df[
Expand Down Expand Up @@ -546,7 +550,7 @@ def calculate_centroid_positions(
:rtype: pd.DataFrame
"""
centroids = (
atoms.groupby(["residue_number","chain_id","residue_name"])
atoms.groupby(["residue_number","chain_id","residue_name", "insertion"])
.mean()[["x_coord", "y_coord", "z_coord"]]
.reset_index()
)
Expand Down