def create(cls, experiment, sample, file, analysisId=None, study=None, analysisState="UNPUBLISHED", info=None): check_type(experiment, VariantCall) check_state( sample is not None and isinstance(sample, list) and len(sample) > 0, "Atleast one sample must be defined") check_state( file is not None and isinstance(file, list) and len(file) > 0, "Atleast one file must be defined") for s in sample: check_type(s, CompositeEntity) for f in file: check_type(f, File) s = VariantCallAnalysis() s.experiment = experiment s.analysisId = analysisId s.study = study s.analysisState = analysisState s.sample = sample s.file = file s.info = default_value(info, {}) return s
def new_func(*args, **kwargs): count = 1 if is_self else 0 for a in inspected_args.keys(): if a not in exclude: check_state(args[count] is not None, "The argument '{}' must be non-null", a) count += 1 return func(*args, **kwargs)
def _check_validator(cls): available_fields = Validator._INTERNAL_DICT.keys() undefined_set = set() for d in datafields: if d.name not in available_fields: undefined_set.add(d.name) num_undefined = len(undefined_set) check_state( num_undefined == 0, "The {} datafields [{}] do not exist in the class definition for '{}'", num_undefined, ",".join(undefined_set), Cls.__name__)
def validate(self, value): if self.multiple: self._validate_single(list, value) if self.required: check_state( len(value) > 0, "The required list datafield '{}' was supplied an empty array", self.name) if value is not None: for t in self.types: for item in value: self._validate_single(t, item) else: for t in self.types: self._validate_single(t, value)
def __init__(self, *datafields): self.datafields = list(datafields) check_type(self.datafields, list) check_state( len(self.datafields) > 0, "Must define atleast one datafield") self.name_type_map = {} for datafield in self.datafields: check_type(datafield, DataField) if datafield.name not in self.name_type_map: self.name_type_map[datafield.name] = {} for t in datafield.types: t_name = t.__name__ if t_name in self.name_type_map[datafield.name]: raise Exception( "Collision: The datafield definition '{}' already exists as '{}' for the type '{}'" .format(datafield, self.name_type_map[datafield.name][t_name], t_name)) self.name_type_map[datafield.name][t_name] = datafield
def create_song_error(cls, data): """ Creates a new song error object. Used to convert a json/dict server error response to a python object :param dict data: input dictionary containing all the fields neccessary to create a song server error :rtype: :class:`SongError <overture_song.model.SongError>` """ check_state(isinstance(data, dict), "input data must be of type dict") check_state(SongError.is_song_error(data), "The input data fields \n'{}'\n are not the same as the data fields in SongError \n'{}'\n", data.keys(), SongError.get_field_names()) args = [] for f in SongError.get_field_names(): result = data[f] if isinstance(result, list): args.append(tuple(result)) else: args.append(result) out = SongError(*args) return out
def _validate_single(self, t, value): if self.required: check_state(value is not None, "The datafield '{}' is required", self.name) if value is not None: if self.required: if t is str: check_state( value, "The required string datafield '{}' was supplied an empty string ", self.name) check_state( isinstance(value, t), "The datafield '{}' is of '{}' type, but was supplied a value of type '{}' with value '{}'", self.name, t, type(value), value)
def upload(config): api = Api(config) check_state(api.is_alive(), "The server '{}' is not running", config) study_client = StudyClient(api) if not study_client.has(config.study_id): study_client.create(Study.create(config.study_id)) donor = Donor() donor.studyId = config.study_id donor.donorGender = "male" donor.donorSubmitterId = "dsId1" donor.set_info("randomDonorField", "someDonorValue") specimen = Specimen() specimen.specimenClass = "Tumour" specimen.specimenSubmitterId = "sp_sub_1" specimen.specimenType = "Normal - EBV immortalized" specimen.set_info("randomSpecimenField", "someSpecimenValue") sample = Sample() sample.sampleSubmitterId = "ssId1" sample.sampleType = "RNA" sample.set_info("randomSample1Field", "someSample1Value") # File 1 file1 = File() file1.fileName = "example.bam" file1.studyId = config.study_id file1.fileAccess = "controlled" file1.fileMd5sum = "73a90acaae2b1ccc0e969709665bc62f" file1.fileSize = 1234561 file1.fileType = "BAM" file1.set_info("randomFile1Field", "someFile1Value") # File 2 file2 = File() file2.fileName = "example.bam.bai" file2.studyId = config.study_id file2.fileAccess = "controlled" file2.fileMd5sum = "67a97437c474cc1d95e0a1672b291b70" file2.fileSize = 1234562 file2.fileType = "BAI" file2.set_info("randomFile2Field", "someFile2Value") # SequencingRead sequencing_read_experiment = SequencingRead() sequencing_read_experiment.aligned = True sequencing_read_experiment.alignmentTool = "myAlignmentTool" sequencing_read_experiment.pairedEnd = True sequencing_read_experiment.insertSize = 0 sequencing_read_experiment.libraryStrategy = "WXS" sequencing_read_experiment.referenceGenome = "GR37" sequencing_read_experiment.set_info("randomSRField", "someSRValue") builder = SimplePayloadBuilder(donor, specimen, sample, [file1, file2], sequencing_read_experiment) print("-----------------------Uploading payload-------------------------") upload_response = api.upload(json_payload=builder.to_dict(), is_async_validation=False) print("upload_response: \n{}".format(upload_response)) sleep(4) print("\n\n\n-------------------Check status----------------------------") status_response = api.status(upload_response.uploadId) print("status_response: \n{}".format(status_response)) sleep(4) print("\n\n\n----------------------Saving-------------------------------") save_response = api.save(status_response.uploadId, ignore_analysis_id_collisions=True) print("save_response: \n{}".format(save_response)) sleep(4) source_dir = "./" manifest_client = ManifestClient(api) print("\n\n\n-----------------Creating manifest-------------------------") manifest = manifest_client.create_manifest(source_dir, save_response.analysisId) print("manifest_file_contents: \n{}".format(manifest))
def __init__(self, *args, **kwargs): Cls.__init__(self, *args, **kwargs) check_state(Validator.SPECIAL_FIELD in Cls.__dict__, "Decorator can only process dataclasses") Validator._check_validator()
def check_is_alive(self): check_state( self.is_alive(), "The SONG server may not be running on '{}'".format( self.config.server_url))