Skip to content

Commit

Permalink
Fix colormap and thick_cds bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
emunozdc committed Jun 17, 2024
1 parent 6c2656a commit f4450c4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 77 deletions.
15 changes: 8 additions & 7 deletions src/pyranges_plot/data_preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,17 +339,17 @@ def chrmd_limits(chrmd_df, limits):
# pyranges object
elif type(limits) is pr.PyRanges:
# create dict to map limits
limits_df = limits.df
limits_chrmd_df = limits_df.groupby(
limits_chrmd_df = limits.groupby(
CHROM_COL, group_keys=False, observed=True
).agg({START_COL: "min", END_COL: "max"})
limits_chrmd_dict = limits_chrmd_df.to_dict(orient="index")
# limits_chrmd_dict = limits_chrmd_df.to_dict(orient="index")

# function to get matching values from limits_chrmd_df
def make_min_max(row):
chromosome = str(row.name)
limits = limits_chrmd_dict.get(chromosome)
if limits:
chromosome = row.name[0]
if chromosome in limits_chrmd_df.index:
limits = limits_chrmd_df.loc[chromosome]

return (
limits[START_COL],
limits[END_COL],
Expand All @@ -363,7 +363,8 @@ def make_min_max(row):
# dictionary as limits
else:
chrmd_df["min_max"] = [
limits.get(index) for index in chrmd_df.index
limits.get(index)
for index in list(chrmd_df.index.get_level_values(CHROM_COL))
] # fills with None the chromosomes not specified


Expand Down
67 changes: 0 additions & 67 deletions src/pyranges_plot/example_data.py

This file was deleted.

6 changes: 5 additions & 1 deletion src/pyranges_plot/matplotlib_base/data2plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ def apply_gene_bridge(
# If transcript structure subtract exons
if transcript_str:
cds = df[df["Feature"] == "CDS"]
exons = df[df["Feature"] == "exon"].subtract_ranges(cds)
exons = df[df["Feature"] == "exon"]

# if there are exons and cds, subtract
if sum([cds.empty, exons.empty]) == 2:
exons = exons.subtract_ranges(cds)
df = pr.concat([cds, exons])

# Define depth order
Expand Down
2 changes: 1 addition & 1 deletion src/pyranges_plot/plot_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def plot(
they do not overlap) and False for unpacked (one row per gene).
color_col: str, default None
Name of the column used to color the genes.
Name of the column used to color the genes. If not specified, id_col will be used.
thickness_col: str, default None
Name of the data column with max 2 different values to plot the intervals correspondig to one value to
Expand Down
6 changes: 5 additions & 1 deletion src/pyranges_plot/plotly_base/data2plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ def apply_gene_bridge(
# If transcript structure subtract exons
if transcript_str:
cds = df[df["Feature"] == "CDS"]
exons = df[df["Feature"] == "exon"].subtract_ranges(cds)
exons = df[df["Feature"] == "exon"]

# if there are exons and cds, subtract
if sum([cds.empty, exons.empty]) == 2:
exons = exons.subtract_ranges(cds)
df = pr.concat([cds, exons])

# Define depth order
Expand Down

0 comments on commit f4450c4

Please sign in to comment.