-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from EBIvariation/feature/support-multiple-ref…
…-seq-per-analysis Multiple analysis support
- Loading branch information
Showing
35 changed files
with
1,040 additions
and
475 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright 2021 EMBL - European Bioinformatics Institute | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import logging | ||
from argparse import ArgumentParser | ||
|
||
from ebi_eva_common_pyutils.logger import logging_config as log_cfg | ||
|
||
from eva_submission.eload_submission import Eload | ||
from eva_submission.submission_config import load_config | ||
|
||
logger = log_cfg.get_logger(__name__) | ||
|
||
|
||
def main(): | ||
argparse = ArgumentParser(description='Upgrade ELOAD config to a format compatible with current automation') | ||
argparse.add_argument('--eload', required=True, type=int, help='The ELOAD number for this submission') | ||
argparse.add_argument('--analysis_alias', required=False, type=str, help='Analysis alias to use') | ||
argparse.add_argument('--debug', action='store_true', default=False, | ||
help='Set the script to output logging information at debug level') | ||
|
||
args = argparse.parse_args() | ||
|
||
log_cfg.add_stdout_handler() | ||
if args.debug: | ||
log_cfg.set_log_level(logging.DEBUG) | ||
|
||
# Load the config_file from default location | ||
load_config() | ||
|
||
eload = Eload(args.eload) | ||
eload.upgrade_config_if_needed(args.analysis_alias) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from copy import deepcopy | ||
|
||
from ebi_eva_common_pyutils.logger import logging_config as log_cfg | ||
|
||
from eva_submission import __version__ | ||
from eva_submission.xlsx.xlsx_parser_eva import EvaXlsxReader | ||
|
||
|
||
logger = log_cfg.get_logger(__name__) | ||
|
||
|
||
def upgrade_version_0_1(eload_cfg, analysis_alias=None): | ||
""" | ||
Upgrades a version 0.x config to version 1, using the provided analysis alias for all files. | ||
""" | ||
if 'submission' not in eload_cfg: | ||
logger.error('Need submission config section to upgrade') | ||
logger.error('Try running prepare_submission or prepare_backlog_study to build a config from scratch.') | ||
raise ValueError('Need submission config section to upgrade') | ||
|
||
# Note: if we're converting an old config, there's only one analysis | ||
if not analysis_alias: | ||
analysis_alias = get_analysis_alias_from_metadata(eload_cfg) | ||
analysis_data = { | ||
'assembly_accession': eload_cfg.pop('submission', 'assembly_accession'), | ||
'assembly_fasta': eload_cfg.pop('submission', 'assembly_fasta'), | ||
'assembly_report': eload_cfg.pop('submission', 'assembly_report'), | ||
'vcf_files': eload_cfg.pop('submission', 'vcf_files') | ||
} | ||
analysis_dict = {analysis_alias: analysis_data} | ||
eload_cfg.set('submission', 'analyses', value=analysis_dict) | ||
|
||
if 'validation' in eload_cfg: | ||
eload_cfg.pop('validation', 'valid', 'vcf_files') | ||
eload_cfg.set('validation', 'valid', 'analyses', value=analysis_dict) | ||
|
||
if 'brokering' in eload_cfg: | ||
brokering_vcfs = { | ||
vcf_file: index_dict | ||
for vcf_file, index_dict in eload_cfg.pop('brokering', 'vcf_files').items() | ||
} | ||
brokering_analyses = deepcopy(analysis_dict) | ||
brokering_analyses[analysis_alias]['vcf_files'] = brokering_vcfs | ||
eload_cfg.set('brokering', 'analyses', value=brokering_analyses) | ||
analysis_accession = eload_cfg.pop('brokering', 'ena', 'ANALYSIS') | ||
eload_cfg.set('brokering', 'ena', 'ANALYSIS', analysis_alias, value=analysis_accession) | ||
|
||
# Set version once we've successfully upgraded | ||
eload_cfg.set('version', value=__version__) | ||
|
||
|
||
def get_analysis_alias_from_metadata(eload_cfg): | ||
""" | ||
Returns analysis alias only if we find a metadata spreadsheet and it has exactly one analysis. | ||
Otherwise provides an error message and raise an error. | ||
""" | ||
metadata_spreadsheet = eload_cfg.query('validation', 'valid', 'metadata_spreadsheet') | ||
if metadata_spreadsheet: | ||
reader = EvaXlsxReader(metadata_spreadsheet) | ||
if len(reader.analysis) == 1: | ||
return reader.analysis[0].get('Analysis Alias') | ||
|
||
if len(reader.analysis) > 1: | ||
logger.error("Can't assign analysis alias: multiple analyses found in metadata!") | ||
else: | ||
logger.error("Can't assign analysis alias: no analyses found in metadata!") | ||
else: | ||
logger.error("Can't assign analysis alias: no metadata found!") | ||
logger.error("Try running upgrade_config and passing an analysis alias explicitly.") | ||
raise ValueError("Can't find an analysis alias for config upgrade.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.