Skip to content

Commit 97e7d72

Browse files
authored
Merge pull request #5092 from broadinstitute/remove-rna-loading-manage-command
Remove rna loading manage command
2 parents be04aca + a41ce70 commit 97e7d72

File tree

5 files changed

+48
-271
lines changed

5 files changed

+48
-271
lines changed

seqr/management/commands/load_rna_seq.py

Lines changed: 0 additions & 64 deletions
This file was deleted.

seqr/management/tests/load_rna_seq_tests.py

Lines changed: 0 additions & 161 deletions
This file was deleted.

seqr/views/apis/data_manager_api.py

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import base64
22
from collections import defaultdict
33
from datetime import datetime
4-
import gzip
54
import json
65
import os
76
import requests
@@ -26,7 +25,7 @@
2625
from seqr.views.utils.airtable_utils import AirtableSession, LOADABLE_PDO_STATUSES, AVAILABLE_PDO_STATUS
2726
from seqr.views.utils.dataset_utils import load_rna_seq, load_phenotype_prioritization_data_file, RNA_DATA_TYPE_CONFIGS, \
2827
post_process_rna_data, convert_django_meta_to_http_headers
29-
from seqr.views.utils.file_utils import get_temp_file_path, load_uploaded_file, persist_temp_file
28+
from seqr.views.utils.file_utils import get_temp_file_path, load_uploaded_file
3029
from seqr.views.utils.json_utils import create_json_response
3130
from seqr.views.utils.json_to_orm_utils import update_model_from_json
3231
from seqr.views.utils.pedigree_info_utils import get_validated_related_individuals, JsonConstants
@@ -72,37 +71,15 @@ def update_rna_seq(request):
7271
if uploaded_mapping_file_id:
7372
mapping_file = load_uploaded_file(uploaded_mapping_file_id)
7473

75-
file_name_prefix = f'rna_sample_data__{data_type}__{datetime.now().isoformat()}'
76-
file_dir = get_temp_file_path(file_name_prefix, is_local=True)
77-
os.mkdir(file_dir)
78-
79-
sample_files = {}
80-
81-
def _save_sample_data(sample_key, sample_data):
82-
if sample_key not in sample_files:
83-
file_name = _get_sample_file_path(file_dir, '_'.join(sample_key))
84-
sample_files[sample_key] = gzip.open(file_name, 'at')
85-
sample_files[sample_key].write(f'{json.dumps(sample_data)}\n')
86-
8774
try:
88-
sample_guids_to_keys, info, warnings = load_rna_seq(
89-
data_type, file_path, _save_sample_data,
75+
sample_guids_to_keys, file_name_prefix, info, warnings = load_rna_seq(
76+
data_type, file_path,
9077
user=request.user, mapping_file=mapping_file, ignore_extra_samples=request_json.get('ignoreExtraSamples'))
9178
except FileNotFoundError:
9279
return create_json_response({'error': 'File not found: {}'.format(file_path)}, status=400)
9380
except ValueError as e:
9481
return create_json_response({'error': str(e)}, status=400)
9582

96-
for sample_guid, sample_key in sample_guids_to_keys.items():
97-
sample_files[sample_key].close() # Required to ensure gzipped files are properly terminated
98-
os.rename(
99-
_get_sample_file_path(file_dir, '_'.join(sample_key)),
100-
_get_sample_file_path(file_dir, sample_guid),
101-
)
102-
103-
if sample_guids_to_keys:
104-
persist_temp_file(file_name_prefix, request.user)
105-
10683
return create_json_response({
10784
'info': info,
10885
'warnings': warnings,

seqr/views/apis/data_manager_api_tests.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -793,12 +793,12 @@ def test_update_rna_splice_outlier(self, *args, **kwargs):
793793
@mock.patch('seqr.views.utils.file_utils.tempfile.gettempdir', lambda: 'tmp/')
794794
@mock.patch('seqr.utils.communication_utils.send_html_email')
795795
@mock.patch('seqr.utils.communication_utils.safe_post_to_slack')
796-
@mock.patch('seqr.views.apis.data_manager_api.datetime')
797-
@mock.patch('seqr.views.apis.data_manager_api.os.mkdir')
798-
@mock.patch('seqr.views.apis.data_manager_api.os.rename')
796+
@mock.patch('seqr.views.utils.dataset_utils.datetime')
797+
@mock.patch('seqr.views.utils.dataset_utils.os.mkdir')
798+
@mock.patch('seqr.views.utils.dataset_utils.os.rename')
799799
@mock.patch('seqr.views.apis.data_manager_api.load_uploaded_file')
800800
@mock.patch('seqr.utils.file_utils.subprocess.Popen')
801-
@mock.patch('seqr.views.apis.data_manager_api.gzip.open')
801+
@mock.patch('seqr.views.utils.dataset_utils.gzip.open')
802802
def _test_update_rna_seq(self, data_type, mock_open, mock_subprocess, mock_load_uploaded_file,
803803
mock_rename, mock_mkdir, mock_datetime, mock_send_slack, mock_send_email):
804804
url = reverse(update_rna_seq)
@@ -906,7 +906,7 @@ def _test_basic_data_loading(data, num_parsed_samples, num_loaded_samples, new_s
906906
f'Attempted data loading for {num_loaded_samples} RNA-seq samples in the following {num_projects}'
907907
f' projects: {project_names}'
908908
]
909-
file_name = RNA_FILENAME_TEMPLATE.format(data_type)
909+
file_name = RNA_FILENAME_TEMPLATE.format(params['data_type'])
910910
response_json = response.json()
911911
self.assertDictEqual(response_json, {'info': info, 'warnings': warnings or [], 'sampleGuids': mock.ANY,
912912
'fileName': file_name})
@@ -974,7 +974,7 @@ def _test_basic_data_loading(data, num_parsed_samples, num_loaded_samples, new_s
974974
self.assertSetEqual(set(response_json['sampleGuids']), {sample_guid, new_sample_guid})
975975

976976
# test correct file interactions
977-
file_path = RNA_FILENAME_TEMPLATE.format(data_type)
977+
file_path = RNA_FILENAME_TEMPLATE.format(params['data_type'])
978978
expected_subprocess_calls = [
979979
f'gsutil ls {RNA_FILE_ID}',
980980
f'gsutil cat {RNA_FILE_ID} | gunzip -c -q - ',
@@ -1027,7 +1027,7 @@ def _test_basic_data_loading(data, num_parsed_samples, num_loaded_samples, new_s
10271027
self.assertTrue(second_tissue_sample_guid != new_sample_guid)
10281028
self.assertTrue(second_tissue_sample_guid in response_json['sampleGuids'])
10291029
self._assert_expected_file_open(mock_rename, mock_open, [
1030-
f'tmp/temp_uploads/{RNA_FILENAME_TEMPLATE.format(data_type)}/{sample_guid}.json.gz'
1030+
f'tmp/temp_uploads/{RNA_FILENAME_TEMPLATE.format(params["data_type"])}/{sample_guid}.json.gz'
10311031
for sample_guid in response_json['sampleGuids']
10321032
])
10331033
self.assertSetEqual(

0 commit comments

Comments
 (0)