Skip to content

Commit 0b32fe2

Browse files
committed
test coverage, removing frozen_string_literal re: callback errors
1 parent 97bd9b8 commit 0b32fe2

File tree

3 files changed

+84
-21
lines changed

3 files changed

+84
-21
lines changed

app/lib/dot_plot_service.rb

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
# frozen_string_literal: true
2-
31
# service that handles preprocessing expression/annotation data to speed up dot plot rendering
42
class DotPlotService
53
# main handler for launching ingest job to process expression data into DotPlotGene objects
6-
# since the study can have only one processed matrix, this will only run if the study is eligible
7-
# and we do not need to specify which matrix/metadata file to process
4+
# since the study can have only one processed matrix/metadata file, this will only run if the study is eligible
85
#
96
# * *params*
107
# - +study+ (Study) => the study that owns the data
@@ -40,35 +37,37 @@ def self.run_process_dot_plot_genes(study, cluster_group, user)
4037
# * *returns*
4138
# - (DotPlotGeneIngestParameters) => a parameters object with the necessary file paths and metadata
4239
def self.create_params_object(cluster_group, expression_file, metadata_file)
43-
params = DotPlotGeneIngestParameters.new(
40+
params = {
4441
cluster_group_id: cluster_group.id,
45-
cluster_file: RequestUtils.cluster_file_url(cluster_group),
46-
matrix_file_type: expression_file.file_type == 'Expression Matrix' ? 'dense' : 'mtx'
47-
)
42+
cluster_file: RequestUtils.cluster_file_url(cluster_group)
43+
}
4844
case expression_file.file_type
4945
when 'Expression Matrix'
50-
params.matrix_file_path = expression_file.gs_url
51-
params.cell_metadata_file = metadata_file.gs_url
46+
params[:matrix_file_type] = 'dense'
47+
params[:matrix_file_path] = expression_file.gs_url
48+
params[:cell_metadata_file] = metadata_file.gs_url
5249
when 'MM Coordinate Matrix'
50+
params[:matrix_file_type] = 'mtx'
5351
genes_file = expression_file.bundled_files.detect { |f| f.file_type == '10X Genes File' }
5452
barcodes_file = expression_file.bundled_files.detect { |f| f.file_type == '10X Barcodes File' }
55-
params.matrix_file_path = expression_file.gs_url
56-
params.cell_metadata_file = metadata_file.gs_url
57-
params.gene_file = genes_file.gs_url
58-
params.barcode_file = barcodes_file.gs_url
53+
params[:matrix_file_path] = expression_file.gs_url
54+
params[:cell_metadata_file] = metadata_file.gs_url
55+
params[:gene_file] = genes_file.gs_url
56+
params[:barcode_file] = barcodes_file.gs_url
5957
when 'AnnData'
60-
params.cell_metadata_file = RequestUtils.data_fragment_url(metadata_file, 'metadata')
61-
params.matrix_file_path = RequestUtils.data_fragment_url(
58+
params[:matrix_file_type] = 'mtx' # extracted expression for AnnData is in MTX format
59+
params[:cell_metadata_file] = RequestUtils.data_fragment_url(metadata_file, 'metadata')
60+
params[:matrix_file_path] = RequestUtils.data_fragment_url(
6261
expression_file, 'matrix', file_type_detail: 'processed'
6362
)
64-
params.gene_file = RequestUtils.data_fragment_url(
63+
params[:gene_file] = RequestUtils.data_fragment_url(
6564
expression_file, 'features', file_type_detail: 'processed'
6665
)
67-
params.barcode_file = RequestUtils.data_fragment_url(
66+
params[:barcode_file] = RequestUtils.data_fragment_url(
6867
expression_file, 'barcodes', file_type_detail: 'processed'
6968
)
7069
end
71-
params
70+
DotPlotGeneIngestParameters.new(**params)
7271
end
7372

7473
# determine study eligibility - can only have one processed matrix and be able to visualize clusters

app/models/dot_plot_gene_ingest_parameters.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# frozen_string_literal: true
2-
31
# class to hold parameters specific to ingest job for computing dot plot gene metrics
42
class DotPlotGeneIngestParameters
53
include ActiveModel::Model
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
require 'test_helper'
2+
3+
class DotPlotGeneIngestParametersTest < ActiveSupport::TestCase
4+
before(:all) do
5+
cluster_group_id = BSON::ObjectId.new
6+
@dense_options = {
7+
cell_metadata_file: 'gs://test_bucket/metadata.tsv',
8+
cluster_file: 'gs://test_bucket/cluster.tsv',
9+
cluster_group_id:,
10+
matrix_file_path: 'gs://test_bucket/dense.tsv',
11+
matrix_file_type: 'dense',
12+
}
13+
14+
@sparse_options = {
15+
cell_metadata_file: 'gs://test_bucket/metadata.tsv',
16+
cluster_file: 'gs://test_bucket/cluster.tsv',
17+
cluster_group_id:,
18+
matrix_file_path: 'gs://test_bucket/sparse.tsv',
19+
matrix_file_type: 'mtx',
20+
gene_file: 'gs://test_bucket/genes.tsv',
21+
barcode_file: 'gs://test_bucket/barcodes.tsv'
22+
}
23+
24+
@anndata_options = {
25+
cell_metadata_file: 'gs://test_bucket/metadata.tsv',
26+
cluster_file: 'gs://test_bucket/cluster.tsv',
27+
cluster_group_id:,
28+
matrix_file_path: 'gs://test_bucket/matrix.h5ad',
29+
matrix_file_type: 'mtx',
30+
gene_file: 'gs://test_bucket/genes.tsv',
31+
barcode_file: 'gs://test_bucket/barcodes.tsv'
32+
}
33+
end
34+
35+
test 'should create and validate parameters' do
36+
[@dense_options, @sparse_options, @anndata_options].each do |options|
37+
params = DotPlotGeneIngestParameters.new(**options)
38+
assert params.valid?
39+
assert_equal DotPlotGeneIngestParameters::PARAM_DEFAULTS[:machine_type], params.machine_type
40+
if options[:matrix_file_type] == 'mtx'
41+
assert params.gene_file.present?
42+
assert params.barcode_file.present?
43+
else
44+
assert params.gene_file.nil?
45+
assert params.barcode_file.nil?
46+
end
47+
end
48+
end
49+
50+
test 'should find associated cluster group' do
51+
user = FactoryBot.create(:user, test_array: @@users_to_clean)
52+
study = FactoryBot.create(:detached_study,
53+
name_prefix: 'DotPlotGeneIngestParameters Test',
54+
user:,
55+
test_array: @@studies_to_clean)
56+
FactoryBot.create(:cluster_file,
57+
name: 'cluster.txt',
58+
study:,
59+
cell_input: { x: [1, 4, 6], y: [7, 5, 3], cells: %w[A B C] }
60+
)
61+
cluster_group = ClusterGroup.find_by(study:)
62+
new_options = @dense_options.dup.merge(cluster_group_id: cluster_group.id)
63+
params = DotPlotGeneIngestParameters.new(**new_options)
64+
assert_equal cluster_group, params.cluster_group
65+
end
66+
end

0 commit comments

Comments
 (0)