
    5ie                     
   d Z ddlmZmZmZmZ ddlZddlZddlZddl	Z
ddlmZmZmZmZmZmZmZmZmZmZ ddlmZ d Z G d d	e      Z G d
 de      ZddlmZmZmZ ddl m!Z!mZmZ ddl"m"Z" ddl#m#Z# ddl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5m6Z6 ddl7m8Z8 ddl9m:Z:m;Z; ddl<m=Z= ddl>m?Z? ddl@mAZAmBZB ddlCmDZDmEZE ddlFmGZGmHZHmIZImJZJmKZKmLZLmMZM ddlNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z] y)z
The :class:`DXObject` class is the abstract base class for all remote
object handlers, and its subclass :class:`DXDataObject` is the abstract
base class for all remote data object handlers.
    )print_functionunicode_literalsdivisionabsolute_importN   )
DXError
DXAPIErrorDXFileErrorDXSearchErrorDXAppletErrorDXJobFailureErrorAppErrorAppInternalErrorAppInsufficientResourceError
DXCLIError)
basestringc                    t        |t              r|g}t        |t              rt        |      dk(  rt	        d      t        | t              r+t        j                  ddj                  |      z   dz   |       sbt        |      dk(  r|d   }n=t        |      dk(  rdj                  |      }nd	j                  |d
d       dz   |d   z   }t	        d|d|       y
)a  
    :param dxid: Value to verify as a DNAnexus ID of class *expected_class*
    :param expected_classes: Single string or list of strings of allowed classes of the ID, e.g. "file" or ["project", "container"]
    :type expected_classes: string or list of strings
    :raises: :exc:`~dxpy.exceptions.DXError` if *dxid* is not a string or is not a valid DNAnexus ID of the expected class
    r   zJverify_string_dxid: expected_classes should be a string or list of stringsz^(|z)-[0-9a-zA-Z]{24}$   r   z or z, Nz, or zInvalid ID of class z: )
isinstancer   listlenr   rematchjoin)dxidexpected_classesstr_expected_classess      x/home/marpiech/ifpan-abm-pgxpred/analysis/marpiech-gwas-test/venv/lib/python3.12/site-packages/dxpy/bindings/__init__.pyverify_string_dxidr!       s     "J/,-&-5E1F!1KbcctZ(HHTCHH%5669MMtT A%#3A#6 !"a'#);;/?#@ #'99-=cr-B#Cg#MP`acPd#d 6JDQRR U    c                   D    e Zd ZdZddZddZd Zd Zd Zd Z	d	 Z
d
 Zy)DXObjectz3Abstract base class for all remote object handlers.Nc                 0    d\  | _         | _        i | _        y )NNN)_dxid_proj_descselfr   projects      r    __init__zDXObject.__init__:   s     ",
DJ
r"   c           
      n   | j                   | j                   nd}| j                  | j                  nd}|r| j                  dvrd}nd}n| j                  dvrd}nd}|j                  | j                  | j
                  j                  ||t        |       | j                  j                  d      	      }|S )
Nzno ID storedzno project ID stored)	containerr,   appglobalworkflowz1<dxpy.{classname}: {name} ({dxid} ({dxproj_id}))>z#<dxpy.{classname}: {name} ({dxid})>zD<{module}.{classname} object at 0x{mem_loc:x}: {dxid} ({dxproj_id})>z6<{module}.{classname} object at 0x{mem_loc:x}: {dxid}>name)module	classnamer   	dxproj_idmem_locr2   )
r'   r(   _classformat
__module__	__class____name__idr)   get)r+   use_namer   r5   descs        r    _reprzDXObject._reprA   s    !ZZ3tzz"&**"8DJJ>T	{{"SSJ<{{"SS]O{{$//%)^^%<%< $'0#%d8 $

v 6  8 r"   c                 &    | j                  d      S )NT)r>   r@   r+   s    r    __str__zDXObject.__str__X   s    zz4z((r"   c                 "    | j                         S NrB   rC   s    r    __repr__zDXObject.__repr__[   s    zz|r"   c                     |dk(  rt        |      | j                  s| j                          	 | j                  |   S #  t               xY w)N__setstate__)AttributeErrorr)   describe)r+   attrs     r    __getattr__zDXObject.__getattr__^   sM    >! !&&zz MMO	#::d##	# ""s	   = A	c                     t               )zU
        Avoid infinite recursion in __getattr__ if describe is not defined.
        )NotImplementedError)r+   argskwargss      r    rK   zDXObject.describel   s     "##r"   c                 B    |t        || j                         || _        y)z
        :param dxid: New ID to be associated with the handler
        :type dxid: string

        Discards the currently stored ID and associates the handler with *dxid*
        N)r!   r7   r'   r+   r   s     r    set_idzDXObject.set_idr   s     tT[[1
r"   c                     | j                   S )z
        :returns: ID of the associated object
        :rtype: string

        Returns the ID that the handler is currently associated with.

        )r'   rC   s    r    get_idzDXObject.get_id~   s     zzr"   r&   )F)r;   r9   __qualname____doc__r-   r@   rD   rG   rM   rK   rT   rV    r"   r    r$   r$   7   s-    =.)#$
	r"   r$   c                       e Zd ZdZddZed        Zd Zd Zd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 dZd Zd!dZd"dZy)#DXDataObjecta  Abstract base class for all remote data object handlers.

    .. note:: The attribute values below are current as of the last time
              :meth:`~dxpy.bindings.DXDataObject.describe` was run.
              (Access to any of the below attributes causes
              :meth:`~dxpy.bindings.DXDataObject.describe` to be called
              if it has never been called before.)

    .. py:attribute:: name

       String giving the name of the object

    .. py:attribute:: folder

       String giving the full path to the folder containing the object

    .. py:attribute:: types

       List of strings indicating the types associated with the object

    .. py:attribute:: state

       A string containing one of the values "open", "closing", or "closed"

    .. py:attribute:: hidden

       Boolean indicating whether the object is hidden or not

    .. py:attribute:: links

       List of strings indicating object IDs that are pointed to by the
       object

    .. py:attribute:: sponsored

       Boolean indicating whether the object is sponsored by DNAnexus

    .. py:attribute:: tags

       List of strings indicating the tags that are assocated with the
       object

    .. py:attribute:: created

       Timestamp at which the object was created, in milliseconds since
       January 1, 1970 at midnight (UTC).

    .. py:attribute:: modified

       Timestamp at which the object was last modified, in milliseconds
       since January 1, 1970 at midnight (UTC).

    .. py:attribute:: createdBy

       dict containing the following keys and values:

       * user: the string ID of the user who created the object or
         launched the job that created it
       * job (optional): the string ID of the job that created the
         object, if a job created the object
       * executable (optional): the string ID of the app or applet that
         the job was running, if a job created the object

    Nc                     t        | d      st        d      t        j                  |        | j	                  ||       y )Nr7   zLDXDataObject is an abstract class; a subclass should be initialized instead.)hasattrrO   r$   r-   set_idsr*   s      r    r-   zDXDataObject.__init__   s<    tX&%^` ` 	$T7#r"   c                     h d}| D ci c]  }||v s| |   || |    }}| D ci c]  }||vs|| |    }}d|vrt         j                  |d<   ||fS c c}w c c}w )N>	   r2   tagstypesfolderhiddendetailsparentsr,   
propertiesr,   )dxpyWORKSPACE_ID)rQ   common_creation_paramspdx_hashremaining_kwargss        r    _get_creation_paramsz!DXDataObject._get_creation_params   s    !})/iA18N3NSYZ[S\Sh1fQi<ii28\QAE[<[AvayL\\G#!%!2!2GI((( j\s   	AAA	AAc                     t        | d      st        d      | j                  |      \  }} | j                  |fi | y)a  
        :param project: Project ID in which to create the new remote object
        :type project: string
        :param name: Name for the object
        :type name: string
        :param tags: Tags to add for the object
        :type tags: list of strings
        :param types: Types to add to the object
        :type types: list of strings
        :param hidden: Whether the object is to be hidden
        :type hidden: boolean
        :param properties: Properties given as key-value pairs of strings
        :type properties: dict
        :param details: Details to set for the object
        :type details: dict or list
        :param folder: Full path to the destination folder
        :type folder: string
        :param parents: If True, recursively create all parent folders if they are missing
        :type parents: boolean

        :rtype: :class:`DXDataObject`

        Creates a data object with the given fields. Only *project* is
        required, and only if no default project or workspace is set;
        the remaining arguments are optional and have default behavior
        as specified in the API documentation for the ``/new`` method of
        each data object class.

        r7   zKDXDataObject is an abstract class; a subclass shouldbe initialized instead.N)r]   rO   rm   _new)r+   rQ   rk   rl   s       r    newzDXDataObject.new   sL    < tX&%./ / %)$=$=f$E!!		'.-.r"   c                 &    | j                  |       y)aS  
        :param dxid: Object ID or a DNAnexus link (a dict with key "$dnanexus_link"); if a project ID is provided in the DNAnexus link, it will also be used to set the project ID
        :type dxid: string or dict

        Equivalent to calling
        :meth:`~dxpy.bindings.DXDataObject.set_ids` with the same
        arguments.
        N)r^   rS   s     r    rT   zDXDataObject.set_id  s     	Tr"   c                     t        |      rt        |      \  }}||}|t        || j                         || _        |t
        j                  | _        y|t        |ddg       || _        yy)a7  
        :param dxid: Object ID or a DNAnexus link (a dict with key "$dnanexus_link"); if a project ID is provided in the DNAnexus link, it will be used as *project* unless *project* has been explictly provided
        :type dxid: string or dict
        :param project: Project ID
        :type project: string

        Discards the currently stored ID and associates the handler with
        *dxid*. Associates the handler with the copy of the object in
        *project* (if no project is explicitly specified, the default
        data container is used).

        Nr,   r/   )	is_dxlinkget_dxlink_idsr!   r7   r'   rg   rh   r(   )r+   r   r,   project_from_links       r    r^   zDXDataObject.set_ids  ss     T?&4T&:#D#+tT[[1
?**DJ wK(@A DJ !r"   c                     | j                   S )z
        :returns: Project ID of associated object
        :rtype: string

        Returns the project ID, if any, that the handler is currently
        associated with.

        )r(   rC   s    r    get_proj_idzDXDataObject.get_proj_id-  s     zzr"   c                    | j                   :t        dj                  | j                  j                  | j
                              |s|r||t        d      |s|rt        ||      }ni }|||d<   ||D ci c]  }|d c}|d<   | j                  | j                  |d<    | j                  | j                   |fi || _
        | j                  S c c}w )	a  
        :param fields: set of fields to include in the output, for
            example ``{'name', 'modified'}``. The field ``id`` is always
            implicitly included. If ``fields`` is specified, the default
            fields are not included (that is, only the fields specified
            here, and ``id``, are included) unless ``default_fields`` is
            additionally set to True.
        :type fields: set or sequence of str
        :param default_fields: if True, include the default fields in
            addition to fields requested in ``fields``, if any; if
            False, only the fields specified in ``fields``, if any, are
            returned (defaults to False if ``fields`` is specified, True
            otherwise)
        :type default_fields: bool
        :param incl_properties: if true, includes the properties of the
            object in the output (deprecated; use
            ``fields={'properties'}, default_fields=True`` instead)
        :type incl_properties: bool
        :param incl_details: if true, includes the details of the object
            in the output (deprecated; use ``fields={'details'},
            default_fields=True`` instead)
        :type incl_details: bool
        :returns: Description of the remote object
        :rtype: dict

        Return a dict with a description of the remote data object.

        The result includes the key-value pairs as specified in the API
        documentation for the ``/describe`` method of each data object
        class. The API defines some default set of fields that will be
        included (at a minimum, "id", "class", etc. should be available,
        and there may be additional fields that vary based on the
        class); the set of fields may be customized using ``fields`` and
        ``default_fields``.

        Any project-specific metadata fields (name, properties, and
        tags) are obtained from the copy of the object in the project
        associated with the handler, if possible.

        zZThis {handler} handler has not been initialized with a {_class} ID and cannot be described)handlerr7   zQCannot specify properties or details in conjunction with fields or default_fields)rf   rd   defaultFieldsTfieldsr,   )r'   r   r8   r:   r;   r7   
ValueErrordictr(   	_describer)   )r+   incl_propertiesincl_detailsr{   default_fieldsrQ   describe_input
field_names           r    rK   zDXDataObject.describe9  s    T ::v}}//{{ ~ $  
 |&2DHbpqql!_lSNN)2@/!OU+VJ,<+Vx(::!(,

N9%#T^^DJJI&I
zz ,Ws   ;
Cc                 D     | j                   | j                  d|ifi | y)aI  
        :param types: Types to add to the object
        :type types: list of strings
        :raises: :class:`~dxpy.exceptions.DXAPIError` if the object is not in the "open" state

        Adds each of the specified types to the remote object. Takes no
        action for types that are already listed for the object.

        ra   N)
_add_typesr'   r+   ra   rQ   s      r    	add_typeszDXDataObject.add_types|  s"     	

We$4??r"   c                 D     | j                   | j                  d|ifi | y)aQ  
        :param types: Types to remove from the object
        :type types: list of strings
        :raises: :class:`~dxpy.exceptions.DXAPIError` if the object is not in the "open" state

        Removes each the specified types from the remote object. Takes
        no action for types that the object does not currently have.

        ra   N)_remove_typesr'   r   s      r    remove_typeszDXDataObject.remove_types  s$     	4::'7B6Br"   c                 <     | j                   | j                  fi |S )zb
        Returns the contents of the details of the object.

        :rtype: list or dict
        )_get_detailsr'   r+   rQ   s     r    get_detailszDXDataObject.get_details  s      !t  6v66r"   c                 >     | j                   | j                  |fi |S )a  
        :param details: Details to set for the object
        :type details: dict or list
        :raises: :class:`~dxpy.exceptions.DXAPIError` if the object is not in the "open" state

        Sets the details for the remote object with the specified value.
        If the input contains the string ``"$dnanexus_link"`` as a key
        in a hash, it must be the only key in the hash, and its value
        must be a valid ID of an existing object.

        )_set_detailsr'   )r+   rd   rQ   s      r    set_detailszDXDataObject.set_details  s"     !t  W???r"   c                 B     | j                   | j                  ddifi |S )z
        :raises: :class:`~dxpy.exceptions.DXAPIError` if the object is not in the "open" state

        Hides the remote object.

        rc   T_set_visibilityr'   r   s     r    hidezDXDataObject.hide  s'     $t##DJJ40@KFKKr"   c                 B     | j                   | j                  ddifi |S )z
        :raises: :class:`~dxpy.exceptions.DXAPIError` if the object is not in the "open" state

        Makes the remote object visible.

        rc   Fr   r   s     r    unhidezDXDataObject.unhide  s'     $t##DJJ50ALVLLr"   c                 X     | j                   | j                  | j                  |dfi |S )z
        :param name: New name for the object
        :type name: string

        Renames the remote object.

        The name is changed on the copy of the object in the project
        associated with the handler.

        )r,   r2   )_renamer'   r(   )r+   r2   rQ   s      r    renamezDXDataObject.rename  s6     t||DJJDJJ15)7 B:@B 	Br"   c                 0     | j                   dddi|d   S )a   
        :returns: Properties given as key-value pairs of strings
        :rtype: dict

        Returns the properties of the object.

        The properties are read from the copy of the object in the
        project associated with the handler.

        r   Trf   rY   rK   r   s     r    get_propertieszDXDataObject.get_properties  s"     t}}<T<V<\JJr"   c                 Z     | j                   | j                  | j                  |dfi | y)a  
        :param properties: Property names and values given as key-value pairs of strings
        :type properties: dict

        Given key-value pairs in *properties* for property names and
        values, the properties are set on the object for the given
        property names. Any property with a value of :const:`None`
        indicates the property will be deleted.

        .. note:: Any existing properties not mentioned in *properties*
           are not modified by this method.

        The properties are written to the copy of the object in the
        project associated with the handler.

        The following example sets the properties for "name" and
        "project" for a remote file::

            dxfile.set_properties({"name": "George", "project": "cancer"})

        Subsequently, the following would delete the property "project"::

            dxfile.set_properties({"project": None})

        )r,   rf   N)_set_propertiesr'   r(   )r+   rf   rQ   s      r    set_propertieszDXDataObject.set_properties  s1    6 	TZZTZZ8B*D 	'%	'r"   c                 Z     | j                   | j                  | j                  |dfi | y)aO  
        :param tags: Tags to add to the object
        :type tags: list of strings

        Adds each of the specified tags to the remote object. Takes no
        action for tags that are already listed for the object.

        The tags are added to the copy of the object in the project
        associated with the handler.

        r,   r`   N)	_add_tagsr'   r(   r+   r`   rQ   s      r    add_tagszDXDataObject.add_tags  s+     	tzztzz4#H 	!	!r"   c                 Z     | j                   | j                  | j                  |dfi | y)a^  
        :param tags: Tags to remove from the object
        :type tags: list of strings

        Removes each of the specified tags from the remote object. Takes
        no action for tags that the object does not currently have.

        The tags are removed from the copy of the object in the project
        associated with the handler.

        r   N)_remove_tagsr'   r(   r   s      r    remove_tagszDXDataObject.remove_tags  s-     	$**$**d&K 	$"	$r"   c                 <     | j                   | j                  fi |S )zv
        Closes the object for further modification to its types,
        details, visibility, and contents.

        )_closer'   r   s     r    closezDXDataObject.close  s     t{{4::000r"   c                 <     | j                   | j                  fi |S )z
        :rtype: dict

        Returns a dict of project IDs of the projects that contain this
        object and the permission level of the requesting user.

        )_list_projectsr'   r   s     r    list_projectszDXDataObject.list_projects&  s      #t""4::888r"   c                     | j                   t        d      t        j                  j                  | j                   d| j
                  gifi | d| _        d| _         i | _        y)z
        :raises: :exc:`~dxpy.exceptions.DXError` if no project is associated with the object

        Permanently removes the associated remote object from the
        associated project.
        NzKRemove called when a project ID was not associated with this object handlerobjects)r(   r   rg   apiproject_remove_objectsr'   r)   r   s     r    removezDXDataObject.remove1  s^     ::ghh''

Y4M 	2*0	2 


r"   c                     | j                   t        d      t        j                  j                  | j                   | j
                  g|dfi | y)z
        :param folder: Folder route to which to move the object
        :type folder: string
        :raises: :exc:`~dxpy.exceptions.DXError` if no project is associated with the object

        Moves the associated remote object to *folder*.

        NzIMove called when a project ID was not associated with this object handler)r   destination)r(   r   rg   r   project_mover'   )r+   rb   rQ   s      r    movezDXDataObject.moveD  sK     ::effdjjtzzl:@+B 	( &	(r"   c                    | j                   t        d      t        j                  j                  | j                   | j
                  g||dfi | t        j                  |       }|j                  |j                         |       |S )a  
        :param project: Destination project ID
        :type project: string
        :param folder: Folder route to which to move the object
        :type folder: string
        :raises: :exc:`~dxpy.exceptions.DXError` if no project is associated with the object
        :returns: An object handler for the new cloned object
        :rtype: :class:`DXDataObject`

        Clones the associated remote object to *folder* in *project* and
        returns an object handler for the new object in the destination
        project.

        zJClone called when a project ID was not associated with this object handler)r   r,   r   )	r(   r   rg   r   project_cloner'   copyr^   rV   )r+   r,   rb   rQ   cloned_copys        r    clonezDXDataObject.cloneV  s~      ::fggtzz,0JJ<+2/5 7	) "(		)
 iioK..0':r"   c                 2     | j                   dddhi|d   S )a  
        :returns: State of the remote object
        :rtype: string

        Queries the API server for the object's state.  Returns a string
        in {"open", "closing", "closed"}.

        Note that this function is shorthand for:

            dxclass.describe()["state"]

        r{   staterY   r   r   s     r    
_get_statezDXDataObject._get_stater  s$     t}}8WI88AAr"   c                     d}d}	  | j                   d	i |}|dk(  ry |dk7  rt        d|z         ||k\  s|dk  rt        d      t        dd|z        }t        j                  |       |dz  }||z  }o)
Nr   closedclosingzUnexpected state: z<Reached timeout while waiting for the remote object to close   r   r   rY   )r   r   mintimesleep)r+   timeoutrQ   elapsedir   waits          r    _wait_on_closezDXDataObject._wait_on_close  s    #DOO-f-E 	!2U:;;'!Wq[\]]tQT?DJJtFAtOG r"   c                   
 d}d}ddddi}| j                   | j                   |d<   	  | j                  | j                  |fi |}|d   |d   c}
|dk(  s
sy t        
fd	
D               }|ry ||k\  s|dk  r(t	        d
j                  | j                                     t        dd|z        }	t        j                  |	       |dz  }||	z  })Nr   r{   T)partsr   r,   r   r   r   c              3   N   K   | ]  }|   j                  d d      dk7    yw)r   completeN)r=   ).0keyr   s     r    	<genexpr>z:DXDataObject._wait_until_parts_uploaded.<locals>.<genexpr>  s&     %i\_eCjnnWj&IZ&W%is   "%zGReached timeout while waiting for parts of the file ({}) to be uploadedr   r   r   )
r(   r~   r'   anyr   r8   rV   r   r   r   )r+   r   rQ   r   r   r   rK   r   is_uploadedr   r   s             @r    _wait_until_parts_uploadedz'DXDataObject._wait_until_parts_uploaded  s    "dT$BC::!(,

N9%%t~~djj.KFKH#G,hw.?LE5 "%%ich%i"ii'!Wq[gnnosozozo|}~~tQT?DJJtFAtOG! r"   r&   rF   )FFNN)/)iQ )   )r;   r9   rW   rX   r-   staticmethodrm   rp   rT   r^   rw   rK   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rY   r"   r    r[   r[      s    ?B$ 	) 	)$/L	!:
AF@C7@LMBK'>! $ 1	9&($8B $r"   r[   r   )DXFileDXFILE_HTTP_THREADSDEFAULT_BUFFER_SIZE)
DXDatabaser   r   )download_all_inputs)mount_all_inputs)open_dxfile
new_dxfiledownload_dxfileupload_local_fileupload_stringlist_subfoldersdownload_folder)download_dxdatabasefile)DXRecordnew_dxrecord)DXContainer	DXProject)DXJob	new_dxjob)
DXAnalysis)DXExecutableDXApplet)DXApp)DXGlobalWorkflow)
DXWorkflownew_dxworkflow)	user_infowhoami)dxlinkrs   rt   get_handlerrK   r   r   )find_data_objectsfind_executions	find_jobsfind_analysesfind_projects	find_appsfind_global_workflowsfind_one_data_objectfind_one_projectfind_one_appresolve_data_objects	find_orgsorg_find_membersorg_find_projectsorg_find_apps)^rX   
__future__r   r   r   r   r   r   r   dxpy.apirg   
exceptionsr   r	   r
   r   r   r   r   r   r   r   compatr   r!   objectr$   r[   dxfiler   r   r   
dxdatabaser   r   r   dxfile_functionsr   r   r   r   r   r   r   dxdatabase_functionsr   dxrecordr   r   	dxprojectr   r   dxjobr   r   
dxanalysisr   dxappletr   r   dxappr   dxglobalworkflowr   
dxworkflowr   r   authr   r   dxdataobject_functionsr   rs   rt   r   rK   r   r   searchr   r   r   r   r   r   r   r   r   r  r  r  r  r  r  rY   r"   r    <module>r     s   " S R   s s s S.Pv Pda8 aF E D L L 4 . K  K  K 9 , - # " ,  . 2 # q q qI I I I Ir"   