Hi Bioinformatician and mathematician : I have datasets on the folder. Data were generated using scRNA seq and in the format of h5 file. Now, we need to pre-process these files using this code (#PRE-PROCESSING

import os
import numpy as np
import pandas as pd
import anndata
import scanpy as sc
import scvi
import scipy.io
import matplotlib.pyplot as plt

def load_data_from_files(matrix_path, barcodes_path, features_path):
    # Load the matrix file and transpose it
    matrix = scipy.io.mmread(matrix_path).transpose()
    
    # Load the barcodes and features files
    barcodes_df = pd.read_csv(barcodes_path, header=None, sep='\t', names=['barcode'])
    features_df = pd.read_csv(features_path, header=None, sep='\t', index_col=0, names=['gene_id', 'gene_symbols'])
    
    # Create an AnnData object
    adata = anndata.AnnData(X=matrix, obs=barcodes_df, var=features_df)
    
    return adata

# Set the directory for the data files
directory = "/home/drdx/Multiple Myeloma/DATA/RAW DATA/DOWNLOADED/GSE223060_DIPERSIO"

# Get a list of all subdirectories in the directory
subdirectories = [f.path for f in os.scandir(directory) if f.is_dir()]

# Load all the preprocessed datasets
adatas = []
for subdir in subdirectories:
    matrix_file = os.path.join(subdir, 'counts.mtx')
    barcodes_file = os.path.join(subdir, 'barcodes.tsv')
    features_file = os.path.join(subdir, 'genes.tsv')
    adata = load_data_from_files(matrix_file, barcodes_file, features_file)
    adata.obs['batch'] = os.path.basename(subdir)
    if "counts" not in adata.layers:
        adata.layers["counts"] = adata.X.copy()
    adatas.append(adata)

# Concatenate all individual preprocessed AnnData objects
combined_adata = anndata.concat(adatas, join='outer', index_unique=None)
combined_adata
) ..... Last time we tried, these error generated (ValueError                                Traceback (most recent call last)
Cell In[3], line 37
     35 barcodes_file = os.path.join(subdir, 'barcodes.tsv')
     36 features_file = os.path.join(subdir, 'genes.tsv')
---> 37 adata = load_data_from_files(matrix_file, barcodes_file, features_file)
     38 adata.obs['batch'] = os.path.basename(subdir)
     39 if "counts" not in adata.layers:

Cell In[3], line 21, in load_data_from_files(matrix_path, barcodes_path, features_path)
     18 features_df = pd.read_csv(features_path, header=None, sep='\t', index_col=0, names=['gene_id', 'gene_symbols'])
     20 # Create an AnnData object
---> 21 adata = anndata.AnnData(X=matrix, obs=barcodes_df, var=features_df)
     23 return ada