@@ -291,4 +291,65 @@ class StudyFilesControllerTest < ActionDispatch::IntegrationTest
291291 assert_equal description , study_file . description
292292 assert study_file . parsed?
293293 end
294+
295+ test 'should extract only raw counts from existing AnnData uploads' do
296+ study = FactoryBot . create ( :detached_study ,
297+ name_prefix : 'AnnData Raw Counts Study' ,
298+ public : true ,
299+ user : @user ,
300+ test_array : @@studies_to_clean )
301+ ann_data_file = FactoryBot . create ( :ann_data_file ,
302+ name : 'matrix.h5ad' ,
303+ study :,
304+ upload_file_size : 1 . megabyte ,
305+ cell_input : %w[ A B C D ] ,
306+ has_raw_counts : false ,
307+ reference_file : false ,
308+ annotation_input : [
309+ { name : 'disease' , type : 'group' , values : %w[ cancer cancer normal normal ] }
310+ ] ,
311+ coordinate_input : [
312+ { umap : { x : [ 1 , 2 , 3 , 4 ] , y : [ 5 , 6 , 7 , 8 ] } }
313+ ] ,
314+ expression_input : {
315+ 'phex' => [ [ 'A' , 0.3 ] , [ 'B' , 1.0 ] , [ 'C' , 0.5 ] , [ 'D' , 0.1 ] ]
316+ } )
317+
318+ assert_not ann_data_file . is_raw_counts_file?
319+ assert_not ann_data_file . needs_raw_counts_extraction?
320+
321+ # test for normal uploads
322+ study_file_attributes = {
323+ study_file : {
324+ expression_file_info_attributes : {
325+ is_raw_counts : true ,
326+ units : 'raw counts'
327+ }
328+ }
329+ }
330+ FileParseService . stub :run_parse_job , true do
331+ execute_http_request ( :patch , api_v1_study_study_file_path ( study_id : study . id , id : ann_data_file . id ) ,
332+ request_payload : study_file_attributes )
333+ assert_response :success
334+ ann_data_file . reload
335+ assert ann_data_file . is_raw_counts_file?
336+ assert ann_data_file . needs_raw_counts_extraction?
337+ end
338+
339+ # test for bucket path uploads, resetting flags first
340+ ann_data_file . expression_file_info . update ( is_raw_counts : false )
341+ ann_data_file . ann_data_file_info . update ( has_raw_counts : false )
342+ ann_data_file . update ( remote_location : 'matrix.h5ad' )
343+ assert_not ann_data_file . is_raw_counts_file?
344+ assert_not ann_data_file . needs_raw_counts_extraction?
345+
346+ FileParseService . stub :run_parse_job , true do
347+ execute_http_request ( :patch , api_v1_study_study_file_path ( study_id : study . id , id : ann_data_file . id ) ,
348+ request_payload : study_file_attributes )
349+ assert_response :success
350+ ann_data_file . reload
351+ assert ann_data_file . is_raw_counts_file?
352+ assert ann_data_file . needs_raw_counts_extraction?
353+ end
354+ end
294355end
0 commit comments