-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete Curation #191
Open
tcezard
wants to merge
9
commits into
EBIvariation:master
Choose a base branch
from
tcezard:delete_curation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Delete Curation #191
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6202e3f
Allow Samples to be overwritten
tcezard 8b922a5
New process for generating BioSamples
tcezard fb96757
Update spreadsheet after new sample id have been derived
tcezard 8336661
Address review comments
tcezard 50bbdb0
New script to delete curation events
tcezard 3402e59
Actually delete the curation object
tcezard b2d9445
DELETE does not return json object
tcezard 3364c65
Fix changes after refactor
tcezard e09ee6c
Fix conflict changes
tcezard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright 2023 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 argparse | ||
|
||
from ebi_eva_common_pyutils.config import cfg | ||
from ebi_eva_common_pyutils.logger import logging_config as log_cfg | ||
|
||
from eva_submission.biosample_submission.biosamples_communicators import WebinHALCommunicator, AAPHALCommunicator | ||
from eva_submission.biosample_submission.biosamples_submitters import BioSamplesSubmitter | ||
from eva_submission.submission_config import load_config | ||
|
||
logger = log_cfg.get_logger(__name__) | ||
|
||
|
||
class LastSampleCurationDeleter(BioSamplesSubmitter): | ||
|
||
def __init__(self, communicators=None): | ||
if not communicators: | ||
communicators = LastSampleCurationDeleter.get_config_communicators() | ||
super().__init__(communicators, submit_type=('curate',), allow_removal=True) | ||
|
||
|
||
@staticmethod | ||
def get_config_communicators(): | ||
communicators = [] | ||
# If the config has the credential for using webin with BioSamples use webin first | ||
if cfg.query('biosamples', 'webin_url') and cfg.query('biosamples', 'webin_username') and \ | ||
cfg.query('biosamples', 'webin_password'): | ||
communicators.append(WebinHALCommunicator( | ||
cfg.query('biosamples', 'webin_url'), cfg.query('biosamples', 'bsd_url'), | ||
cfg.query('biosamples', 'webin_username'), cfg.query('biosamples', 'webin_password') | ||
)) | ||
communicators.append(AAPHALCommunicator( | ||
cfg.query('biosamples', 'aap_url'), cfg.query('biosamples', 'bsd_url'), | ||
cfg.query('biosamples', 'username'), cfg.query('biosamples', 'password'), | ||
cfg.query('biosamples', 'domain') | ||
)) | ||
return communicators | ||
|
||
def delete_last_curation_of(self, accession, delete=False): | ||
sample_data = self.default_communicator.follows_link('samples', method='GET', join_url=accession) | ||
curation_data = self.default_communicator.follows_link('curationLinks', json_obj=sample_data, all_pages=True) | ||
curation_links = curation_data.get('_embedded').get('curationLinks') | ||
curation_object = curation_links[-1] | ||
|
||
communicator = None | ||
# Check if we own the curation | ||
for c in self.communicators: | ||
if c.communicator_attributes.items() <= curation_object.items(): | ||
communicator = c | ||
if not communicator: | ||
self.warning(f'Curation object {curation_object["hash"]} is not owned by you: ' | ||
f'Webin: {curation_object["webinSubmissionAccountId"]} - ' | ||
f'Domain: {curation_object["domain"]}') | ||
else: | ||
if curation_object: | ||
logger.info( | ||
f'About to delete BioSamples curation {curation_object["hash"]} for accession {accession} which changed\n ' | ||
f'- attributes with {curation_object["curation"]["attributesPre"]} to {curation_object["curation"]["attributesPost"]}\n' | ||
f'- External Ref with {curation_object["curation"]["externalReferencesPre"]} to {curation_object["curation"]["externalReferencesPost"]}\n' | ||
f'- Relationship with {curation_object["curation"]["relationshipsPre"]} to {curation_object["curation"]["relationshipsPost"]}' | ||
) | ||
if delete: | ||
self.default_communicator.follows_link('self', json_obj=curation_object, method='DELETE') | ||
pass | ||
|
||
|
||
def main(): | ||
arg_parser = argparse.ArgumentParser( | ||
description='query Biosamples accessions from a file') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Description doesn't seem complete... |
||
arg_parser.add_argument('--accession_file', required=True, | ||
help='file containing the list of accession to query') | ||
arg_parser.add_argument('--set_delete', action='store_true', default=False, help='Actually does the deletion') | ||
# Load the config_file from default location | ||
load_config() | ||
|
||
args = arg_parser.parse_args() | ||
|
||
log_cfg.add_stdout_handler() | ||
|
||
# Load the config_file from default location | ||
load_config() | ||
last_sample_curation_deleter = LastSampleCurationDeleter() | ||
with open(args.accession_file) as open_file: | ||
for line in open_file: | ||
accession = line.strip() | ||
last_sample_curation_deleter.delete_last_curation_of(accession, args.set_delete) | ||
|
||
|
||
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is the same as here then it might make sense to refactor so as to not repeat logic.