def import_sra_from_staging(self, ctx, params): """ :param params: instance of type "SRAToReadsParams" (required params: staging_file_subdir_path: subdirectory file path e.g. for file: /data/bulk/user_name/file_name staging_file_subdir_path is file_name for file: /data/bulk/user_name/subdir_1/subdir_2/file_name staging_file_subdir_path is subdir_1/subdir_2/file_name sequencing_tech: sequencing technology name: output reads file name workspace_name: workspace name/ID of the object Optional Params: single_genome: whether the reads are from a single genome or a metagenome. insert_size_mean: mean (average) insert length insert_size_std_dev: standard deviation of insert lengths read_orientation_outward: whether reads in a pair point outward) -> structure: parameter "staging_file_subdir_path" of String, parameter "sequencing_tech" of type "sequencing_tech", parameter "name" of type "name", parameter "workspace_name" of type "workspace_name" (workspace name of the object), parameter "single_genome" of type "single_genome", parameter "insert_size_mean" of type "insert_size_mean", parameter "insert_size_std_dev" of type "insert_size_std_dev", parameter "read_orientation_outward" of type "read_orientation_outward" :returns: instance of type "UploadMethodResult" -> structure: parameter "obj_ref" of type "obj_ref", parameter "report_name" of type "report_name", parameter "report_ref" of type "report_ref" """ # ctx is the context object # return variables are: returnVal #BEGIN import_sra_from_staging print '--->\nRunning uploadmethods.import_sra_from_staging\nparams:' print json.dumps(params, indent=1) for key, value in params.iteritems(): if isinstance(value, basestring): params[key] = value.strip() importer = ImportSRAUtil(self.config) returnVal = importer.import_sra_from_staging(params) reportVal = importer.generate_report(returnVal['obj_ref'], params) returnVal.update(reportVal) #END import_sra_from_staging # At some point might do deeper type checking... if not isinstance(returnVal, dict): raise ValueError('Method import_sra_from_staging return value ' + 'returnVal is not type dict as required.') # return the results return [returnVal]
def import_sra_from_web(self, ctx, params): """ :param params: instance of type "WebSRAToReadsParams" -> structure: parameter "download_type" of String, parameter "sra_urls_to_add" of type "sra_urls_to_add" (download_type: download type for web source fastq file ('Direct Download', 'FTP', 'DropBox', 'Google Drive') sra_urls_to_add: dict of SRA file URLs required params: file_url: SRA file URL sequencing_tech: sequencing technology name: output reads file name workspace_name: workspace name/ID of the object Optional Params: single_genome: whether the reads are from a single genome or a metagenome. insert_size_mean: mean (average) insert length insert_size_std_dev: standard deviation of insert lengths read_orientation_outward: whether reads in a pair point outward) -> structure: parameter "file_url" of String, parameter "sequencing_tech" of type "sequencing_tech", parameter "name" of type "name", parameter "single_genome" of type "single_genome", parameter "insert_size_mean" of type "insert_size_mean", parameter "insert_size_std_dev" of type "insert_size_std_dev", parameter "read_orientation_outward" of type "read_orientation_outward", parameter "workspace_name" of type "workspace_name" (workspace name of the object) :returns: instance of type "WebSRAToReadsResult" -> structure: parameter "obj_refs" of list of String, parameter "report_name" of type "report_name", parameter "report_ref" of type "report_ref" """ # ctx is the context object # return variables are: returnVal #BEGIN import_sra_from_web print '--->\nRunning uploadmethods.import_sra_from_web\nparams:' print json.dumps(params, indent=1) for key, value in params.iteritems(): if isinstance(value, basestring): params[key] = value.strip() importer = ImportSRAUtil(self.config) returnVal = importer.import_sra_from_web(params) params['uploaded_files'] = returnVal.get('uploaded_files') reportVal = importer.generate_report(returnVal['obj_refs'], params) returnVal.update(reportVal) #END import_sra_from_web # At some point might do deeper type checking... if not isinstance(returnVal, dict): raise ValueError('Method import_sra_from_web return value ' + 'returnVal is not type dict as required.') # return the results return [returnVal]
def __init__(self, config): self.uploader_utils = UploaderUtil(config) self.sra_importer = ImportSRAUtil(config)
class ImportReadsUtil: def __init__(self, config): self.uploader_utils = UploaderUtil(config) self.sra_importer = ImportSRAUtil(config) def import_reads_from_staging(self, params): self._validate_import_reads_from_staging_params(params) if params.get('import_type') == 'FASTQ/FASTA': fastq_importer_params = params fastq_importer_params['fwd_staging_file_name'] = params.get( 'fastq_fwd_staging_file_name') fastq_importer_params['rev_staging_file_name'] = params.get( 'fastq_rev_staging_file_name') returnVal = self.uploader_utils.upload_fastq_file( fastq_importer_params) uploaded_file = params.get('fastq_fwd_staging_file_name') if params.get('fastq_rev_staging_file_name') is not None: uploaded_file += '\n' + params.get( 'fastq_rev_staging_file_name') fastq_importer_params['uploaded_files'] = [uploaded_file] """ Update the workspace object related meta-data for staged file """ self.uploader_utils.update_staging_service( params.get('fastq_fwd_staging_file_name'), returnVal['obj_ref']) if params.get('fastq_rev_staging_file_name') is not None: self.uploader_utils.update_staging_service( params.get('fastq_rev_staging_file_name'), returnVal['obj_ref']) reportVal = self.sra_importer.generate_report( [returnVal['obj_ref']], fastq_importer_params) returnVal.update(reportVal) elif params.get('import_type') == 'SRA': sra_importer_params = params sra_importer_params['staging_file_subdir_path'] = params.get( 'sra_staging_file_name') returnVal = self.sra_importer.import_sra_from_staging( sra_importer_params) sra_importer_params['uploaded_files'] = [ params.get('sra_staging_file_name') ] """ Update the workspace object related meta-data for staged file """ self.uploader_utils.update_staging_service( params.get('sra_staging_file_name'), returnVal['obj_ref']) reportVal = self.sra_importer.generate_report( [returnVal['obj_ref']], sra_importer_params) returnVal.update(reportVal) return returnVal def _validate_import_reads_from_staging_params(self, params): """ _validate_import_reads_from_staging_params: validates params passed to import_reads_from_staging method """ # check for required parameters for p in ['import_type', 'sequencing_tech', 'name', 'workspace_name']: if p not in params: raise ValueError( '"{}" parameter is required, but missing'.format(p)) valide_import_type = ['FASTQ/FASTA', 'SRA'] if params.get('import_type') not in valide_import_type: error_msg = 'Import file type [{}] is not supported. '.format( params.get('import_type')) error_msg += 'Please selet one of {}'.format(valide_import_type) raise ValueError(error_msg) if (params.get('import_type') == 'FASTQ/FASTA' and not params.get('fastq_fwd_staging_file_name')): error_msg = 'FASTQ/FASTA input file type selected. But missing FASTQ/FASTA file.' raise ValueError(error_msg) if (params.get('import_type') == 'SRA' and not params.get('sra_staging_file_name')): error_msg = 'SRA input file type selected. But missing SRA file.' raise ValueError(error_msg) if ((params.get('fastq_fwd_staging_file_name') and params.get('sra_staging_file_name')) or (params.get('fastq_rev_staging_file_name') and params.get('sra_staging_file_name'))): error_msg = 'Both SRA and FASTQ/FASTA file given. Please provide one file type only.' raise ValueError(error_msg)