
    5i3'                         d Z ddlmZmZmZmZ ddlZddlmZ ddlm	Z
 ddlmZ dd	lmZ dd
Zd Zd Zd ZddZd Zd Zd Zy)a  

These functions provide shorthand functional interfaces for actions such
as getting a :class:`~dxpy.bindings.DXDataObject` handler from an ID or
`link
<https://documentation.dnanexus.com/developer/api/data-object-lifecycle/details-and-links#linking>`_,
or creating a link from a handler. In addition, there are functions for
performing simple actions with an ID or link as input without creating a
full object handler.

    )print_functionunicode_literalsdivisionabsolute_importN   )DXDataObject)__dict__   )DXError)
basestringc                     t        |       r| S t        | t              r| j                         } t	        ||f      sd| iS |rt        j                  | d       d| |diS d|| diS )a6  
    :param object_id: Object ID or the object handler itself
    :type object_id: string or :class:`~dxpy.bindings.DXDataObject`
    :param project_id: A project ID, if creating a cross-project DXLink
    :type project_id: string
    :param field: A field name, if creating a job-based object reference
    :type field: string
    :returns: A dict formatted as a symbolic DNAnexus object reference
    :rtype: dict

    Creates a DXLink to the specified object.

    If `object_id` is already a link, it is returned without modification.

    If `object_id is a `~dxpy.bindings.DXDataObject`, the object ID is
    retrieved via its `get_id()` method.

    If `field` is not `None`, `object_id` is expected to be of class 'job'
    and the link created is a Job Based Object Reference (JBOR), which is
    of the form::

        {'$dnanexus_link': {'job': object_id, 'field': field}}

    If `field` is `None` and `project_id` is not `None`, the link created
    is a project-specific link of the form::

        {'$dnanexus_link': {'project': project_id, 'id': object_id}}
    $dnanexus_linkjob)r   field)projectid)	is_dxlink
isinstancer   get_idanydxpyverify_string_dxid)	object_id
project_idr   s      /home/marpiech/ifpan-abm-pgxpred/analysis/marpiech-gwas-test/venv/lib/python3.12/site-packages/dxpy/bindings/dxdataobject_functions.pydxlinkr   %   su    : )\*$$&	
E"# ),,		51 )e"DEE j	"JKK    c                     t        | t              syd| vry| d   t        t              ryt        t              rt        fddD              S y)z
    :param x: A potential DNAnexus link

    Returns whether *x* appears to be a DNAnexus link (is a dict with
    key ``"$dnanexus_link"``) with a referenced data object.
    Fr   Tc              3   &   K   | ]  }|v  
 y wN ).0keylinks     r   	<genexpr>zis_dxlink.<locals>.<genexpr>]   s     833$;8s   )r   r   )r   dictr   r   )xr$   s    @r   r   r   N   sS     aq D$
#	D$	8-888r   c                     t        |       st        d| z        t        | d   t              r| d   dfS d| d   v r| d   d   | d   j	                  d      fS | d   d   | d   d   fS )a  
    :param link: A DNAnexus link
    :type link: dict
    :returns: (Object ID, Project ID) if the link is to a data object (or :const:`None`
        if no project specified in the link), or (Job ID, Field) if the link is
        a job-based object reference (JBOR).
    :rtype: tuple

    Get the object ID and detail from a link. There are three types of links:

    * Simple link of the form ``{"$dnanexus_link": "file-XXXX"}`` returns
      ``("file-XXXX", None)``.
    * Data object link of the form ``{"$dnanexus_link': {"id": "file-XXXX",
      "project": "project-XXXX"}}`` returns ``("file-XXXX", "project-XXXX")``.
    * Job-based object reference (JBOR) of the form ``{"$dnanexus_link":
      {"job": "job-XXXX", "field": "foo"}}`` returns ``("job-XXXX", "foo")``.
    zInvalid link: %rr   Nr   r   r   r   )r   r   r   r   get)r$   s    r   get_dxlink_idsr*   `   s    $ T?(4/00$'(*5$%t++	&'	'$%d+T2B-C-G-G	-RRR$%e,d3C.DW.MMMr   c                     t        |       rt        |       d   n| }d|j                  dd      d   j                         z   }|t        vrddij                  |      }|t        vrt        d|      t        |   }|S )Nr   DX-r   DXGlobalworkflowDXGlobalWorkflowzInvalid class name: %s)r   r*   split
capitalizeall_bindingsr)   r   )
id_or_linkr   
class_nameclss       r   _guess_link_target_typer6   {   s    1::1Fz*1-JI	Q/2==??J% 2

#j/ 	 %.
;;
z
"CJr   c                 X   	 t        |       }|t        j
                  t        j                  fv r}t        j                  j                  j                  |       r ||       S | j                  d      }| j                  d      }|dk(  r || |dz   d       S  || |dz   | | |dz   d       S |@|t        j                  t        j                  t        j                  t        j                  fv r ||       S  || |	      S # t        $ r }t        dj                  | |            d}~ww xY w)
a  
    :param id_or_link: String containing an object ID or dict containing a DXLink
    :type id_or_link: string or dict
    :param project: String project ID to use as the context if the the object is a data object
    :type project: string
    :rtype: :class:`~dxpy.bindings.DXObject`, :class:`~dxpy.bindings.DXApp`, or :class:`~dxpy.bindings.DXGlobalWorkflow`

    Parses a string or DXLink dict. Creates and returns an object handler for it.

    Example::

        get_handler("file-1234")
    zCould not parse link {}: {}N/r-   r   )name)r:   alias)r   )r6   	Exceptionr   formatr   DXAppr/   utilsresolver	is_hashidfindDXJob
DXAnalysis	DXProjectDXContainer)r3   r   r5   e	slash_posdash_poss         r   get_handlerrJ      s   K%j1 tzz40011 ::((4z?"",I!s+HB
8A:; 788
8A:i @!+IMN!;= =	CDJJQUQaQa#bb ::w//-  K3:::qIJJKs   D   	D)	D$$D)c                 .   t        | t              st        |       rt        |       } |j                  d
i |S g }| D ]?  }t        |      r!t        |d   t              r|d   }n|d   d   }|j                  |       A |j                  dg       rt        |d   D cg c]  }|df c}      nd}|D cg c]  }||d	 }}d|i}d|v r|d   |d<   t        j                  j                  |      }	|	d   D 
cg c]  }
|
d	   	 c}
S c c}w c c}w c c}
w )a  
    :param id_or_link: String containing an object ID or dict containing a DXLink,
                       or a list of object IDs or dicts containing a DXLink.

    Given an object ID, calls :meth:`~dxpy.bindings.DXDataObject.describe` on the object.

    Example::

        describe("file-1234")

    Given a list of object IDs, calls :meth:`~dxpy.api.system_describe_data_objects`.

    Example::

        describe(["file-1234", "workflow-5678"])

    Note: If id_or_link is a list and **kwargs contains a "fields" parameter, these
    fields will be returned in the response for each data object in addition to the
    fields included by default. Additionally, describe options can be provided for
    each data object class in the "classDescribeOptions" kwargs argument. See
    https://documentation.dnanexus.com/developer/api/system-methods#api-method-system-describedataobjects
    for input parameters used with the multiple object describe method.
    r   r   fieldsT)r   describeobjectsclassDescribeOptionsresultsrM   r!   )r   r   r   rJ   rM   appendr)   r&   r   apisystem_describe_data_objects)r3   kwargshandlerlinksr$   r   describe_inputdescribe_links_inputbulk_describe_inputdata_object_descriptionsdescs              r   rM   rM      s;   4 *j)Yz-Bj)w)&)) 	Dd#34jA 01D 01$7DLL	 DJ::hXZC[DVH-=>E5$->?ae 	UZ[Tt H[[(*>?!V+:@AW:X 67#'88#H#HI\#] -Ei-PQTZ QQ ?[ Rs   D5D9Dc                 <    t        |       } |j                  di |S )z
    :param id_or_link: String containing an object ID or dict containing a DXLink

    Given an object ID, calls :meth:`~dxpy.bindings.DXDataObject.get_details` on the object.

    Example::

        get_details("file-1234")
    r!   )rJ   get_detailsr3   rT   rU   s      r   r]   r]      s$     *%G7(((r   c                 <    t        |       } |j                  di |S )z
    :param id_or_link: String containing an object ID or dict containing a DXLink

    Given an object ID, calls :meth:`~dxpy.bindings.DXDataObject.remove` on the object.

    Example::

        remove("file-1234")
    r!   )rJ   remover^   s      r   r`   r`      s"     *%G7>>#F##r   )NNr    )__doc__
__future__r   r   r   r   r    r   r	   r2   
exceptionsr   compatr   r   r   r*   r6   rJ   rM   r]   r`   r!   r   r   <module>rf      sP   "
 S R   &   'LR$N6&0P5Rn)$r   