Пример #1
0
 def test_raw_assay_type_equivelence(self):
     rdata = os.path.join(base_dir, "tests/example_sce.RData")
     sce_from_rdata = SingleCellExperiment.fromRData(rdata)
     tenx = DropletUtils()
     rs4_results = tenx.read10xCounts("/home/ceglian/data/raw_gene_bc_matrices/hg19/")
     sce_from_rs4 = SingleCellExperiment(rs4_results)
     self.assertEqual(type(sce_from_rdata.assays["counts"]),type(sce_from_rdata.assays["counts"]))
Пример #2
0
 def read10xCountsRaw(tenx_analysis, output):
     tenx_analysis.load()
     utils = DropletUtils()
     counts = utils.read10xCounts(tenx_analysis.raw_matrices())
     sce = SingleCellExperiment.fromRS4(counts)
     sce.save(output)
     return sce
Пример #3
0
 def test_save_and_load_rdata(self):
     print("Reading")
     tenx = DropletUtils()
     rs4_result = tenx.read10xCounts("/home/ceglian/data/raw_gene_bc_matrices/hg19/")
     sce = SingleCellExperiment.fromRS4(rs4_result)
     print("Writing")
     sce.save("tests/sce_1.rdata")
     print("Loading...")
     sce_saved = SingleCellExperiment.fromRData("tests/sce_1.rdata")
     print(sce_saved.assays["counts"].shape)
Пример #4
0
def Run(sampleid, before, finished, use_corrected=False):
    if use_corrected and os.path.exists(".cache/corrected/"):
        sce = ".cache/corrected/corrected_sce.rdata"
        if not os.path.exists(sce):
            utils = DropletUtils()
            utils.read10xCounts(".cache/corrected/",
                                ".cache/corrected/corrected_sce.rdata")
    else:
        tenx = TenxDataStorage(sampleid, version="v3")
        tenx.download()
        analysis_path = tenx.tenx_path
        tenx_analysis = TenxAnalysis(analysis_path)
        tenx_analysis.load()
        tenx_analysis.extract()
        qc = QualityControl(tenx_analysis, sampleid)
        sce = qc.sce
    if not os.path.exists(".cache/{}/celltypes.rdata".format(sampleid)):
        CellAssign.run(sce, config.rho_matrix,
                       ".cache/{}/celltypes.rdata".format(sampleid))
    open(finished, "w").write("Completed")
Пример #5
0
def Analysis(sampleid, before, finished, use_corrected=False):
    if use_corrected and os.path.exists(".cache/corrected"):
        sce = ".cache/corrected/corrected_sce.rdata"
        if not os.path.exists(sce):
            utils = DropletUtils()
            utils.read10xCounts(".cache/corrected/",
                                ".cache/corrected/corrected_sce.rdata")
        filtered_sce = sce
    else:
        tenx = TenxDataStorage(sampleid, version="v3")
        tenx.download()
        analysis_path = tenx.tenx_path
        tenx_analysis = TenxAnalysis(analysis_path)
        tenx_analysis.load()
        tenx_analysis.extract()
        qc = QualityControl(tenx_analysis, sampleid)
        filtered_sce = os.path.join(os.path.split(qc.sce)[0], "sce_cas.rdata")
    cellassign_analysis = ".cache/{}/cellassignanalysis/".format(sampleid)
    if not os.path.exists(cellassign_analysis):
        os.makedirs(cellassign_analysis)
    pyfit = os.path.join(".cache/{}/cell_types.pkl".format(sampleid))
    assert os.path.exists(pyfit), "No Pyfit Found."
    pyfit = pickle.load(open(pyfit, "rb"))
    marker_list = GeneMarkerMatrix.read_yaml(config.rho_matrix)
    cell_types = marker_list.celltypes()
    if "B cell" not in cell_types: cell_types.append("B cell")
    celltypes(pyfit, sampleid, cellassign_analysis, known_types=cell_types)

    tsne_by_cell_type(filtered_sce,
                      pyfit,
                      sampleid,
                      cellassign_analysis,
                      known_types=cell_types)
    umap_by_cell_type(filtered_sce,
                      pyfit,
                      sampleid,
                      cellassign_analysis,
                      known_types=cell_types)
    open(finished, "w").write("Completed")
Пример #6
0
 def test_symbol_retrieve(self):
     tenx = TenxAnalysis("tests/pre_igo")
     sce = TenX.read10xCounts(tenx)
     print(sce.rowData.keys())
     example_rda = os.path.join(base_dir, "tests/example_sce.rda")
     sce = SingleCellExperiment.fromRData(example_rda)
     print(sce.rowData.keys())
     tenx = DropletUtils()
     rs4_result = tenx.read10xCounts("tests/hg19/")
     sce = SingleCellExperiment.fromRS4(rs4_result)
     print(sce.rowData.keys())
     example_rda = os.path.join(base_dir, "tests/example_copy_number.rda")
     sce = SingleCellExperiment.fromRData(example_rda)
     print(sce.rowData.keys())
     print(sce.rownames)
     print(sce.colnames)
Пример #7
0
 def test_get_assay_with_row_col_data_rs4(self):
     tenx = DropletUtils()
     rs4_results = tenx.read10xCounts(
         "/home/ceglian/data/raw_gene_bc_matrices/hg19/")
     sce_from_rs4 = SingleCellExperiment.fromRS4(rs4_results)
Пример #8
0
 def test_read10x_counts_load_rs4(self):
     tenx = DropletUtils()
     rs4_result = tenx.read10xCounts(
         "/home/ceglian/data/raw_gene_bc_matrices/hg19/")
     sce_from_rs4 = SingleCellExperiment.fromRS4(rs4_result)
Пример #9
0
 def test_call_empty_drops(self):
     rdata = os.path.join(base_dir, "tests/example_sce.RData")
     sce_from_rdata = SingleCellExperiment.fromRData(rdata)
     tenx = DropletUtils()
     assay = sce_from_rdata.assays["counts"]
     values = tenx.emptyDrops(assay)
Пример #10
0
 def test_barcode_ranks(self):
     rdata = os.path.join(base_dir, "tests/example_sce.RData")
     sce_from_rdata = SingleCellExperiment.fromRData(rdata)
     tenx = DropletUtils()
     assay = sce_from_rdata.assays["counts"]
     values = tenx.barcodeRanks(assay)
Пример #11
0
 def emptyDrops(counts):
     utils = DropletUtils()
     cells = utils.emptyDrops(counts)
     cells = cells.slots["listData"]
     return dict(zip(cells.names, map(list,list(cells))))
Пример #12
0
 def barcodeRanks(sce):
     utils = DropletUtils()
     ranks = utils.barcodeRanks(sce.assays["counts"])
     return dict(zip(ranks.names, map(list,list(ranks))))
Пример #13
0
 def read10xCountsFiltered(tenx_analysis, output):
     utils = DropletUtils()
     counts = utils.read10xCounts(tenx_analysis.filtered_matrices())
     sce = SingleCellExperiment.fromRS4(counts)
     sce.save(output)
     return sce
Пример #14
0
 def emptyDrops(tenx_analysis):
     utils = DropletUtils()
Пример #15
0
 def barcodeRanks(tenx_analysis):
     utils = DropletUtils()
Пример #16
0
 def read10xCounts(tenx_analysis):
     utils = DropletUtils()
     counts = utils.read10xCounts(tenx_analysis.raw_matrices(config.build))
     sce = SingleCellExperiment.fromRS4(counts)
     return sce