Skip to content

Commit

Permalink
EVA-3221 - Provide the expected parameter to the brokering prep (#161)
Browse files Browse the repository at this point in the history
* provide the expected parameter to the brokering prep
  • Loading branch information
tcezard authored Jul 3, 2023
1 parent 9e53ff4 commit ea18009
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
19 changes: 18 additions & 1 deletion eva_submission/eload_brokering.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import csv
import os
import shutil
import subprocess
Expand Down Expand Up @@ -144,10 +145,26 @@ def _get_valid_vcf_files(self):
valid_vcf_files.extend(files) if files else None
return valid_vcf_files

def _generate_csv_mappings(self):
vcf_files_mapping_csv = os.path.join(self.eload_dir, 'brokering_vcf_files_mapping.csv')
with open(vcf_files_mapping_csv, 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(['vcf', 'fasta', 'report', 'assembly_accession'])
sub_analyses = self.eload_cfg.query('submission', 'analyses')
valid_analyses = self.eload_cfg.query('validation', 'valid', 'analyses')
for analysis_alias in valid_analyses:
fasta = sub_analyses[analysis_alias]['assembly_fasta']
report = sub_analyses[analysis_alias]['assembly_report']
assembly_accession = sub_analyses[analysis_alias]['assembly_accession']
for vcf_file in valid_analyses[analysis_alias]['vcf_files']:
writer.writerow([vcf_file, fasta, report, assembly_accession])
return vcf_files_mapping_csv

def _run_brokering_prep_workflow(self):
output_dir = self.create_nextflow_temp_output_directory()
cfg['executable']['python']['script_path'] = os.path.dirname(os.path.dirname(__file__))
brokering_config = {
'vcf_files': self._get_valid_vcf_files(),
'vcf_files_mapping': self._generate_csv_mappings(),
'output_dir': output_dir,
'executable': cfg['executable']
}
Expand Down
7 changes: 3 additions & 4 deletions eva_submission/eload_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,17 @@ def parse_sv_check_log(self, sv_check_log):
return nb_sv

def _generate_csv_mappings(self):
vcf_files_mapping_csv = os.path.join(self.eload_dir, 'vcf_files_mapping.csv')
vcf_files_mapping_csv = os.path.join(self.eload_dir, 'validation_vcf_files_mapping.csv')
with open(vcf_files_mapping_csv, 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(['vcf', 'fasta', 'report', 'assembly_accession'])
writer.writerow(['vcf', 'fasta', 'report'])
analyses = self.eload_cfg.query('submission', 'analyses')
for analysis_alias, analysis_data in analyses.items():
fasta = analysis_data['assembly_fasta']
report = analysis_data['assembly_report']
assembly_accession = analysis_data['assembly_accession']
if analysis_data['vcf_files']:
for vcf_file in analysis_data['vcf_files']:
writer.writerow([vcf_file, fasta, report, assembly_accession])
writer.writerow([vcf_file, fasta, report])
else:
self.warning(f"VCF files for analysis {analysis_alias} not found")
return vcf_files_mapping_csv
Expand Down
9 changes: 8 additions & 1 deletion tests/test_eload_brokering.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,18 @@ def test_run_brokering_prep_workflow(self):
self.eload.eload_cfg.set('validation', 'valid', 'analyses', value={
'analysis_alias1': {
'vcf_files': [os.path.join(self.resources_folder, 'vcf_file.vcf')],
},
})
self.eload.eload_cfg.set('submission', 'analyses', value={
'analysis_alias1': {
'assembly_fasta': os.path.join(self.resources_folder, 'reference_genome.fa'),
'assembly_report': os.path.join(self.resources_folder, 'reference_genome_assembly_report.tx'),
'assembly_accession': 'GCA000000.1'
},
})
cfg.content['executable'] = {
'nextflow': 'path_to_nextflow'
'nextflow': 'path_to_nextflow',
'python': {'script_path': 'path_to_script'}
}
temp_dir = 'temporary_directory'
nf_script = os.path.join(NEXTFLOW_DIR, 'prepare_brokering.nf')
Expand Down

0 comments on commit ea18009

Please sign in to comment.