Skip to content

Commit 3107603

Browse files
committed
More linting and formatting
1 parent a6285d8 commit 3107603

20 files changed

+438
-622
lines changed

pf2rnaseq/figures/commonFuncs/plotGeneral.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
import anndata
12
import numpy as np
23
import pandas as pd
3-
import seaborn as sns
44
import scanpy as sc
5-
from scipy.stats import ranksums
6-
import anndata
5+
import scipy.sparse
6+
import seaborn as sns
77
from matplotlib.axes import Axes
8+
89
from ...factorization import pf2_pca_r2x
9-
import matplotlib.pyplot as plt
10-
import scipy.sparse
1110

1211

1312
def plot_r2x(data, rank_vec, ax: Axes):

pf2rnaseq/figures/commonFuncs/plotPaCMAP.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import anndata
2+
import datashader as ds
3+
import datashader.transfer_functions as tf
4+
import matplotlib.colors
15
import numpy as np
26
import pandas as pd
37
import seaborn as sns
4-
import matplotlib.colors
58
from matplotlib import pyplot as plt
69
from matplotlib.axes import Axes
7-
import datashader as ds
8-
import datashader.transfer_functions as tf
910
from matplotlib.patches import Patch
10-
import anndata
1111
from scipy.sparse import spmatrix
1212

1313

pf2rnaseq/figures/figureCytokineGeneSet.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,18 @@
33
"""
44

55
import pandas as pd
6-
from anndata import read_h5ad
7-
from .common import subplotLabel, getSetup
6+
7+
from ..factorization import correct_conditions, pf2
8+
from ..imports import import_cytokine
9+
from .common import getSetup, subplotLabel
810
from .commonFuncs.plotFactors import (
9-
plot_condition_factors,
10-
plot_eigenstate_factors,
1111
plot_geneSet_factors,
12-
plot_factor_weight,
1312
plot_geneSetScore,
14-
plot_geneSetScoreDot
13+
plot_geneSetScoreDot,
1514
)
16-
from ..factorization import correct_conditions
17-
from ..imports import import_cytokine,import_pf2Cytokine30
18-
from ..factorization import pf2
1915

20-
#plots gene component factors for specifc subset of genes
16+
17+
# plots gene component factors for specifc subset of genes
2118
def samples_only(X) -> pd.DataFrame:
2219
"""Obtain samples once only with corresponding observations"""
2320
samples = X.obs
@@ -34,20 +31,29 @@ def makeFigure():
3431
# Add subplot labels
3532
subplotLabel(ax)
3633
X = import_cytokine()
37-
3834

39-
X = pf2(X, 15,regularize_A=True, regParam=5e-1)
40-
35+
X = pf2(X, 15, regularize_A=True, regParam=5e-1)
36+
4137
X.uns["Pf2_A"] = correct_conditions(X)
42-
43-
immune_suppressive = ["FOXP3","TIGIT","ICOS","IL2RA","PDCD1","TGFB1","SOCS3","PD1", "LAG3","TNFRSF18","CTLA4"]
44-
immune_activating = ["GZMA","GZMAB", "PRF1"]
45-
plot_geneSet_factors(X,ax[0],immune_suppressive, False )
46-
#plot_geneSet_factors(X,ax[1],["GZMA","GZMB","PRF1",], False )
47-
plot_geneSetScore(X,ax[1],immune_suppressive, False )
48-
plot_geneSetScoreDot(X,ax[2],immune_suppressive, False )
49-
plot_geneSetScore(X,ax[3],immune_activating, False )
50-
51-
52-
53-
return f
38+
39+
immune_suppressive = [
40+
"FOXP3",
41+
"TIGIT",
42+
"ICOS",
43+
"IL2RA",
44+
"PDCD1",
45+
"TGFB1",
46+
"SOCS3",
47+
"PD1",
48+
"LAG3",
49+
"TNFRSF18",
50+
"CTLA4",
51+
]
52+
immune_activating = ["GZMA", "GZMAB", "PRF1"]
53+
plot_geneSet_factors(X, ax[0], immune_suppressive, False)
54+
# plot_geneSet_factors(X,ax[1],["GZMA","GZMB","PRF1",], False )
55+
plot_geneSetScore(X, ax[1], immune_suppressive, False)
56+
plot_geneSetScoreDot(X, ax[2], immune_suppressive, False)
57+
plot_geneSetScore(X, ax[3], immune_activating, False)
58+
59+
return f

pf2rnaseq/figures/figureCytokineGenes.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
"""
22
Cytokine: Highly weighted genes per component
33
"""
4-
from anndata import read_h5ad
4+
5+
from ..factorization import correct_conditions, pf2
6+
from ..imports import import_cytokine
57
from .common import getSetup
68
from .commonFuncs.plotFactors import plot_gene_factors_partial
7-
from ..imports import import_cytokine,import_pf2Cytokine30
8-
from ..factorization import correct_conditions
9-
from ..factorization import pf2
109

1110

1211
def makeFigure():
1312
"""Get a list of the axis objects and create a figure."""
1413
# Get list of axis objects
1514
ax, f = getSetup((21, 24), (10, 10))
1615
X = import_cytokine()
17-
#X=read_h5ad("/home/nicoleb/Pf2-scRNAseq-1/pf2rnaseq/Cytokine_Pf2__NB30.h5ad")
18-
#X = import_pf2Cytokine30()
16+
# X=read_h5ad("/home/nicoleb/Pf2-scRNAseq-1/pf2rnaseq/Cytokine_Pf2__NB30.h5ad")
17+
# X = import_pf2Cytokine30()
1918
X = pf2(X, 30, regParam=1e-5, regularize_A=True)
2019

2120
X.uns["Pf2_A"] = correct_conditions(X)

pf2rnaseq/figures/figureCytokineR2X.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,10 @@
22
Plotting the R2X
33
"""
44

5-
import pandas as pd
6-
from anndata import read_h5ad
7-
from .common import subplotLabel, getSetup
8-
from .commonFuncs.plotGeneral import (
9-
plot_r2x
10-
)
11-
from ..factorization import correct_conditions
12-
from ..imports import import_pf2Cytokine30, import_cytokine
135
from ..factorization import pf2
14-
15-
6+
from ..imports import import_cytokine
7+
from .common import getSetup, subplotLabel
8+
from .commonFuncs.plotGeneral import plot_r2x
169

1710

1811
def makeFigure():
@@ -22,11 +15,11 @@ def makeFigure():
2215

2316
# Add subplot labels
2417
subplotLabel(ax)
25-
18+
2619
X = import_cytokine()
27-
20+
2821
X = pf2(X, 30)
29-
ranks=list(range(1, 31))
30-
plot_r2x(X,ranks,ax[0])
22+
ranks = list(range(1, 31))
23+
plot_r2x(X, ranks, ax[0])
3124

3225
return f

pf2rnaseq/figures/figureCytokineRegTest.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
21
"""FMS score for different regularization parameters"""
2+
33
import anndata
44
import numpy as np
55
import pandas as pd
6-
import scanpy as sc
76
import seaborn as sns
7+
import wandb
88
from matplotlib.axes import Axes
99
from tensorly.cp_tensor import CPTensor
1010
from tlviz.factor_tools import factor_match_score as fms
11-
import wandb
11+
1212
from ..factorization import pf2, pf2_pca_r2x
13-
from .common import getSetup, subplotLabel
1413
from ..imports import import_cytokine
14+
from .common import getSetup, subplotLabel
1515

1616
run = wandb.init(
1717
# Set the wandb entity where your project will be logged (generally your team name).
@@ -21,23 +21,19 @@
2121
# Track hyperparameters and run metadata.
2222
config={
2323
"rank": 20,
24-
2524
},
2625
)
2726

2827

29-
3028
def makeFigure():
3129
ax, f = getSetup((6, 3), (1, 1))
3230
subplotLabel(ax)
3331

3432
X = import_cytokine()
3533
lambdaList = [5e-6, 1e-5, 5e-5, 1e-4]
36-
rank=np.arange(1, 31, 5)
34+
rank = np.arange(1, 31, 5)
3735
plot_fms_diff_reg(X, ax[0], 20, lambdaList, runs=3)
3836

39-
40-
4137
return f
4238

4339

@@ -76,22 +72,23 @@ def plot_fms_diff_reg(
7672
regsList: list[float],
7773
runs: int,
7874
):
79-
#Plots FMS when using different regularization params
75+
# Plots FMS when using different regularization params
8076
fmsLists = []
8177

8278
for j in range(0, runs, 1):
8379
scores = []
8480
for r in rank:
8581
for i in regsList:
86-
dataX = pf2(X, rank=r, random_state=j, doEmbedding=False,regParam=i)
82+
dataX = pf2(X, rank=r, random_state=j, doEmbedding=False, regParam=i)
8783

88-
sampledX = pf2(resample(X), rank=r, random_state=j, doEmbedding=False, regParam=i)
84+
sampledX = pf2(
85+
resample(X), rank=r, random_state=j, doEmbedding=False, regParam=i
86+
)
8987
r2xError = pf2_pca_r2x(dataX, r)
9088
fmsScore = calculateFMS(dataX, sampledX)
9189
scores.append(fmsScore)
92-
run.log({"fms": fmsScore,"regParam": i,"rank": r, "R2X": r2xError})
90+
run.log({"fms": fmsScore, "regParam": i, "rank": r, "R2X": r2xError})
9391
fmsLists.append(scores)
94-
9592

9693
runsList_df = []
9794
for i in range(0, runs):
@@ -114,4 +111,3 @@ def plot_fms_diff_reg(
114111
run.finish()
115112
sns.lineplot(data=df, x="Parameter", y="FMS", ax=ax)
116113
ax.set_ylim(0, 1)
117-

pf2rnaseq/figures/figureHeiser1.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@
33
"""
44

55
import pandas as pd
6-
import numpy as np
7-
import scipy.sparse as sp
8-
from anndata import read_h5ad, AnnData
9-
import anndata as an
10-
from .common import subplotLabel, getSetup
6+
7+
from ..factorization import correct_conditions, pf2
8+
from ..imports import import_Heiser
9+
from .common import getSetup, subplotLabel
1110
from .commonFuncs.plotFactors import (
1211
plot_condition_factors_groups,
1312
plot_eigenstate_factors,
14-
plot_gene_factors,
1513
plot_factor_weight,
14+
plot_gene_factors,
1615
)
17-
from ..factorization import correct_conditions
18-
from ..imports import import_Heiser
19-
from ..factorization import pf2
2016

2117

2218
def samples_only(X) -> pd.DataFrame:

pf2rnaseq/figures/figureHeiserCellPac.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
"Plot cell lineage pacmap"
22

3-
import pandas as pd
43
from anndata import read_h5ad
5-
from .common import subplotLabel, getSetup
6-
from .commonFuncs.plotPaCMAP import plot_labels_pacmap
7-
from ..factorization import correct_conditions
84

9-
from ..factorization import pf2
5+
from .common import getSetup, subplotLabel
6+
from .commonFuncs.plotPaCMAP import plot_labels_pacmap
107

118

129
def makeFigure():

pf2rnaseq/figures/figureHeiserCellTypePer.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
Cell type percentage per Leiden cluster per condition
33
"""
44

5-
from anndata import read_h5ad
6-
from ..imports import import_Heiser
7-
from .common import subplotLabel, getSetup
85
import seaborn as sns
6+
7+
from ..imports import import_Heiser
8+
from .common import getSetup, subplotLabel
99
from .commonFuncs.plotGeneral import cell_count_perc_df
1010

1111

@@ -17,11 +17,8 @@ def makeFigure():
1717
# Add subplot labels
1818
subplotLabel(ax)
1919

20-
21-
2220
X = import_Heiser()
2321

24-
2522
df = cell_count_perc_df(X, celltype="cell_type_1", grouping="expBatch")
2623

2724
sns.barplot(

pf2rnaseq/figures/figureHeiserCompPac.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22
Weighted projections per component in PaCMAP and boxplot of cell types
33
"""
44

5-
import pandas as pd
65

76
import numpy as np
8-
from .common import subplotLabel, getSetup
9-
from anndata import read_h5ad
7+
8+
from ..factorization import correct_conditions, pf2
9+
from ..imports import import_Heiser
10+
from .common import getSetup, subplotLabel
1011
from .commonFuncs.plotPaCMAP import (
11-
plot_wp_per_celltype,
1212
plot_wp_pacmap,
13+
plot_wp_per_celltype,
1314
)
14-
from ..factorization import correct_conditions
15-
from ..imports import import_Heiser
16-
from ..factorization import pf2
1715

1816

1917
def makeFigure():

0 commit comments

Comments
 (0)