
    5i<                         d Z ddlmZmZmZmZ ddlZddlmZm	Z	m
Z
mZ ddlmZ ddlmZ g d	Zg d
Zg Zg dZ G d dee	      Zy)a  
DXApp Handler
+++++++++++++

Apps allow for application logic to be distributed to users in the
system, and they allow for analyses to be run in a reproducible and
composable way.

Apps extend the functionality of applets to require input/output
specifications as well as to allow for versioning, collaborative
development, and policies for billing and data access. Similarly to
applets, apps can be run by calling their
:meth:`~dxpy.bindings.dxapp.DXApp.run` method.

Unlike applets, apps are not data objects and do not live in projects.
Instead, they share a single global namespace. An app may have multiple
different versions (e.g. "1.0.0", "1.0.1", etc.) associated with a
single name (which is of the form "app-APPNAME"). A particular version
of an app may be identified in two ways, either by specifying a
combination of its name and a version (or a *tag*), or by specifying its
unique identifier.

Each app has a list of developers, which are the users that are
authorized to publish new versions of an app; perform administrative
tasks, such as assigning categories, and attaching new tags to versions
of the app; and add or remove other developers. When the first version
of an app with a given name is created, the creating user initially
becomes the sole developer of the app.

    )print_functionunicode_literalsdivisionabsolute_importN   )DXObjectDXExecutableDXJobverify_string_dxid   )DXError)
basestring)nametitlesummarydxapi
openSourcehttpsAppversion	inputSpec
outputSpecrunSpec
developersauthorizedUsersregionalOptions)details
categoriesaccessignoreReusetreeTurnaroundTimeThreshold)	r   r   r   r   r   r   r   r   r   c                        e Zd ZdZdZddZddZd Zd ZddZ	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z fdZ xZS )DXAppz%
    Remote app object handler.

    appc                 `    t        j                  |        ||| j                  |||       y y )N)dxidr   alias)r   __init__set_idselfr%   r   r&   s       u/home/marpiech/ifpan-abm-pgxpred/analysis/marpiech-gwas-test/venv/lib/python3.12/site-packages/dxpy/bindings/dxapp.pyr'   zDXApp.__init__O   s2    $t/KKTEK:  0    c                 :   d| _         d| _        d| _        |-||t        d      t	        || j
                         || _         y|U|| _        t        |t              st        d|      |&t        |t              st        d|      || _        yd| _        yy)aF  
        :param dxid: App ID
        :type dxid: string
        :param name: App name
        :type name: string
        :param alias: App version or tag
        :type alias: string
        :raises: :exc:`~dxpy.exceptions.DXError` if *dxid* and some other input are both given or if neither *dxid* nor *name* are given

        Discards the currently stored ID and associates the handler
        with the requested parameters.  Note that if *dxid* is given,
        the other fields should not be given, and if *name* is given,
        *alias* has default value "default".

        Nz9Did not expect name or alias to be given if dxid is givenzApp name needs to be a string: z App alias needs to be a string: default)_dxid_name_aliasr   r   _class
isinstancer   r)   s       r+   r(   zDXApp.set_idT   s      

5#4YZZtT[[1DJDJdJ/TKLL !%4!%"QRR#' r,   c                 p    | j                   | j                   S d| j                  z   dz   | j                  z   S )z
        :returns: Object ID of associated app
        :rtype: string

        Returns the object ID of the app that the handler is currently
        associated with.
        app-/)r/   r0   r1   r*   s    r+   get_idzDXApp.get_idw   s5     ::!::DJJ&,t{{::r,   c                    i }d|vr,d|vr(t        | j                  j                  ddddd      dD ]6  }||vr%t        | j                  j                  d|d      ||   ||<   ||= 8 dD ]  }||v s||   ||<   ||=  d	|v r|d	   |d
<   |d	= t        j                  j
                  |fi |}| j                  |d          y)a|  
        :param initializeFrom: ID of an existing app object from which to initialize the app
        :type initializeFrom: string
        :param applet: ID of the applet that the app will be created from
        :type applet: string
        :param name: Name of the app (inherits from *initializeFrom* if possible)
        :type name: string
        :param title: Title or brand name of the app (optional)
        :type title: string
        :param summary: A short description of the app (optional)
        :type summary: string
        :param description: An extended description of the app (optional)
        :type description: string
        :param details: Arbitrary JSON to be associated with the app (optional)
        :type details: dict or list
        :param version: Version number
        :type version: string
        :param bill_to: ID of the user or organization who will own the app and be billed for its space usage (optional if an app with this name already exists)
        :type bill_to: string
        :param access: Access specification (optional)
        :type access: dict
        :param resources: Specifies what is to be put into the app's resources container. Must be a string containing a project ID, or a list containing object IDs. (optional)
        :type resources: string or list

        .. note:: It is highly recommended that the higher-level module
           :mod:`dxpy.app_builder` or (preferably) its frontend `dx build --create-app
           <https://documentation.dnanexus.com/user/helpstrings-of-sdk-command-line-utilities#build>`_
           be used instead for app creation.

        Creates an app with the given parameters by using the specified
        applet or app as a base and overriding its attributes. See the
        API documentation for the `/app/new
        <https://documentation.dnanexus.com/developer/api/running-analyses/apps#api-method-app-new>`_
        method for more info.

        Exactly one of *initializeFrom* and *applet* must be provided.

        The app is only available to its developers until
        :meth:`publish()` is called, and is not run until :meth:`run()`
        is called.

        appletinitializeFromz: One of the keyword arguments z and z is required)r   z: Keyword argument )	r;   r:   r   r   r   descriptionbillingr   	resourcesbill_tobillToid)r%   N)r   	__class____name__dxpyapiapp_newr(   )r*   kwargsdx_hashfieldresps        r+   newz	DXApp.new   s   X 6!&6f&DVZVdVdVmVmow  zJ  K  L  L  	EF"t~~G^G^`efgg#E]GENu		 } 	"E!'5M	"
  &y 1GHy!xx262d$r,   c                 <   i }|r||d<   | j                   =t        j                  j                  | j                   fd|i|| _        | j                  S t        j                  j                  d| j
                  z   f| j                  |d|| _        | j                  S )aF  
        :param fields: Hash where the keys are field names that should be returned, and values should be set to True (default is that all fields are returned)
        :type fields: dict
        :returns: Description of the remote app object
        :rtype: dict

        Returns a dict with a description of the app. The result
        includes the key-value pairs as specified in the API
        documentation for the `/app-xxxx/describe
        <https://documentation.dnanexus.com/developer/api/running-analyses/apps#api-method-app-xxxx-yyyy-describe>`_
        method.

        fieldsinput_paramsr5   r&   rN   )r/   rD   rE   app_describe_descr0   r1   )r*   rM   rG   describe_inputs       r+   describezDXApp.describe   s     '-N8$::!..tzzaaZ`aDJ
 zz ..v

/B V$++<JVNTVDJ zzr,   c                    i }dD ]  }||v s||   ||<   ||=  | j                   -t        j                  j                  | j                   fd|i|}yt        j                  j                  d| j                  z   f| j
                  |d|}y)a8  
        :param applet: ID of the applet to replace the app's contents with
        :type applet: string
        :param details: Metadata to store with the app (optional)
        :type details: dict or list
        :param access: Access specification (optional)
        :type access: dict
        :param resources: Specifies what is to be put into the app's resources container. Must be a string containing a project ID, or a list containing object IDs. (optional)
        :type resources: string or list

        Updates the parameters of an existing app. See the API
        documentation for the `/app/update
        <https://documentation.dnanexus.com/developer/api/running-analyses/apps#api-method-app-xxxx-yyyy-update>`_
        method for more info.

        The current user must be a developer of the app.

        )r:   r=   r   r>   r   NrN   r5   rO   )r/   rD   rE   
app_updater0   r1   )r*   rG   updatesrI   rJ   s        r+   updatezDXApp.update   s    & J 	"E!'5M	"
 ::!88&&tzzRR6RD88&&v

': G$++4;G?EGDr,   c                     | j                   .t        j                  j                  | j                   fdd|ii|S t        j                  j                  d| j                  z   f| j
                  d|id|S )z
        :param tags: Tags to add to the app
        :type tags: array

        Adds the specified application name tags (aliases) to this app.

        The current user must be a developer of the app.

        rN   tagsr5   rO   )r/   rD   rE   app_add_tagsr0   r1   r*   rY   rG   s      r+   add_tagszDXApp.add_tags   sv     ::!88(([64.[TZ[[88(($**)< PDKK7=tnPHNP Pr,   c                 (     | j                   |fi |S )zS
        .. deprecated:: 0.72.0
           Use :meth:`add_tags()` instead.
        )r\   r[   s      r+   addTagszDXApp.addTags  s    
 t}}T,V,,r,   c                     | j                   .t        j                  j                  | j                   fdd|ii|S t        j                  j                  d| j                  z   f| j
                  d|id|S )a  
        :param tags: Tags to remove from the app
        :type tags: array

        Removes the specified application name tags (aliases) from this
        app, so that it is no longer addressable by those aliases.

        The current user must be a developer of the app.

        rN   rY   r5   rO   )r/   rD   rE   app_remove_tagsr0   r1   r[   s      r+   remove_tagszDXApp.remove_tags  sv     ::!88++DJJ^fd^^W]^^88++FTZZ,? St{{:@$SKQS Sr,   c                 (     | j                   |fi |S )zV
        .. deprecated:: 0.72.0
           Use :meth:`remove_tags()` instead.
        )ra   r[   s      r+   
removeTagszDXApp.removeTags&  s    
  t///r,   c                     | j                   *t        j                  j                  | j                   fi |S t        j                  j                  d| j                  z   fd| j
                  i|S )zA
        Installs the app in the current user's account.
        r5   r&   )r/   rD   rE   app_installr0   r1   r*   rG   s     r+   installzDXApp.install-  sY     ::!88''

=f==88''(;Y4;;YRXYYr,   c                     | j                   *t        j                  j                  | j                   fi |S t        j                  j                  d| j                  z   fd| j
                  i|S )zE
        Uninstalls the app from the current user's account.
        r5   r&   )r/   rD   rE   app_uninstallr0   r1   rf   s     r+   	uninstallzDXApp.uninstall6  sY     ::!88))$**???88))&4::*=[T[[[TZ[[r,   c                     | j                   *t        j                  j                  | j                   fi |S t        j                  j                  d| j                  z   fd| j
                  i|S )a{  
        :returns: Full specification of the remote app object
        :rtype: dict

        Returns the contents of the app. The result includes the
        key-value pairs as specified in the API documentation for the
        `/app-xxxx/get
        <https://documentation.dnanexus.com/developer/api/running-analyses/apps#api-method-app-xxxx-yyyy-get>`_
        method.
        r5   r&   )r/   rD   rE   app_getr0   r1   rf   s     r+   getz	DXApp.get?  sX     ::!88##DJJ9&9988##FTZZ$7Ut{{UfUUr,   c                     | j                   *t        j                  j                  | j                   fi |S t        j                  j                  d| j                  z   fd| j
                  i|S )z
        Publishes the app, so all users can find it on the platform.

        The current user must be a developer of the app.
        r5   r&   )r/   rD   rE   app_publishr0   r1   rf   s     r+   publishzDXApp.publishO  sY     ::!88''

=f==88''(;Y4;;YRXYYr,   c                     | j                   *t        j                  j                  | j                   fi |S t        j                  j                  d| j                  z   fd| j
                  i|S )zv
        Removes this app object from the platform.

        The current user must be a developer of the app.
        r5   r&   )r/   rD   rE   
app_deleter0   r1   rf   s     r+   deletezDXApp.deleteZ  sY     ::!88&&tzz<V<<88&&v

':X$++XQWXXr,   c                    | j                   8t        t        j                  j                  | j                   fd|i|d         S t        t        j                  j                  d| j
                  z   f| j                  |d|d         S )NrN   rA   r5   rO   )r/   r
   rD   rE   app_runr0   r1   )r*   	run_inputrG   s      r+   	_run_implzDXApp._run_imple  s    ::!))$**W9WPVWX\]^^))&4::*= 4T[[7@4,2448: ; ;r,   c                 .    t        j                  |fi |S N)r	    _get_run_input_fields_for_applet)r*   executable_inputrG   s      r+   _get_run_inputzDXApp._get_run_inputm  s    <<=MXQWXXr,   c                     t         S ry   )_app_required_keysr7   s    r+   _get_required_keyszDXApp._get_required_keysp      !!r,   c                     t         S ry   )_app_optional_keysr7   s    r+   _get_optional_keyszDXApp._get_optional_keyss  r   r,   c                     t         S ry   )_app_describe_output_keysr7   s    r+   _get_describe_output_keyszDXApp._get_describe_output_keysv  s    ((r,   c                     t         S ry   )_app_cleanup_keysr7   s    r+   _get_cleanup_keyszDXApp._get_cleanup_keysy  s      r,   c                 2    t        t        | 
  |g|i |S )z
        Creates a new job that executes the function "main" of this app with
        the given input *app_input*.

        See :meth:`dxpy.bindings.dxapplet.DXExecutable.run` for the available
        args.
        )superr"   run)r*   	app_inputargsrG   rB   s       r+   r   z	DXApp.run|  s!     UD%iA$A&AAr,   )NNNry   )rC   
__module____qualname____doc__r2   r'   r(   r8   rK   rS   rW   r\   r^   ra   rc   rg   rj   rm   rp   rs   rw   r|   r   r   r   r   r   __classcell__)rB   s   @r+   r"   r"   G   s    
 F;
!(F;@%D2G>P -S"0Z\V 	Z	Y;Y"")!
B 
Br,   r"   )r   
__future__r   r   r   r   rD    r   r	   r
   r   
exceptionsr   compatr   r~   r   r   r   r"    r,   r+   <module>r      sU   "> S R  ? ?   J 
 g  L BHl Br,   