
    5i*                     ^    d Z ddlmZmZmZmZ ddlZddlZddlm	Z	 ddl
mZ  G d de	      Zy)z
DXAnalysis Handler
++++++++++++++++++

Analyses are DNAnexus entities that capture an instantiation of a
running workflow. They can be created from
:func:`dxpy.bindings.dxworkflow.DXWorkflow.run` or from an
existing analysis ID.

    )print_functionunicode_literalsdivisionabsolute_importN)DXObject)DXJobFailureErrorc                   R    e Zd ZdZdZddZddZd Zd Zd Z	dd	Z
d
 ZddZd Zy)
DXAnalysisz)
    Remote analysis object handler.
    analysisNc                 b    d | _         t        j                  | |       | j                  |       y )N)dxid)_test_harness_resultr   __init__set_id)selfr   s     z/home/marpiech/ifpan-abm-pgxpred/analysis/marpiech-gwas-test/venv/lib/python3.12/site-packages/dxpy/bindings/dxanalysis.pyr   zDXAnalysis.__init__.   s&    $(!$T*D    c                     i }|||d<   t        j                  j                  | j                  |fi || _        | j                  S )az  
        :param fields: dict where the keys are field names that should
            be returned, and values should be set to True (by default,
            all fields are returned)
        :type fields: dict
        :returns: Description of the analysis
        :rtype: dict

        Returns a hash with key-value pairs containing information
        about the analysis

        fields)dxpyapianalysis_describe_dxid_desc)r   r   kwargsdescribe_inputs       r   describezDXAnalysis.describe3   sD     '-N8$XX//

NUfU
zzr   c                 ^    t        j                  j                  | j                  d|ifi | y)z
        :param tags: Tags to add to the analysis
        :type tags: list of strings

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

        tagsN)r   r   analysis_add_tagsr   r   r   r   s      r   add_tagszDXAnalysis.add_tagsF   s%     	""4::~HHr   c                 ^    t        j                  j                  | j                  d|ifi | y)z
        :param tags: Tags to remove from the analysis
        :type tags: list of strings

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

        r   N)r   r   analysis_remove_tagsr   r!   s      r   remove_tagszDXAnalysis.remove_tagsR   s%     	%%djj64.KFKr   c                 ^    t        j                  j                  | j                  d|i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 analysis 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.

        
propertiesN)r   r   analysis_set_propertiesr   )r   r'   r   s      r   set_propertieszDXAnalysis.set_properties^   s'     	((lJ5OZSYZr   c                    d}	  | j                   di |}|dk(  ry|dv rl | j                  di |} dj                  di |}|j                  d      dk7  r)|d   d   |d   k7  r|dj                  |d   d   	      z  }t	        |      |d
k(  rt	        d      ||k\  s|dk  rt	        d      t        j                  |       ||z  })a  
        :param interval: Number of seconds between queries to the analysis's state
        :type interval: integer
        :param timeout: Maximum amount of time to wait, in seconds, until the analysis is done (or at least partially failed)
        :type timeout: integer
        :raises: :exc:`~dxpy.exceptions.DXError` if the timeout is reached before the analysis has finished running, or :exc:`~dxpy.exceptions.DXJobFailureError` if some job in the analysis has failed

        Waits until the analysis has finished running.
        r   done)failedpartially_failedz@Analysis has failed because of {failureReason}: {failureMessage}failureFromNidz (failure from {id}))r/   
terminatedzAnalysis was terminated.z8Reached timeout while waiting for the analysis to finish )
_get_stater   formatgetr   timesleep)r   intervaltimeoutr   elapsedstatedescerr_msgs           r   wait_on_donezDXAnalysis.wait_on_doneo   s     #DOO-f-E66$t}}.v.c\cckfjk88M*d2tM7J47PTXY]T^7^5<<]@STX@Y<ZZG'00$'(BCC'!Wq['(bccJJx xG# r   c                 X    t        j                  j                  | j                  fi | y)z5
        Terminates the associated analysis.
        N)r   r   analysis_terminater   r   r   s     r   	terminatezDXAnalysis.terminate   s     	##DJJ9&9r   c                 P    d| j                   |di}|||d   d<   |||d   d<   |S )a9  
        :param field: Output field name of this analysis
        :type field: string
        :param index: If the referenced field is an array, optionally specify an index (starting from 0) to indicate a particular member of the array
        :type index: int
        :param metadata: If the referenced field is of a data object class, a string indicating the metadata that should be read, e.g. "name", "properties.propkey", "details.refgenome"
        :type metadata: string

        Returns a dict containing a valid reference to an output of this analysis.
        z$dnanexus_link)r   fieldindexmetadata)r   )r   rC   rD   rE   links        r   get_output_refzDXAnalysis.get_output_ref   sH     !tzzE"JK.3D!"7+19D!":.r   c                 D     | j                   ddt        d      i|d   S )z
        :returns: State of the remote object
        :rtype: string

        Queries the API server for the analysis's state.

        Note that this function is shorthand for:

            dxanalysis.describe(**kwargs)["state"]

        r   T)r:   r:   r1   )r   dictr@   s     r   r2   zDXAnalysis._get_state   s'     t}}?Dt$4??HHr   )N)   i:	 )NN)__name__
__module____qualname____doc___classr   r   r"   r%   r)   r=   rA   rG   r2   r1   r   r   r
   r
   '   s?     F
&
I
L[" >:&Ir   r
   )rN   
__future__r   r   r   r   r5   r   dxpy.bindingsr   dxpy.exceptionsr   r
   r1   r   r   <module>rS      s/   "	 S R   & -MI MIr   