Skip to content

Commit

Permalink
fix outlier manage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hanars committed Feb 5, 2024
1 parent 8b26e24 commit e5a1c34
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 102 deletions.
2 changes: 1 addition & 1 deletion seqr/management/commands/load_rna_seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ def _save_sample_data(self, sample_guid, data_by_gene):
sample = Sample.objects.get(guid=sample_guid)
models = self.model_cls.objects.bulk_create(
[self.model_cls(sample=sample, **data) for data in data_by_gene.values()], batch_size=1000)
logger.info(f'create {len(models)} {self.model_cls} for {sample.sample_id}')
logger.info(f'create {len(models)} {self.model_cls.__name__} for {sample.sample_id}')
38 changes: 0 additions & 38 deletions seqr/management/commands/load_rna_seq_outlier.py

This file was deleted.

63 changes: 0 additions & 63 deletions seqr/management/tests/load_rna_seq_outlier_tests.py

This file was deleted.

54 changes: 54 additions & 0 deletions seqr/management/tests/load_rna_seq_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,58 @@ def test_tpm(self, mock_open, mock_logger, mock_utils_logger, mock_gzip_open):
self.assertEqual(models.values('sample').distinct().count(), 2)
mock_logger.info.assert_has_calls([
mock.call('create 1 RnaSeqTpm for NA19678_D1'),
mock.call('DONE'),
])

@mock.patch('seqr.management.commands.load_rna_seq.logger.info')
@mock.patch('seqr.management.commands.load_rna_seq.open')
@mock.patch('seqr.utils.file_utils.gzip.open')
def test_outlier(self, mock_gzip_open, mock_open, mock_logger):
mock_gzip_file = mock_gzip_open.return_value.__enter__.return_value
mock_gzip_file.__iter__.return_value = ['invalid\theader']

with self.assertRaises(ValueError) as e:
call_command('load_rna_seq', 'outlier', RNA_FILE_ID)
self.assertEqual(str(e.exception),
'Invalid file: missing column(s): geneID, pValue, padjust, project, sampleID, tissue, zScore')

mock_gzip_file.__iter__.return_value = [
'sampleID\tproject\tgeneID\tdetail\tpValue\tpadjust\tzScore\ttissue\n',
'NA19675_D2\t1kg project nåme with uniçøde\tENSG00000240361\tdetail1\t0.01\t0.13\t-3.1\tmuscle\n',
'NA19675_D2\t1kg project nåme with uniçøde\tENSG00000240361\tdetail2\t0.01\t0.13\t-3.1\tmuscle\n',
'NA19675_D2\t1kg project nåme with uniçøde\tENSG00000233750\tdetail1\t0.064\t0.0000057\t7.8\tmuscle\n',
'NA19675_D3\t1kg project nåme with uniçøde\tENSG00000233750\tdetail1\t0.064\t0.0000057\t7.8\tmuscle\n',
'NA19675_D4\t1kg project nåme with uniçøde\tENSG00000233750\tdetail1\t0.064\t0.0000057\t7.8\tmuscle\n',
]
mock_open.return_value.__enter__.return_value.__iter__.return_value = ['NA19675_D4\tNA19678']

with self.assertRaises(ErrorsWarningsException) as e:
call_command('load_rna_seq', 'outlier', RNA_FILE_ID)
self.assertEqual(e.exception.errors,
['Unable to find matches for the following samples: NA19675_D3, NA19675_D4'])

with self.assertRaises(ErrorsWarningsException) as e:
call_command('load_rna_seq', 'outlier', RNA_FILE_ID, '--mapping-file', 'map.tsv')
self.assertEqual(e.exception.errors, ['Unable to find matches for the following samples: NA19675_D3'])

call_command('load_rna_seq', 'outlier', RNA_FILE_ID, '--ignore-extra-samples')

rna_samples = Sample.objects.filter(individual_id=1, sample_id='NA19675_D2', sample_type='RNA')
self.assertEqual(len(rna_samples), 1)
sample = rna_samples.first()
self.assertEqual(sample.guid, EXISTING_SAMPLE_GUID)
self.assertTrue(sample.is_active)
self.assertIsNone(sample.elasticsearch_index)
#self.assertEqual(sample.data_source, 'new_muscle_samples.tsv.gz') TODO?
self.assertEqual(sample.tissue_type, 'M')

models = RnaSeqOutlier.objects.all()
self.assertEqual(models.count(), 2)
self.assertSetEqual({model.sample for model in models}, {sample})
self.assertListEqual(list(models.values_list('gene_id', 'p_adjust', 'p_value', 'z_score')), [
('ENSG00000240361', 0.13, 0.01, -3.1), ('ENSG00000233750', 0.0000057, 0.064, 7.8),
])
mock_logger.assert_has_calls([
mock.call('create 2 RnaSeqOutlier for NA19675_D2'),
mock.call('DONE'),
])

0 comments on commit e5a1c34

Please sign in to comment.