ScreenPro2 0.2.1__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022, Abolfazl Arab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.1
2
+ Name: ScreenPro2
3
+ Version: 0.2.1
4
+ Summary: Analyze pooled CRISPR screens
5
+ Requires-Python: >=3.8
6
+ License-File: LICENSE
7
+
@@ -0,0 +1,9 @@
1
+ screenpro/__init__.py,sha256=heNcvrsJwuisUqdpi4kljd2pzC9om9eW-RR7SYGLdfs,62
2
+ screenpro/__version__.py,sha256=HfjVOrpTnmZ-xVFCYSVmX50EXaBQeJteUHG-PD6iQs8,22
3
+ screenpro/load.py,sha256=M6d7jEWp_MIj2e6zK9X0DmthMTKHH3TIaWx3EQ1LP0U,2009
4
+ screenpro/phenoScore.py,sha256=cxScAJ8CjM9vwpMbMsZ73l1XQrHuxtgvdiEWqLN-vwE,3178
5
+ ScreenPro2-0.2.1.dist-info/LICENSE,sha256=IHBn522sDxLGxi5EfDS9CZdqnW11ZeDrUxqkRfIbJR4,1072
6
+ ScreenPro2-0.2.1.dist-info/METADATA,sha256=b273X3qBEv3hthvGaBqtMBbA3cmo91OElHilvJKmzQs,139
7
+ ScreenPro2-0.2.1.dist-info/WHEEL,sha256=bb2Ot9scclHKMOLDEHY6B2sicWOgugjFKaJsT7vwMQo,110
8
+ ScreenPro2-0.2.1.dist-info/top_level.txt,sha256=uOEhN69bjK8D-lUo9aFehqGZQiGp8ouTSdzTDvZ4aek,10
9
+ ScreenPro2-0.2.1.dist-info/RECORD,,
@@ -0,0 +1,6 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.38.4)
3
+ Root-Is-Purelib: true
4
+ Tag: py2-none-any
5
+ Tag: py3-none-any
6
+
@@ -0,0 +1 @@
1
+ screenpro
screenpro/__init__.py ADDED
@@ -0,0 +1,2 @@
1
+ from .__version__ import __version__
2
+ from . import phenoScore
@@ -0,0 +1 @@
1
+ __version__ = "0.2.1"
screenpro/load.py ADDED
@@ -0,0 +1,44 @@
1
+ """load screen datasets
2
+ """
3
+ import pickle
4
+ import pandas as pd
5
+
6
+
7
+ def loadScreenProcessingData(experimentName, collapsedToTranscripts=True, premergedCounts=False):
8
+ """load ScreenProcessing outputs
9
+ (see original code `here <https://github.com/mhorlbeck/ScreenProcessing/blob/master/screen_analysis.py#L70>`__)
10
+ """
11
+ dataDict = {'library': pd.read_csv(experimentName + '_librarytable.txt', sep='\t', header=0, index_col=0),
12
+ 'counts': pd.read_csv(experimentName + '_mergedcountstable.txt', sep='\t', header=list(range(2)),
13
+ index_col=list(range(1))),
14
+ 'phenotypes': pd.read_csv(experimentName + '_phenotypetable.txt', sep='\t', header=list(range(2)),
15
+ index_col=list(range(1)))}
16
+
17
+ if premergedCounts:
18
+ dataDict['premerged counts'] = pd.read_csv(experimentName + '_rawcountstable.txt', sep='\t',
19
+ header=list(range(3)), index_col=list(range(1)))
20
+
21
+ if collapsedToTranscripts:
22
+ dataDict['transcript scores'] = pd.read_csv(experimentName + '_genetable.txt', sep='\t', header=list(range(3)),
23
+ index_col=list(range(2)))
24
+ dataDict['gene scores'] = pd.read_csv(experimentName + '_genetable_collapsed.txt', sep='\t',
25
+ header=list(range(3)), index_col=list(range(1)))
26
+ else:
27
+ dataDict['gene scores'] = pd.read_csv(experimentName + '_genetable.txt', sep='\t', header=list(range(3)),
28
+ index_col=list(range(1)))
29
+
30
+ return dataDict
31
+
32
+
33
+ def write_adata_pkl(adata, name):
34
+ file_name = f'{name}.pkl'
35
+ with open(file_name, 'wb') as file:
36
+ pickle.dump(adata, file)
37
+ print(f'Object successfully saved to "{file_name}"')
38
+
39
+
40
+ def read_adata_pkl(name):
41
+ file_name = f'{name}.pkl'
42
+ with open(file_name, 'rb') as f:
43
+ adata = pickle.load(f)
44
+ return adata
@@ -0,0 +1,100 @@
1
+ """phenoScore module
2
+ """
3
+
4
+ import numpy as np
5
+ import pandas as pd
6
+ import anndata as ad
7
+
8
+ from pydeseq2 import preprocessing
9
+ from scipy.stats import ttest_rel
10
+ # from scipy.stats import mannwhitneyu
11
+ # from statsmodels.stats.multitest import multipletests
12
+
13
+
14
+ def seqDepthNormalization(adata):
15
+ norm_counts, size_factors = preprocessing.deseq2_norm(adata.X)
16
+
17
+ adata.obs['size_factors'] = size_factors
18
+ adata.layers['deseq'] = norm_counts
19
+
20
+
21
+ def getDelta(x,y):
22
+ """log ratio of y / x, averaged across replicates
23
+ """
24
+ return np.mean(np.log1p(y) - np.log1p(x), axis=1)
25
+
26
+
27
+ def getScore(x, y, x_ctrl, y_ctrl, growth_rate):
28
+ """
29
+ """
30
+ ctrl_std = np.std(getDelta(x_ctrl, y_ctrl))
31
+ ctrl_median = np.median(getDelta(x_ctrl, y_ctrl))
32
+
33
+ return ((getDelta(x,y) - ctrl_median) / growth_rate) / ctrl_std
34
+
35
+
36
+ def runPhenoScore(adata, cond1, cond2, growth_rate=1, n_reps=2, test='ttest'):
37
+ # prep fqcounter
38
+ df_cond1 = adata[adata.obs.query(f'condition=="{cond1}"').index[:n_reps], ].to_df('deseq').T
39
+ df_cond2 = adata[adata.obs.query(f'condition=="{cond2}"').index[:n_reps], ].to_df('deseq').T
40
+
41
+ x = df_cond1.to_numpy()
42
+ y = df_cond2.to_numpy()
43
+
44
+ x_ctrl = df_cond1[adata.var.targetType.eq('negCtrl')].to_numpy()
45
+ y_ctrl = df_cond2[adata.var.targetType.eq('negCtrl')].to_numpy()
46
+
47
+ # calculate growth score
48
+ phenotype_score = getScore(x,y,x_ctrl,y_ctrl,growth_rate)
49
+
50
+ adata.var[f'condition_{cond2}_vs_{cond1}_delta'] = phenotype_score
51
+
52
+ # calculate p-values
53
+ if test == 'MW':
54
+ # run Mann-Whitney U rank test on replicates
55
+ pass
56
+ if test == 'ttest':
57
+ # run ttest on replicates
58
+ pvalues = ttest_rel(y, x, axis=1)[1]
59
+ adata.var[f'condition_{cond2}_vs_{cond1}_pvalue'] = pvalues
60
+
61
+ ## calculate FDR
62
+ # Calculate the adjusted p-values using the Benjamini-Hochberg method
63
+ # _, adj_pvalues, _, _ = multipletests(adata.var[f'condition_{cond1}_vs_{cond2}_pvalue'], alpha=0.05, method='fdr_bh')
64
+ # adata.var[f'condition_{cond1}_vs_{cond2}_adj_pvalue'] = adj_pvalues
65
+
66
+
67
+ def ann_score_df(df_in, up_hit='resistance_hit', down_hit='sensitivity_hit', ctrl_label='non-targeting', threshold=10):
68
+ df = df_in.copy()
69
+
70
+ df.columns = ['target', 'score', 'pvalue']
71
+ df['score'] = df['score'].astype(float)
72
+ df['pvalue'] = df['pvalue'].astype(float)
73
+
74
+ pseudo_sd = df[df['target'].str.contains(ctrl_label)]['score'].tolist()
75
+ pseudo_sd = np.std(pseudo_sd)
76
+ # print (pseudo_sd)
77
+
78
+ df['label'] = '.'
79
+
80
+ df.loc[
81
+ (df['score'] > 0) & (~df['target'].str.contains(ctrl_label)) &
82
+ (df['score']/pseudo_sd * -np.log10(df['pvalue']) >= threshold), 'label'
83
+ ] = up_hit
84
+
85
+ df.loc[
86
+ (df['score'] < 0) & (~df['target'].str.contains(ctrl_label)) &
87
+ (df['score']/pseudo_sd * -np.log10(df['pvalue']) <= -threshold), 'label'
88
+ ] = down_hit
89
+
90
+ df.loc[df['target'].str.contains(ctrl_label), 'label'] = ctrl_label
91
+
92
+ df.loc[df['label'] == '.', 'label'] = 'target_non_hit'
93
+
94
+ # reorder factors
95
+ df['label'] = pd.Categorical(
96
+ df['label'],
97
+ categories=[down_hit, up_hit, ctrl_label, 'target_non_hit']
98
+ )
99
+
100
+ return df