1111from anndata_ import AnnDataIngestor
1212from ingest_files import IngestFiles
1313
14- class TestAnnDataIngestor (unittest .TestCase ):
1514
15+ class TestAnnDataIngestor (unittest .TestCase ):
1616 @staticmethod
1717 def setup_class (self ):
1818 filepath_valid = "../tests/data/anndata/trimmed_compliant_pbmc3K.h5ad"
@@ -24,14 +24,16 @@ def setup_class(self):
2424 self .cluster_name = 'X_tsne'
2525 self .valid_kwargs = {'obsm_keys' : [self .cluster_name ]}
2626 self .anndata_ingest = AnnDataIngestor (* self .valid_args , ** self .valid_kwargs )
27- self .output_filename = f"{ self .cluster_name } .cluster.anndata_segment .tsv"
27+ self .output_filename = f"h5ad_frag.cluster. { self .cluster_name } .tsv"
2828
2929 def teardown_method (self , _ ):
3030 if os .path .isfile (self .output_filename ):
3131 os .remove (self .output_filename )
3232
3333 def test_minimal_valid_anndata (self ):
34- self .assertTrue (self .anndata_ingest .validate (), "expect known good file to open with scanpy" )
34+ self .assertTrue (
35+ self .anndata_ingest .validate (), "expect known good file to open with scanpy"
36+ )
3537
3638 def test_truncated_anndata (self ):
3739 truncated_input = AnnDataIngestor (* self .invalid_args )
@@ -47,9 +49,7 @@ def test_truncated_anndata(self):
4749
4850 def test_input_bad_suffix (self ):
4951 bad_input = AnnDataIngestor (
50- "../tests/data/anndata/bad.foo" ,
51- self .study_id ,
52- self .study_file_id ,
52+ "../tests/data/anndata/bad.foo" , self .study_id , self .study_file_id
5353 )
5454 # passing obtain_data function to assertRaises using lambda
5555 # otherwise bad_input.obtain_data() is evaluated and triggers
@@ -64,40 +64,60 @@ def test_input_bad_suffix(self):
6464 def test_set_output_filename (self ):
6565 cluster_name = "X_Umap"
6666 self .assertEqual (
67- AnnDataIngestor .set_output_filename (cluster_name ),
68- "X_Umap .cluster.anndata_segment .tsv"
67+ AnnDataIngestor .set_clustering_filename (cluster_name ),
68+ "h5ad_frag .cluster.X_Umap .tsv" ,
6969 )
7070
7171 def test_generate_cluster_header (self ):
72- self .anndata_ingest .generate_cluster_header (self .anndata_ingest .obtain_adata (), self .cluster_name )
72+ self .anndata_ingest .generate_cluster_header (
73+ self .anndata_ingest .obtain_adata (), self .cluster_name
74+ )
7375 with open (self .output_filename ) as header_file :
7476 header = header_file .readline ().split ("\t " )
75- self .assertEqual (['NAME' , 'X' , "Y\n " ], header , "did not find expected headers" )
77+ self .assertEqual (
78+ ['NAME' , 'X' , "Y\n " ], header , "did not find expected headers"
79+ )
7680
7781 def test_generate_cluster_type_declaration (self ):
78- self .anndata_ingest .generate_cluster_type_declaration (self .anndata_ingest .obtain_adata (), self .cluster_name )
82+ self .anndata_ingest .generate_cluster_type_declaration (
83+ self .anndata_ingest .obtain_adata (), self .cluster_name
84+ )
7985 with open (self .output_filename ) as header_file :
8086 header = header_file .readline ().split ("\t " )
81- self .assertEqual (['TYPE' , 'numeric' , "numeric\n " ], header , "did not find expected headers" )
87+ self .assertEqual (
88+ ['TYPE' , 'numeric' , "numeric\n " ],
89+ header ,
90+ "did not find expected headers" ,
91+ )
8292
8393 def test_generate_cluster_body (self ):
84- self .anndata_ingest .generate_cluster_body (self .anndata_ingest .obtain_adata (), self .cluster_name )
94+ self .anndata_ingest .generate_cluster_body (
95+ self .anndata_ingest .obtain_adata (), self .cluster_name
96+ )
8597 with open (self .output_filename ) as cluster_body :
8698 line = cluster_body .readline ().split ("\t " )
8799 expected_line = ['AAACATACAACCAC-1' , '16.009954' , "-21.073845\n " ]
88- self .assertEqual (expected_line , line , 'did not get expected coordinates from cluster body' )
100+ self .assertEqual (
101+ expected_line ,
102+ line ,
103+ 'did not get expected coordinates from cluster body' ,
104+ )
89105
90106 def test_get_files_to_delocalize (self ):
91- files = AnnDataIngestor .files_to_delocalize (self .valid_kwargs )
107+ files = AnnDataIngestor .clusterings_to_delocalize (self .valid_kwargs )
92108 expected_files = [self .output_filename ]
93109 self .assertEqual (expected_files , files )
94110
95111 def test_delocalize_files (self ):
96112 # just create header, no reason to run full extract
97- self .anndata_ingest .generate_cluster_header (self .anndata_ingest .obtain_adata (), self .cluster_name )
113+ self .anndata_ingest .generate_cluster_header (
114+ self .anndata_ingest .obtain_adata (), self .cluster_name
115+ )
98116 with patch ('ingest_files.IngestFiles.delocalize_file' ):
99117 AnnDataIngestor .delocalize_file (
100- "gs://fake_bucket" , self .study_id , AnnDataIngestor .files_to_delocalize (self .valid_kwargs )
118+ "gs://fake_bucket" ,
119+ self .study_id ,
120+ AnnDataIngestor .clusterings_to_delocalize (self .valid_kwargs ),
101121 )
102122 self .assertEqual (
103123 IngestFiles .delocalize_file .call_count ,
0 commit comments