Exemplo n.º 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"]))
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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")
Exemplo n.º 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")
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 11
0
 def emptyDrops(counts):
     utils = DropletUtils()
     cells = utils.emptyDrops(counts)
     cells = cells.slots["listData"]
     return dict(zip(cells.names, map(list,list(cells))))
Exemplo n.º 12
0
 def barcodeRanks(sce):
     utils = DropletUtils()
     ranks = utils.barcodeRanks(sce.assays["counts"])
     return dict(zip(ranks.names, map(list,list(ranks))))
Exemplo n.º 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
Exemplo n.º 14
0
 def emptyDrops(tenx_analysis):
     utils = DropletUtils()
Exemplo n.º 15
0
 def barcodeRanks(tenx_analysis):
     utils = DropletUtils()
Exemplo n.º 16
0
 def read10xCounts(tenx_analysis):
     utils = DropletUtils()
     counts = utils.read10xCounts(tenx_analysis.raw_matrices(config.build))
     sce = SingleCellExperiment.fromRS4(counts)
     return sce