Exemple #1
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace, All the arguments that were provided to this
        command invocation.

    Returns:
      an Operation message which tracks the asynchronous import
    """
        apitools_client = genomics_util.GetGenomicsClient()
        genomics_messages = genomics_util.GetGenomicsMessages()

        if not args.source_uris:
            raise GenomicsError(
                'at least one value is required for --source-uris')

        partition_enum = (genomics_messages.ImportReadGroupSetsRequest.
                          PartitionStrategyValueValuesEnum)
        partition_strat = None
        if args.partition_strategy:
            if args.partition_strategy not in partition_enum.to_dict():
                raise GenomicsError(
                    '--partition-strategy must be one of {0}; received: {1}'.
                    format(sorted(partition_enum.names()),
                           args.partition_strategy))
            partition_strat = partition_enum.lookup_by_name(
                args.partition_strategy)

        try:
            return apitools_client.readgroupsets.Import(
                genomics_messages.ImportReadGroupSetsRequest(
                    datasetId=args.dataset_id,
                    sourceUris=args.source_uris,
                    referenceSetId=args.reference_set_id,
                    partitionStrategy=partition_strat,
                ))
        except apitools_exceptions.HttpError as error:
            # Map our error messages (JSON API camelCased) back into flag names.
            msg = (
                exceptions.HttpException(error).payload.status_message.replace(
                    'datasetId', '--dataset-id').replace(
                        'partitionStrategy', '--partition-strategy').replace(
                            'sourceUris',
                            '--source-uris').replace('referenceSetId',
                                                     '--reference-set-id'))
            unused_type, unused_value, traceback = sys.exc_info()
            raise exceptions.HttpException, msg, traceback
Exemple #2
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace, All the arguments that were provided to this
        command invocation.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    Returns:
      None
    """
        apitools_client = genomics_util.GetGenomicsClient()
        genomics_messages = genomics_util.GetGenomicsMessages()

        name = args.name
        if not name.startswith(_OPERATIONS_PREFIX):
            name = _OPERATIONS_PREFIX + name

        # Look up the operation so we can display it in the confirmation prompt
        op = apitools_client.operations.Get(
            genomics_messages.GenomicsOperationsGetRequest(name=name))
        operation_string = StringIO()
        print_format = display.Displayer(self, args).GetFormat()
        resource_printer.Print(op, print_format, out=operation_string)

        if not console_io.PromptContinue(
                message='%s\n%s' %
            (operation_string.getvalue(), 'This operation will be canceled')):
            raise GenomicsError('Cancel aborted by user.')

        apitools_client.operations.Cancel(
            genomics_messages.GenomicsOperationsCancelRequest(name=name))
        log.status.write('Canceled [{0}].\n'.format(name))
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace, All the arguments that were provided to this
        command invocation.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    Returns:
      None
    """
        # Look it up first so that we can display the name
        existing_cs = genomics_util.GetCallSet(self.context, args.id)
        prompt_message = (
            'Deleting call set {0} ({1}) will delete all objects in the '
            'call set.').format(existing_cs.id, existing_cs.name)
        if not console_io.PromptContinue(message=prompt_message):
            raise GenomicsError('Deletion aborted by user.')
        apitools_client = self.context[lib.GENOMICS_APITOOLS_CLIENT_KEY]
        genomics_messages = self.context[lib.GENOMICS_MESSAGES_MODULE_KEY]
        call_set = genomics_messages.GenomicsCallsetsDeleteRequest(
            callSetId=args.id, )

        apitools_client.callsets.Delete(call_set)
        log.DeletedResource('{0} ({1})'.format(existing_cs.id,
                                               existing_cs.name))
Exemple #4
0
  def Run(self, args):
    """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace, All the arguments that were provided to this
        command invocation.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    Returns:
      None
    """
    apitools_client = genomics_util.GetGenomicsClient()
    genomics_messages = genomics_util.GetGenomicsMessages()

    # Look it up first so that we can display the name
    existing_rgs = apitools_client.readgroupsets.Get(
        genomics_messages.GenomicsReadgroupsetsGetRequest(readGroupSetId=args.id))

    prompt_message = (
        'Deleting read group set {0} ({1}) will delete all objects in the read '
        'group set.').format(args.id, existing_rgs.name)

    if not console_io.PromptContinue(message=prompt_message):
      raise GenomicsError('Deletion aborted by user.')

    apitools_client.readgroupsets.Delete(
        genomics_messages.GenomicsReadgroupsetsDeleteRequest(
            readGroupSetId=str(args.id)))
    log.DeletedResource('{0} ({1})'.format(args.id,
                                           existing_rgs.name))
Exemple #5
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace, All the arguments that were provided to this
        command invocation.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    Returns:
      None
    """
        prompt_message = ('Restoring dataset {0} will restore all objects in '
                          'the dataset.').format(args.id)

        if not console_io.PromptContinue(message=prompt_message):
            raise GenomicsError('Restore aborted by user.')

        apitools_client = self.context[lib.GENOMICS_APITOOLS_CLIENT_KEY]
        genomics_messages = self.context[lib.GENOMICS_MESSAGES_MODULE_KEY]

        dataset = genomics_messages.GenomicsDatasetsUndeleteRequest(
            datasetId=str(args.id), )

        return apitools_client.datasets.Undelete(dataset)
Exemple #6
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace, All the arguments that were provided to this
        command invocation.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    Returns:
      None
    """
        # Look it up first so that we can display the name
        existing_ds = genomics_util.GetDataset(args.id)

        prompt_message = (
            'Deleting dataset {0} ({1}) will delete all objects in the dataset. '
            'Deleted datasets can be recovered with the "restore" command '
            'up to one week after the deletion occurs.').format(
                existing_ds.id, existing_ds.name)

        if not console_io.PromptContinue(message=prompt_message):
            raise GenomicsError('Deletion aborted by user.')

        apitools_client = genomics_util.GetGenomicsClient()
        genomics_messages = genomics_util.GetGenomicsMessages()

        dataset = genomics_messages.GenomicsDatasetsDeleteRequest(
            datasetId=str(args.id), )

        apitools_client.datasets.Delete(dataset)
        log.DeletedResource('{0} ({1})'.format(existing_ds.id,
                                               existing_ds.name))
Exemple #7
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace, All the arguments that were provided to this
        command invocation.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    Returns:
      None
    """
        apitools_client = self.context[lib.GENOMICS_APITOOLS_CLIENT_KEY]
        genomics_messages = self.context[lib.GENOMICS_MESSAGES_MODULE_KEY]

        name = args.name
        if not name.startswith(_OPERATIONS_PREFIX):
            name = _OPERATIONS_PREFIX + name

        # Look it up first so that we can display it
        op = apitools_client.operations.Get(
            genomics_messages.GenomicsOperationsGetRequest(name=name))
        self.format(op)

        if not console_io.PromptContinue(
                message='This operation will be canceled'):
            raise GenomicsError('Cancel aborted by user.')

        apitools_client.operations.Cancel(
            genomics_messages.GenomicsOperationsCancelRequest(name=name))
        log.status.write('Canceled [{0}].\n'.format(name))
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace, All the arguments that were provided to this
        command invocation.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    Returns:
      None
    """
        prompt_message = ('Restoring dataset {0} will restore all objects in '
                          'the dataset.').format(args.id)

        if not console_io.PromptContinue(message=prompt_message):
            raise GenomicsError('Restore aborted by user.')

        apitools_client = genomics_util.GetGenomicsClient()
        genomics_messages = genomics_util.GetGenomicsMessages()

        dataset = genomics_messages.GenomicsDatasetsUndeleteRequest(
            datasetId=args.id)

        result = apitools_client.datasets.Undelete(dataset)
        log.RestoredResource('{0}, id: {1}'.format(result.name, result.id),
                             kind='dataset')
        return result
Exemple #9
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace, All the arguments that were provided to this
        command invocation.

    Raises:
      HttpException: An http error response was received while executing api
          request.
      GenomicsError: if canceled by the user.
    Returns:
      None
    """

        prompt_message = (
            'Deleting variant set {0} will delete all its contents '
            '(variants, callsets, and calls). '
            'The variant set object is not deleted.').format(
                args.variant_set_id)

        if not console_io.PromptContinue(message=prompt_message):
            raise GenomicsError('Deletion aborted by user.')

        apitools_client = self.context[lib.GENOMICS_APITOOLS_CLIENT_KEY]
        genomics_messages = self.context[lib.GENOMICS_MESSAGES_MODULE_KEY]

        req = genomics_messages.GenomicsVariantsetsDeleteRequest(
            variantSetId=str(args.variant_set_id), )

        ret = apitools_client.variantsets.Delete(req)
        log.DeletedResource('{0}'.format(args.variant_set_id))
        return ret
Exemple #10
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace, All the arguments that were provided to this
        command invocation.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    Returns:
      None
    """
        client, resource = genomics_client.CreateFromName(args.name)
        op = client.GetOperation(resource)

        operation_string = io.StringIO()
        print_format = display.Displayer(self, args).GetFormat()
        resource_printer.Print(op, print_format, out=operation_string)

        if not console_io.PromptContinue(
                message='%s\n%s' %
            (operation_string.getvalue(), 'This operation will be canceled')):
            raise GenomicsError('Cancel aborted by user.')

        client.CancelOperation(resource)
        log.status.write('Canceled [{0}].\n'.format(resource.RelativeName()))
Exemple #11
0
def ValidateLimitFlag(limit, flag_name='limit'):
    """Validates a limit flag value.

  Args:
    limit: the limit flag value to sanitize.
    flag_name: the name of the limit flag - defaults to limit
  Raises:
    GenomicsError: if the provided limit flag value is negative
  """
    if limit is None:
        return

    if limit < 0:
        raise GenomicsError(
            '--{0} must be a non-negative integer; received: {1}'.format(
                flag_name, limit))
Exemple #12
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace, All the arguments that were provided to this
        command invocation.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    Returns:
      None
    """
        op = None
        apitools_client = genomics_util.GetGenomicsClient('v2alpha1')
        genomics_messages = genomics_util.GetGenomicsMessages('v2alpha1')

        name, v2 = genomics_util.CanonicalizeOperationName(args.name)
        if v2:
            op = apitools_client.projects_operations.Get(
                genomics_messages.GenomicsProjectsOperationsGetRequest(
                    name=name))
        else:
            apitools_client = genomics_util.GetGenomicsClient()
            genomics_messages = genomics_util.GetGenomicsMessages()
            op = apitools_client.operations.Get(
                genomics_messages.GenomicsOperationsGetRequest(name=name))

        operation_string = io.StringIO()
        print_format = display.Displayer(self, args).GetFormat()
        resource_printer.Print(op, print_format, out=operation_string)

        if not console_io.PromptContinue(
                message='%s\n%s' %
            (operation_string.getvalue(), 'This operation will be canceled')):
            raise GenomicsError('Cancel aborted by user.')

        if v2:
            apitools_client.projects_operations.Cancel(
                genomics_messages.GenomicsProjectsOperationsCancelRequest(
                    name=name))
        else:
            apitools_client.operations.Cancel(
                genomics_messages.GenomicsOperationsCancelRequest(name=name))
        log.status.write('Canceled [{0}].\n'.format(name))
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace, All the arguments that were provided to this
        command invocation.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    Returns:
      None
    """
        apitools_client = genomics_util.GetGenomicsClient()
        genomics_messages = genomics_util.GetGenomicsMessages()

        if not (args.name or args.reference_set_id):
            raise GenomicsError(
                'Must specify --name and/or --reference-set-id')

        updated = genomics_messages.ReadGroupSet()
        mask = []
        # TODO(b/26871577): Consider using resource parser here
        if args.name:
            updated.name = args.name
            mask.append('name')
        if args.reference_set_id:
            updated.referenceSetId = args.reference_set_id
            mask.append('referenceSetId')

        request = genomics_messages.GenomicsReadgroupsetsPatchRequest(
            readGroupSet=updated,
            readGroupSetId=str(args.id),
            updateMask=','.join(mask))

        result = apitools_client.readgroupsets.Patch(request)
        name = str(result.id)
        if result.name:
            name += ', name: {0}'.format(result.name)
        if result.referenceSetId:
            name += ', referenceSetId: {0}'.format(result.referenceSetId)
        log.UpdatedResource(name, kind='readgroupset')
        return result
Exemple #14
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace, All the arguments that were provided to this
        command invocation.

    Raises:
      HttpException: An http error response was received while executing api
          request.
      GenomicsError: if canceled by the user.
    Returns:
      None
    """

        apitools_client = genomics_util.GetGenomicsClient()
        genomics_messages = genomics_util.GetGenomicsMessages()

        get_request = genomics_messages.GenomicsVariantsetsGetRequest(
            variantSetId=str(args.variant_set_id))

        variant_set = apitools_client.variantsets.Get(get_request)

        prompt_message = (
            'Deleting variant set {0}: "{1}" will also delete all its contents '
            '(variants, callsets, and calls).').format(args.variant_set_id,
                                                       variant_set.name)

        if not console_io.PromptContinue(message=prompt_message):
            raise GenomicsError('Deletion aborted by user.')

        req = genomics_messages.GenomicsVariantsetsDeleteRequest(
            variantSetId=args.variant_set_id, )

        ret = apitools_client.variantsets.Delete(req)
        log.DeletedResource('{0}: "{1}"'.format(args.variant_set_id,
                                                variant_set.name))
        return ret
Exemple #15
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace, All the arguments that were provided to this
        command invocation.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    Returns:
      None
    """
        apitools_client = self.context[lib.GENOMICS_APITOOLS_CLIENT_KEY]
        genomics_messages = self.context[lib.GENOMICS_MESSAGES_MODULE_KEY]

        if not (args.name or args.reference_set_id):
            raise GenomicsError(
                'Must specify --name and/or --reference-set-id')

        updated = genomics_messages.ReadGroupSet()
        mask = []
        # TODO(b/26871577): Consider using resource parser here
        if args.name:
            updated.name = args.name
            mask.append('name')
        if args.reference_set_id:
            updated.referenceSetId = args.reference_set_id
            mask.append('referenceSetId')

        request = genomics_messages.GenomicsReadgroupsetsPatchRequest(
            readGroupSet=updated,
            readGroupSetId=str(args.id),
            updateMask=','.join(mask))

        return apitools_client.readgroupsets.Patch(request)