@@ -1310,19 +1310,19 @@ def concatenate(self, *adatas, join='inner', batch_key='batch', batch_categories
1310
1310
adatas : :class:`~anndata.AnnData`
1311
1311
AnnData matrices to concatenate with.
1312
1312
join: `str` (default: 'inner')
1313
- Use intersection (``'inner'``) or union (``'outer'``) of variables?
1313
+ Use intersection (``'inner'``) or union (``'outer'``) of variables.
1314
1314
batch_key : `str` (default: 'batch')
1315
1315
Add the batch annotation to `.obs` using this key.
1316
1316
batch_categories : list, optional (default: `range(len(adatas)+1)`)
1317
1317
Use these as categories for the batch annotation.
1318
- index_unique : `str` or `None`, optional (default: '-' )
1319
- Make the index unique by joining the previous index name with the
1320
- batch category. Provide `None` to keep previous indices.
1318
+ index_unique : `str` or `None`, optional (default: None )
1319
+ Make the index unique by joining the existing index names with the
1320
+ batch category. Provide `None` to keep existing indices.
1321
1321
1322
1322
Returns
1323
1323
-------
1324
1324
adata : :class:`~anndata.AnnData`
1325
- The concatenated AnnData, where `adata.obs['batch' ]` stores a
1325
+ The concatenated AnnData, where `adata.obs[batch_key ]` stores a
1326
1326
categorical variable labeling the batch.
1327
1327
1328
1328
Examples
@@ -1360,8 +1360,18 @@ def concatenate(self, *adatas, join='inner', batch_key='batch', batch_categories
1360
1360
return self
1361
1361
elif len (adatas ) == 1 and not isinstance (adatas [0 ], AnnData ):
1362
1362
adatas = adatas [0 ] # backwards compatibility
1363
- all_adatas = (self ,) + adatas
1363
+ all_adatas = (self ,) + tuple ( adatas )
1364
1364
1365
+ # for controlled behavior, make all variable names unique
1366
+ printed_info = False
1367
+ for i , ad in enumerate (all_adatas ):
1368
+ if not ad .var_names .is_unique :
1369
+ ad .var_names = utils .make_index_unique (ad .var_names )
1370
+ if not printed_info :
1371
+ logg .info (
1372
+ 'Making variable names unique for controlled concatenation.' )
1373
+ printed_info = True
1374
+
1365
1375
mergers = dict (inner = set .intersection , outer = set .union )
1366
1376
var_names = pd .Index (reduce (mergers [join ], (set (ad .var_names ) for ad in all_adatas )))
1367
1377
0 commit comments