예제 #1
0
 def validate_entity(self, entity: Entity):
     # identify which attribute cases the error
     attribute = 'fake_attribute'
     error_msg = 'Example error message'
     entity.add_error(attribute, error_msg)
     # or if multiple errors occur for the same attribute
     error_msgs = ['error 1', 'error 2']
     entity.add_errors(attribute, error_msgs)
     raise NotImplementedError('Example validate entity used')
예제 #2
0
 def add_errors(self, schema, ena_type: str, entity_type: str, entity: Entity):
     for error in schema.error_log:
         match = self.regex.match(error.message)
         error_message = match.group('error') if match else error.message
         error_attribute = error.path.rpartition('/')[2].lower()
         if error_attribute not in entity.attributes:
             error_attribute = f'{entity_type}_ena_{ena_type}_accession'.lower()
             error_message = f'{error.path} {error_message}'
         entity.add_error(error_attribute, error_message)
예제 #3
0
 def validate_file(self, entity: Entity, file_attribute: str,
                   check_attribute: str):
     file_name = entity.attributes[file_attribute]
     if file_name not in self.file_checksum_map:
         entity.add_error(
             file_attribute,
             f'File has not been uploaded to drag-and-drop: {file_name}')
         return
     upload_checksum = self.file_checksum_map[file_name]
     if check_attribute in entity.attributes:
         stated_checksum = entity.attributes[check_attribute]
         if stated_checksum != upload_checksum:
             entity.add_error(
                 check_attribute,
                 f'The checksum found on drag-and-drop {upload_checksum} does not match: {stated_checksum}'
             )
             return
     else:
         entity.attributes[check_attribute] = upload_checksum
예제 #4
0
    def convert_experiment(converter: EnaExperimentConverter, data: Submission, experiment: Entity) -> Element:
        samples = data.get_linked_entities(experiment, 'sample')
        studies = data.get_linked_entities(experiment, 'study')

        if len(samples) < 1 or len(studies) < 1:
            if len(samples) < 1:
                experiment.add_error('run_experiment_ena_experiment_accession', 'No Linked Sample')
            if len(studies) < 1:
                experiment.add_error('run_experiment_ena_experiment_accession', 'No Linked Study')
        else:
            len_samples = len(samples)
            len_studies = len(studies)
            sample = samples.pop()
            study = studies.pop()

            # ENA Only supports linking one study & sample to an experiment
            if len_samples > 1:
                experiment.add_error('run_experiment_ena_experiment_accession', f'More than one Sample Linked, using first: {sample.identifier.index}')
            if len_studies > 1:
                experiment.add_error('run_experiment_ena_experiment_accession', f'More than one Study Linked, using first: {study.identifier.index}')
            return converter.convert_experiment(experiment, sample, study)