@@ -1053,7 +1053,7 @@ def plot_feature(self, feature_id, sample_ids=None,
1053
1053
phenotype_to_color = None ,
1054
1054
phenotype_to_marker = None , nmf_xlabel = None ,
1055
1055
nmf_ylabel = None ,
1056
- nmf_space = False , fig = None , axesgrid = None ):
1056
+ nmf_space = False , fig = None , axesgrid = None , n = 20 ):
1057
1057
"""
1058
1058
Plot the violinplot of a feature. Have the option to show NMF movement
1059
1059
"""
@@ -1101,13 +1101,13 @@ def plot_feature(self, feature_id, sample_ids=None,
1101
1101
phenotype_to_color = phenotype_to_color ,
1102
1102
phenotype_to_marker = phenotype_to_marker ,
1103
1103
order = phenotype_order , ax = axes [1 ],
1104
- xlabel = nmf_xlabel , ylabel = nmf_ylabel )
1104
+ xlabel = nmf_xlabel , ylabel = nmf_ylabel , n = n )
1105
1105
except KeyError :
1106
1106
continue
1107
1107
sns .despine ()
1108
1108
fig .tight_layout ()
1109
1109
1110
- def nmf_space_positions (self , groupby , n = 0.5 ):
1110
+ def nmf_space_positions (self , groupby , n = 20 ):
1111
1111
"""Calculate NMF-space position of splicing events in phenotype groups
1112
1112
1113
1113
Parameters
@@ -1138,16 +1138,17 @@ def nmf_space_positions(self, groupby, n=0.5):
1138
1138
# lambda x: x if x.count() >= n else pd.Series(np.nan,
1139
1139
# index=x.index))
1140
1140
df = at_least_n_per_group_per_event .groupby (groupby ).apply (
1141
- lambda x : self .binned_nmf_reduced (data = x ))
1141
+ lambda x : self .binned_nmf_reduced (data = x ) if
1142
+ x .notnull ().sum ().sum () > 0 else pd .DataFrame ())
1142
1143
df = df .swaplevel (0 , 1 )
1143
1144
df = df .sort_index ()
1144
1145
return df
1145
1146
1146
1147
def plot_nmf_space_transitions (self , feature_id , groupby ,
1147
1148
phenotype_to_color ,
1148
1149
phenotype_to_marker , order , ax = None ,
1149
- xlabel = None , ylabel = None ):
1150
- nmf_space_positions = self .nmf_space_positions (groupby )
1150
+ xlabel = None , ylabel = None , n = 20 ):
1151
+ nmf_space_positions = self .nmf_space_positions (groupby , n = n )
1151
1152
1152
1153
nmf_space_transitions (nmf_space_positions , feature_id ,
1153
1154
phenotype_to_color ,
@@ -1156,7 +1157,7 @@ def plot_nmf_space_transitions(self, feature_id, groupby,
1156
1157
1157
1158
@staticmethod
1158
1159
def transition_distances (positions , transitions ):
1159
- """Get NMF distance of features between phenotype transitions
1160
+ """Get cartesian distance of phenotype transitions in NMF space
1160
1161
1161
1162
Parameters
1162
1163
----------
@@ -1186,7 +1187,7 @@ def transition_distances(positions, transitions):
1186
1187
pass
1187
1188
return distances
1188
1189
1189
- def nmf_space_transitions (self , groupby , phenotype_transitions , n = 0.5 ):
1190
+ def nmf_space_transitions (self , groupby , phenotype_transitions , n = 20 ):
1190
1191
"""Get distance in NMF space of different splicing events
1191
1192
1192
1193
Parameters
@@ -1225,78 +1226,6 @@ def nmf_space_transitions(self, groupby, phenotype_transitions, n=0.5):
1225
1226
axis = 0 )
1226
1227
return nmf_space_transitions
1227
1228
1228
- def big_nmf_space_transitions (self , groupby , phenotype_transitions , n = 0.5 ):
1229
- """Get features whose change in NMF space between phenotypes is large
1230
-
1231
- Parameters
1232
- ----------
1233
- groupby : mappable
1234
- A sample id to phenotype group mapping
1235
- phenotype_transitions : list of length-2 tuples of str
1236
- List of ('phenotype1', 'phenotype2') transitions whose change in
1237
- distribution you are interested in
1238
- n : int
1239
- Minimum number of samples per phenotype, per event
1240
-
1241
- Returns
1242
- -------
1243
- big_transitions : pandas.DataFrame
1244
- A (n_events, n_transitions) dataframe of the NMF distances between
1245
- splicing events
1246
- """
1247
- nmf_space_transitions = self .nmf_space_transitions (
1248
- groupby , phenotype_transitions , n = n )
1249
-
1250
- # get the mean and standard dev of the whole array
1251
- n = nmf_space_transitions .count ().sum ()
1252
- mean = nmf_space_transitions .sum ().sum () / n
1253
- std = np .sqrt (np .square (nmf_space_transitions - mean ).sum ().sum () / n )
1254
-
1255
- big_transitions = nmf_space_transitions [
1256
- nmf_space_transitions > (mean + std )].dropna (how = 'all' )
1257
- return big_transitions
1258
-
1259
- def plot_big_nmf_space_transitions (self , phenotype_groupby ,
1260
- phenotype_transitions ,
1261
- phenotype_order , color ,
1262
- phenotype_to_color ,
1263
- phenotype_to_marker , n = 0.5 ):
1264
- """Violinplots and NMF transitions of features different in phenotypes
1265
-
1266
- Plot violinplots and NMF-space transitions of features that have large
1267
- NMF-space transitions between different phenotypes
1268
-
1269
- Parameters
1270
- ----------
1271
- n : int
1272
- Minimum number of samples per phenotype, per event
1273
-
1274
-
1275
- Returns
1276
- -------
1277
-
1278
-
1279
- Raises
1280
- ------
1281
- """
1282
- big_transitions = self .big_nmf_space_transitions (phenotype_groupby ,
1283
- phenotype_transitions ,
1284
- n = n )
1285
- nrows = big_transitions .shape [0 ]
1286
- ncols = 2
1287
- figsize = 4 * ncols , 4 * nrows
1288
-
1289
- fig , axesgrid = plt .subplots (nrows = nrows , ncols = ncols ,
1290
- figsize = figsize )
1291
- if nrows == 1 :
1292
- axesgrid = [axesgrid ]
1293
- for feature_id in big_transitions .index :
1294
- self .plot_feature (feature_id , phenotype_groupby = phenotype_groupby ,
1295
- phenotype_order = phenotype_order , color = color ,
1296
- phenotype_to_color = phenotype_to_color ,
1297
- phenotype_to_marker = phenotype_to_marker ,
1298
- nmf_space = True , fig = fig , axesgrid = axesgrid )
1299
-
1300
1229
def plot_two_samples (self , sample1 , sample2 , fillna = None ,
1301
1230
** kwargs ):
1302
1231
"""
0 commit comments