def test_read10xvdj_cr6_folder(create_testfolder, json_10x_cr6, annotation_10x_cr6, fasta_10x_cr6): fasta_file = str(create_testfolder) + "/test_filtered_contig.fasta" json_file = str(create_testfolder) + "/test_all_contig_annotations.json" annot_file = str(create_testfolder) + "/test_filtered_contig_annotations.csv" annotation_10x_cr6.to_csv(annot_file, index=False) vdj = ddl.read_10x_vdj(str(create_testfolder)) assert vdj.data.shape[0] == 26 assert vdj.data.shape[1] == 33 assert vdj.metadata.shape[0] == 10 assert vdj.metadata.shape[1] == 27 with open(json_file, 'w') as outfile: json.dump(json_10x_cr6, outfile) vdj = ddl.read_10x_vdj(str(create_testfolder)) assert vdj.data.shape[0] == 26 assert vdj.data.shape[1] == 49 assert vdj.metadata.shape[0] == 10 assert vdj.metadata.shape[1] == 27 assert not vdj.data.sequence.empty os.remove(json_file) fh = open(fasta_file, "w") fh.close() out = '' for l in fasta_10x_cr6: out = '>' + l + '\n' + fasta_10x_cr6[l] + '\n' ddl.utl.Write_output(out, fasta_file) vdj = ddl.read_10x_vdj(str(create_testfolder)) assert vdj.data.shape[0] == 26 assert vdj.data.shape[1] == 34 assert vdj.metadata.shape[0] == 10 assert vdj.metadata.shape[1] == 27 assert not vdj.data.sequence.empty os.remove(fasta_file)
def test_to_scirpy(create_testfolder, annotation_10x, fasta_10x): fasta_file = str(create_testfolder) + "/test_filtered_contig.fasta" annot_file = str(create_testfolder) + "/test_filtered_contig_annotations.csv" annotation_10x.to_csv(annot_file, index=False) vdj = ddl.read_10x_vdj(str(create_testfolder)) assert vdj.data.shape[0] == 9 assert vdj.data.shape[1] == 20 assert vdj.metadata.shape[0] == 4 assert vdj.metadata.shape[1] == 25 adata = ddl.to_scirpy(vdj) assert adata.obs.shape[0] == 5 assert adata.obs.shape[1] == 43 fh = open(fasta_file, "w") fh.close() out = '' for l in fasta_10x: out = '>' + l + '\n' + fasta_10x[l] + '\n' ddl.utl.Write_output(out, fasta_file) vdj = ddl.read_10x_vdj(str(create_testfolder)) assert vdj.data.shape[0] == 9 assert vdj.data.shape[1] == 21 assert vdj.metadata.shape[0] == 4 assert vdj.metadata.shape[1] == 25 assert not vdj.data.sequence.empty adata = ddl.to_scirpy(vdj) assert adata.obs.shape[0] == 5 assert adata.obs.shape[1] == 43 os.remove(fasta_file)
def test_filtercontigs(create_testfolder, dummy_adata_cr6, json_10x_cr6): json_file = str(create_testfolder) + "/test_all_contig_annotations.json" out_file = str(create_testfolder) + "/test_filtered.tsv" with open(json_file, 'w') as outfile: json.dump(json_10x_cr6, outfile) vdj = ddl.read_10x_vdj(str(create_testfolder), filename_prefix='test_all') vdj2, adata = ddl.pp.filter_contigs(vdj, dummy_adata_cr6) assert vdj.data.shape[0] == 26 assert vdj2.data.shape[0] == 14 assert adata.obs.shape[0] == 10 vdj2, adata = ddl.pp.filter_contigs(vdj, dummy_adata_cr6, productive_only=False) assert vdj.data.shape[0] == 26 assert vdj2.data.shape[0] == 23 assert adata.obs.shape[0] == 10 vdj2, adata = ddl.pp.filter_contigs(vdj, dummy_adata_cr6, productive_only=True, simple=True) assert vdj.data.shape[0] == 26 assert vdj2.data.shape[0] == 26 assert adata.obs.shape[0] == 10 vdj2, adata = ddl.pp.filter_contigs(vdj, dummy_adata_cr6, productive_only=False, simple=True) assert vdj.data.shape[0] == 26 assert vdj2.data.shape[0] == 26 assert adata.obs.shape[0] == 10 vdj2, adata = ddl.pp.filter_contigs(vdj, dummy_adata_cr6, productive_only=True, filter_vj_chains=False) assert vdj.data.shape[0] == 26 assert vdj2.data.shape[0] == 16 assert adata.obs.shape[0] == 10 vdj2, adata = ddl.pp.filter_contigs(vdj, dummy_adata_cr6, filter_vj_chains=False, keep_highest_umi=False) assert vdj.data.shape[0] == 26 assert vdj2.data.shape[0] == 17 assert adata.obs.shape[0] == 10 vdj2, adata = ddl.pp.filter_contigs(vdj, dummy_adata_cr6, filter_rna=True) assert vdj.data.shape[0] == 26 assert vdj2.data.shape[0] == 14 assert adata.obs.shape[0] == 9 vdj2, adata = ddl.pp.filter_contigs(vdj, dummy_adata_cr6, productive_only=False, filter_poorqualitycontig=True) assert vdj.data.shape[0] == 26 assert vdj2.data.shape[0] == 23 assert adata.obs.shape[0] == 10 vdj2, adata = ddl.pp.filter_contigs(vdj, dummy_adata_cr6, save=out_file) assert os.path.exists(out_file)
def test_read10xvdj_json(create_testfolder, json_10x_cr6): json_file = str(create_testfolder) + "/test_all_contig_annotations.json" with open(json_file, 'w') as outfile: json.dump(json_10x_cr6, outfile) vdj = ddl.read_10x_vdj(json_file) assert vdj.data.shape[0] == 26 assert vdj.data.shape[1] == 49 assert vdj.metadata.shape[0] == 10 assert vdj.metadata.shape[1] == 27 os.remove(json_file)
def test_tofro_scirpy_cr6(create_testfolder, annotation_10x_cr6, json_10x_cr6): json_file = str(create_testfolder) + "/test_all_contig_annotations.json" annot_file = str(create_testfolder) + "/test_all_contig_annotations.csv" annotation_10x_cr6.to_csv(annot_file, index=False) with open(json_file, 'w') as outfile: json.dump(json_10x_cr6, outfile) vdj = ddl.read_10x_vdj(str(create_testfolder), filename_prefix = 'test_all') assert vdj.data.shape[0] == 26 assert vdj.data.shape[1] == 33 assert vdj.metadata.shape[0] == 10 assert vdj.metadata.shape[1] == 27 adata = ddl.to_scirpy(vdj) assert adata.obs.shape[0] == 10 assert adata.obs.shape[1] == 43
def test_setup2(create_testfolder, json_10x_cr6, dummy_adata_cr6): json_file = str(create_testfolder) + "/test_all_contig_annotations.json" with open(json_file, 'w') as outfile: json.dump(json_10x_cr6, outfile) vdj = ddl.read_10x_vdj(str(create_testfolder)) vdj, adata = ddl.pp.filter_contigs(vdj, dummy_adata_cr6) assert vdj.data.shape[0] == 14 assert vdj.data.shape[1] == 50 assert vdj.metadata.shape[0] == 7 assert vdj.metadata.shape[1] == 25 ddl.tl.find_clones(vdj) ddl.tl.generate_network(vdj, key='sequence') ddl.tl.transfer(adata, vdj) f = create_testfolder / "test.h5" vdj.write_h5(f) f2 = create_testfolder / "test.h5ad" adata.write_h5ad(f2)
def test_filtercontigs_no_adata(create_testfolder): json_file = str(create_testfolder) + "/test_all_contig_annotations.json" vdj = ddl.read_10x_vdj(str(create_testfolder), filename_prefix='test_all') vdj2 = ddl.pp.filter_contigs(vdj) assert vdj.data.shape[0] == 26 assert vdj2.data.shape[0] == 14