def create_from_cellranger(indir: str, outdir: str = None, genome: str = None) -> str:
if outdir is None:<EOL><INDENT>outdir = indir<EOL><DEDENT>sampleid = os.path.split(os.path.abspath(indir))[-<NUM_LIT:1>]<EOL>matrix_folder = os.path.join(indir, '<STR_LIT>', '<STR_LIT>')<EOL>if os.path.exists(matrix_folder):<EOL><INDENT>if genome is None:<EOL><INDENT>genome = [f for f in os.listdir(matrix_folder) if not f.startswith("<STR_LIT:.>")][<NUM_LIT:0>]<EOL><DEDENT>matrix_folder = os.path.join(matrix_folder, genome)<EOL>matrix = mmread(os.path.join(matrix_folder, "<STR_LIT>")).astype("<STR_LIT>").todense()<EOL>genelines = open(os.path.join(matrix_folder, "<STR_LIT>"), "<STR_LIT:r>").readlines()<EOL>bclines = open(os.path.join(matrix_folder, "<STR_LIT>"), "<STR_LIT:r>").readlines()<EOL><DEDENT>else: <EOL><INDENT>if genome is None:<EOL><INDENT>genome = "<STR_LIT>" <EOL><DEDENT>matrix_folder = os.path.join(indir, '<STR_LIT>', '<STR_LIT>')<EOL>matrix = mmread(os.path.join(matrix_folder, "<STR_LIT>")).astype("<STR_LIT>").todense()<EOL>genelines = [ l.decode() for l in gzip.open(os.path.join(matrix_folder, "<STR_LIT>"), "<STR_LIT:r>").readlines() ]<EOL>bclines = [ l.decode() for l in gzip.open(os.path.join(matrix_folder, "<STR_LIT>"), "<STR_LIT:r>").readlines() ]<EOL><DEDENT>accession = np.array([x.split("<STR_LIT:\t>")[<NUM_LIT:0>] for x in genelines]).astype("<STR_LIT:str>")<EOL>gene = np.array([x.split("<STR_LIT:\t>")[<NUM_LIT:1>].strip() for x in genelines]).astype("<STR_LIT:str>")<EOL>cellids = np.array([sampleid + "<STR_LIT::>" + x.strip() for x in bclines]).astype("<STR_LIT:str>")<EOL>col_attrs = {"<STR_LIT>": cellids}<EOL>row_attrs = {"<STR_LIT>": accession, "<STR_LIT>": gene}<EOL>tsne_file = os.path.join(indir, "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>")<EOL>if not os.path.exists(tsne_file):<EOL><INDENT>tsne_file = os.path.join(indir, "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>")<EOL><DEDENT>if os.path.exists(tsne_file):<EOL><INDENT>tsne = np.loadtxt(tsne_file, usecols=(<NUM_LIT:1>, <NUM_LIT:2>), delimiter='<STR_LIT:U+002C>', skiprows=<NUM_LIT:1>)<EOL>col_attrs["<STR_LIT:X>"] = tsne[:, <NUM_LIT:0>].astype('<STR_LIT>')<EOL>col_attrs["<STR_LIT:Y>"] = tsne[:, <NUM_LIT:1>].astype('<STR_LIT>')<EOL><DEDENT>clusters_file = os.path.join(indir, "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>")<EOL>if os.path.exists(clusters_file):<EOL><INDENT>labels = np.loadtxt(clusters_file, usecols=(<NUM_LIT:1>, ), delimiter='<STR_LIT:U+002C>', skiprows=<NUM_LIT:1>)<EOL>col_attrs["<STR_LIT>"] = labels.astype('<STR_LIT:int>') - <NUM_LIT:1><EOL><DEDENT>path = os.path.join(outdir, sampleid + "<STR_LIT>")<EOL>create(path, matrix, row_attrs, col_attrs, file_attrs={"<STR_LIT>": genome})<EOL>return path<EOL>
Create a .loom file from 10X Genomics cellranger output

Args:
        indir (str):	path to the cellranger output folder (the one that contains 'outs')
        outdir (str):	output folder wher the new loom file should be saved (default to indir)
        genome (str):	genome build to load (e.g. 'mm10'; if None, determine species from outs folder)

Returns:
        path (str):		Full path to the created loom file.

Remarks:
        The resulting file will be named ``{sampleID}.loom``, where the sampleID is the one given by cellranger.