def run_prefix( # pylint: disable=too-many-arguments project_id, prefix, metadata_json, status, host, email, password, api_key ): # pylint: disable=C0301 """Assign all uploads from Gencove prefix to a project. Optionally add metadata to the samples. Uploads can also be filtered through status. Examples: Assign uploads to a project: gencove projects run-prefix 06a5d04b-526a-4471-83ba-fb54e0941758 gncv://my-project/path Assign uploads to a project with metadata: gencove projects run-prefix 06a5d04b-526a-4471-83ba-fb54e0941758 gncv://my-project/path --metadata-json='{"batch": "batch1"}' Assign uploads filtered by status to a project: gencove projects run-prefix 06a5d04b-526a-4471-83ba-fb54e0941758 gncv://my-project/path --status assigned """ # noqa: E501 RunPrefix( project_id, prefix, Credentials(email=email, password=password, api_key=api_key), RunPrefixOptionals( host=host, metadata_json=metadata_json, status=status ), ).run()
def test_login_mfa(mocker): """Test that the the login function in APIClient asks for the one time password token. """ api_client = APIClient() credentials = Credentials(email="*****@*****.**", password="******", api_key="") def _request( endpoint, params, *args, # pylint: disable=unused-argument **kwargs, # pylint: disable=unused-argument ): if endpoint == ApiEndpoints.GET_JWT.value: if "otp_token" not in params: raise APIClientError( {"otp_token": ["Please enter your OTP token."]}, 401) return {"access": "access", "refresh": "refresh"} return {} mocked_request = mocker.patch.object(APIClient, "_request", side_effect=_request) mocked_prompt = mocker.patch("gencove.utils.click.prompt", return_value="token") login(api_client, credentials) assert mocked_request.call_count == 2 mocked_prompt.assert_called_once_with("One time password", type=str, err=True)
def create_project_batch( # pylint: disable=too-many-arguments project_id, batch_type, batch_name, sample_ids, host, email, password, api_key, ): """Create a batch in a project.""" if sample_ids: sample_ids = [s_id.strip() for s_id in sample_ids.split(",")] echo_debug("Sample ids translation: {}".format(sample_ids)) else: sample_ids = [] CreateBatch( project_id, batch_type, batch_name, sample_ids, Credentials(email=email, password=password, api_key=api_key), Optionals(host=host), ).run()
def create( # pylint: disable=too-many-arguments project_id, identifier, metadata_json, host, email, password, api_key, ): # pylint: disable=line-too-long """Sets up periodic import of BaseSpace projects (their Biosamples) whose name contain the identifer to a project in Gencove. Optionally assign metadata to the samples to be added when the automatic import job runs. Examples: Set up automatic import of BaseSpace projects' samples that contain the identifier to a project: gencove basespace autoimports create 06a5d04b-526a-4471-83ba-fb54e0941758 identifier-in-basespace-project-name Set up automatic import of BaseSpace projects' samples that contain the identifier to a project with metadata: gencove basespace autoimports create 06a5d04b-526a-4471-83ba-fb54e0941758 identifier-in-basespace-project-name --metadata-json='{"batch": "batch1"}' """ # noqa: E501 BaseSpaceAutoImport( project_id, identifier, Credentials(email=email, password=password, api_key=api_key), BaseSpaceAutoImportOptionals(host=host, metadata_json=metadata_json), ).run()
def s3_import( # pylint: disable=too-many-arguments s3_uri, project_id, metadata_json, host, email, password, api_key, ): # pylint: disable=line-too-long """Import all samples from a S3 URI to a project. Optionally add metadata to the samples. Examples: Import samples to a project: gencove s3 import s3://bucket/path/ 06a5d04b-526a-4471-83ba-fb54e0941758 Import samples to a project: gencove s3 import s3://bucket/path/ 06a5d04b-526a-4471-83ba-fb54e0941758 --metadata-json='{"batch": "batch1"}' """ # noqa: E501 S3Import( s3_uri, project_id, Credentials(email=email, password=password, api_key=api_key), S3ImportOptionals(host=host, metadata_json=metadata_json), ).run()
def biosamples_list( basespace_project_id, host, email, password, api_key, ): """List all Biosamples from BaseSpace project. Examples: List Biosamples of a BaseSpace project: gencove basespace biosamples list 12345678 List Biosamples of a BaseSpace projects: gencove basespace biosamples list 12345678,87654321 """ BiosamplesList( basespace_project_id, Credentials(email=email, password=password, api_key=api_key), Optionals(host=host), ).run()
def list_project_batch_types(project_id, host, email, password, api_key): """List batch types that are available for a project.""" ListBatchTypes( project_id, Credentials(email=email, password=password, api_key=api_key), Optionals(host=host), ).run()
def create( # pylint: disable=too-many-arguments project_id, s3_uri, metadata_json, host, email, password, api_key, ): # pylint: disable=line-too-long """Sets up automatic import from S3 URI to a project in Gencove. Optionally assign metadata to the samples to be added when the automatic import job runs. Examples: Set up automatic import from S3 to a project: gencove s3 autoimports create 06a5d04b-526a-4471-83ba-fb54e0941758 s3://bucket/path/to/project Set up automatic import from S3 to a project with metadata: gencove s3 autoimports create 06a5d04b-526a-4471-83ba-fb54e0941758 s3://bucket/path/to/project --metadata-json='{"batch": "batch1"}' """ # noqa: E501 S3AutoImport( project_id, s3_uri, Credentials(email=email, password=password, api_key=api_key), S3AutoImportOptionals(host=host, metadata_json=metadata_json), ).run()
def list_uploads( # pylint: disable=E0012,C0330,R0913 search, status, host, email, password, api_key ): """List user uploads.""" ListSampleSheet( Credentials(email=email, password=password, api_key=api_key), UploadsOptions(host=host, status=status, search=search), ).run()
def get_batch(batch_id, output_filename, host, email, password, api_key, no_progress): """Get batch that is available for a project.""" GetBatch( batch_id, output_filename, Credentials(email=email, password=password, api_key=api_key), Optionals(host=host), no_progress, ).run()
def upload( # pylint: disable=E0012,C0330,R0913 source, destination, host, email, password, api_key, run_project_id, output, no_progress, metadata, ): # noqa: D301 """Upload FASTQ files to Gencove's system. SOURCE: folder that contains fastq files to be uploaded (acceptable file extensions are .fastq.gz, .fastq.bgz, .fq.gz, .fq.bgz), or .fastq-map.csv file with the mapping of R1/R2 files to related sample by client_id DESTINATION (optional): gncv://[folder], where the folder is the location on Gencove systems Examples: Upload directory contents: gencove upload test_dataset gncv://test \f Args: source (.fastq.gz, .fastq.bgz, .fq.gz, .fq.bgz): folder that contains fastq files to be uploaded OR .fastq-map.csv file destination (str, optional): 'gncv://' notated folder on Gencove's system, where the files will be uploaded to. run_project_id (UUID, optional): ID of a project to which all files in this upload will be assigned to and then immediately analyzed. output (str, optional): must be used with run_project_id. "-" redirects the JSON to STDOUT, and a name redirects the output to a file. no_progress (bool, optional, default False): do not show progress bar. metadata (str, optional): JSON metadata to be applied to all samples """ Upload( source, destination, Credentials(email=email, password=password, api_key=api_key), UploadOptions( host=host, project_id=run_project_id, metadata=metadata ), output, no_progress, ).run()
def status_merged_vcf( project_id, host, email, password, api_key, ): """Get status of merge VCF files job in a project.""" StatusMergedVCF( project_id, Credentials(email=email, password=password, api_key=api_key), Optionals(host=host), ).run()
def create_merged_vcf( project_id, host, email, password, api_key, ): """Merge VCF files in a project.""" CreateMergedVCF( project_id, Credentials(email=email, password=password, api_key=api_key), Optionals(host=host), ).run()
def list_project_samples( # pylint: disable=E0012,C0330,R0913 project_id, search, status, archive_status, host, email, password, api_key): """List samples in a project.""" ListSamples( project_id, Credentials(email=email, password=password, api_key=api_key), SamplesOptions( host=host, status=status, archive_status=archive_status, search=search, ), ).run()
def get_metadata( sample_id, output_filename, host, email, password, api_key, ): """Get sample metadata.""" GetMetadata( sample_id, output_filename, Credentials(email=email, password=password, api_key=api_key), Optionals(host=host), ).run()
def set_metadata( sample_id, json, host, email, password, api_key, ): """Set sample metadata.""" SetMetadata( sample_id, json, Credentials(email=email, password=password, api_key=api_key), Optionals(host=host), ).run()
def get_merged_vcf( project_id, output_filename, host, email, password, api_key, no_progress, ): """Download merged VCF file in a project.""" GetMergedVCF( project_id, output_filename, Credentials(email=email, password=password, api_key=api_key), Optionals(host=host), no_progress, ).run()
def delete_project_samples( # pylint: disable=too-many-arguments project_id, sample_ids, host, email, password, api_key, ): """Delete samples in a project.""" sample_ids = ([s_id.strip() for s_id in sample_ids.split(",")] if sample_ids else []) echo_debug("Sample ids translation: {}".format(sample_ids)) DeleteSamples( project_id, sample_ids, Credentials(email=email, password=password, api_key=api_key), Optionals(host=host), ).run()
def basespace_list( host, email, password, api_key, ): """List all BaseSpace projects. Examples: Import Biosamples to a project: gencove basespace projects list """ BaseSpaceList( Credentials(email=email, password=password, api_key=api_key), Optionals(host=host), ).run()
def autoimport_list( host, email, password, api_key, ): """Lists S3 automatic import jobs. Examples: List S3 automatic import jobs: gencove s3 autoimports list """ # noqa: E501 S3AutoImportList( Credentials(email=email, password=password, api_key=api_key), Optionals(host=host), ).run()
def basespace_import( # pylint: disable=too-many-arguments basespace_project_ids, project_id, metadata_json, host, email, password, api_key, ): # pylint: disable=line-too-long """Import all Biosamples from BaseSpace projects to a project. Optionally add metadata to the samples. Examples: Import Biosamples to a project: gencove basespace projects import 12345678 06a5d04b-526a-4471-83ba-fb54e0941758 Import Biosamples from multiple BaseSpace projects to a project: gencove basespace projects import 12345678,87654321 06a5d04b-526a-4471-83ba-fb54e0941758 Import Biosamples to a project with metadata: gencove basespace projects import 12345678 06a5d04b-526a-4471-83ba-fb54e0941758 --metadata-json='{"batch": "batch1"}' """ # noqa: E501 basespace_project_ids = [ basespace_project_id.strip() for basespace_project_id in basespace_project_ids.split(",") ] echo_debug( "BaseSpace project ids translation: {}".format(basespace_project_ids)) BaseSpaceImport( basespace_project_ids, project_id, Credentials(email=email, password=password, api_key=api_key), BaseSpaceImportOptionals(host=host, metadata_json=metadata_json), ).run()
def download( # pylint: disable=E0012,C0330,R0913 destination, project_id, sample_ids, file_types, skip_existing, download_urls, download_template, host, email, password, api_key, no_progress, ): # noqa: D413,D301,D412 # pylint: disable=C0301 """Download deliverables of a project. Must specify either project id or sample ids. Examples: Download all samples results: gencove download ./results --project-id d9eaa54b-aaac-4b85-92b0-0b564be6d7db Download some samples: gencove download ./results --sample-ids 59f5c1fd-cce0-4c4c-90e2-0b6c6c525d71,7edee497-12b5-4a1d-951f-34dc8dce1c1d Download specific deliverables: gencove download ./results --project-id d9eaa54b-aaac-4b85-92b0-0b564be6d7db --file-types alignment-bam,impute-vcf,fastq-r1,fastq-r2 Skip download entirely and print out the deliverables as a JSON: gencove download - --project-id d9eaa54b-aaac-4b85-92b0-0b564be6d7db --download-urls \f Args: destination (str): path/to/save/deliverables/to. project_id (str): project id in Gencove's system. sample_ids (list(str), optional): specific samples for which to download the results. if not specified, download deliverables for all samples. file_types (list(str), optional): specific deliverables to download results for. if not specified, all file types will be downloaded. skip_existing (bool, optional, default True): skip downloading existing files. download_urls (bool, optional): output the files available for a download. if the destination parameter is "-", it goes to the stdout. no_progress (bool, optional, default False): do not show progress bar. """ # noqa: E501 s_ids = tuple() if sample_ids: s_ids = tuple(s_id.strip() for s_id in sample_ids.split(",")) echo_debug("Sample ids translation: {}".format(s_ids)) f_types = tuple() if file_types: f_types = tuple(f_type.strip() for f_type in file_types.split(",")) echo_debug("File types translation: {}".format(f_types)) Download( destination, DownloadFilters(project_id=project_id, sample_ids=s_ids, file_types=f_types), Credentials(email=email, password=password, api_key=api_key), DownloadOptions( host=host, skip_existing=skip_existing, download_template=download_template, ), download_urls, no_progress, ).run()
def download_file( sample_id, file_type, destination, host, email, password, api_key, no_progress, ): # noqa: D413,D301,D412 # pylint: disable=C0301 """Download sample file metadata. SAMPLE_ID specific sample for which to download the results FILE_TYPE specific deliverable to download results for DESTINATION path/to/file Examples: Download sample: gencove samples download-file e6b45af7-07c5-4a6d-9f97-6e1efbf3e215 ancestry-json ancestry.json Download and print to stdout then compress using gzip: gencove samples download-file e6b45af7-07c5-4a6d-9f97-6e1efbf3e215 ancestry-json - | gzip > ancestry.json.gz \f Args: sample_id (str): specific sample for which to download the results. file_type (str): specific deliverable to download results for. destination (str): path/to/file. no_progress (bool, optional, default False): do not show progress bar. """ # noqa: E501 if destination in ("-", "/dev/stdout"): DownloadFile( sample_id, file_type, sys.stdout.buffer, Credentials(email=email, password=password, api_key=api_key), Optionals(host=host), no_progress, ).run() else: try: with open(destination, "wb") as destination_file: DownloadFile( sample_id, file_type, destination_file, Credentials(email=email, password=password, api_key=api_key), Optionals(host=host), no_progress, ).run() except IsADirectoryError: echo_error("Please specify a file path (not directory path)" " for DESTINATION") raise click.Abort() # pylint: disable=raise-missing-from
def list_projects(host, email, password, api_key): """List your projects.""" List( Credentials(email=email, password=password, api_key=api_key), Optionals(host=host), ).run()