Skip to content

Commit

Permalink
Fixed the error of subset of cell using isin (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
Starlitnightly committed Sep 11, 2024
1 parent a501c93 commit 4f0838a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 38 deletions.
2 changes: 1 addition & 1 deletion omicverse/pp/_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def preprocess(adata, mode='shiftlog|pearson', target_sum=50*1e4, n_HVGs=2000,
adata.var = adata.var.drop(columns=['highly_variable_features'])
adata.var['highly_variable_features'] = adata.var['highly_variable']
adata.var = adata.var.drop(columns=['highly_variable'])
adata.var = adata.var.rename(columns={'means':'mean', 'variances':'var'})
#adata.var = adata.var.rename(columns={'means':'mean', 'variances':'var'})
print(f'End of size normalization: {method_list[0]} and HVGs selection {method_list[1]}')
return adata
def normalize_pearson_residuals(adata,**kwargs):
Expand Down
5 changes: 3 additions & 2 deletions omicverse/single/_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ def batch_correction(adata:anndata.AnnData,batch_key:str,
)

adata3=adata.copy()
scale(adata3)
pca(adata3,layer='scaled',n_pcs=n_pcs)
if 'scaled|original|X_pca' not in adata3.obsm.keys():
scale(adata3)
pca(adata3,layer='scaled',n_pcs=n_pcs)
sc.external.pp.harmony_integrate(adata3, batch_key,basis=use_rep,**kwargs)
adata.obsm['X_harmony']=adata3.obsm['X_pca_harmony'].copy()
return adata3
Expand Down
36 changes: 1 addition & 35 deletions omicverse_guide/docs/Tutorials-single/t_single_batch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -276,40 +276,6 @@
"We can store the raw counts if we need the raw counts after filtered the HVGs."
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "cba5294c-0ade-4f23-807a-4fd71f4f640a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"......The X of adata have been stored in counts\n"
]
},
{
"data": {
"text/plain": [
"AnnData object with n_obs × n_vars = 26707 × 13953\n",
" obs: 'GEX_n_genes_by_counts', 'GEX_pct_counts_mt', 'GEX_size_factors', 'GEX_phase', 'ADT_n_antibodies_by_counts', 'ADT_total_counts', 'ADT_iso_count', 'cell_type', 'batch', 'ADT_pseudotime_order', 'GEX_pseudotime_order', 'Samplename', 'Site', 'DonorNumber', 'Modality', 'VendorLot', 'DonorID', 'DonorAge', 'DonorBMI', 'DonorBloodType', 'DonorRace', 'Ethnicity', 'DonorGender', 'QCMeds', 'DonorSmoker', 'is_train', 'nUMIs', 'mito_perc', 'detected_genes', 'cell_complexity', 'n_genes', 'doublet_score', 'predicted_doublet', 'passing_mt', 'passing_nUMIs', 'passing_ngenes'\n",
" var: 'feature_types', 'gene_id', 'mt', 'n_cells'\n",
" uns: 'scrublet', 'layers_counts'\n",
" obsm: 'ADT_X_pca', 'ADT_X_umap', 'ADT_isotype_controls', 'GEX_X_pca', 'GEX_X_umap'\n",
" layers: 'counts'"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ov.utils.store_layers(adata,layers='counts')\n",
"adata"
]
},
{
"cell_type": "code",
"execution_count": 10,
Expand Down Expand Up @@ -431,7 +397,7 @@
],
"source": [
"ov.pp.scale(adata)\n",
"ov.pp.pca(adata,layer='scaled',n_pcs=50)\n",
"ov.pp.pca(adata,layer='scaled',n_pcs=50,mask_var='highly_variable_features')\n",
"\n",
"adata.obsm[\"X_mde_pca\"] = ov.utils.mde(adata.obsm[\"scaled|original|X_pca\"])"
]
Expand Down

0 comments on commit 4f0838a

Please sign in to comment.