How to use the dxpy.WORKSPACE_ID function in dxpy

To help you get started, we’ve selected a few dxpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dnanexus / dx-toolkit / src / python / dxpy / scripts / dx_build_app.py View on Github external
# Create a temp project
            try:
                working_project = dxpy.api.project_new({"name": "Temporary build project for dx-build-app"})["id"]
            except:
                err_exit()
            region = dxpy.api.project_describe(working_project,
                                               input_params={"fields": {"region": True}})["region"]
            projects_by_region[region] = working_project
            logger.debug("Created temporary project %s to build in" % (working_project,))

        using_temp_project = True
    elif mode == "app" and not dry_run:
        # If we are not using temporary project(s) to build the executable,
        # then we should have a project context somewhere.
        try:
            project = app_json.get("project", dxpy.WORKSPACE_ID)
            region = dxpy.api.project_describe(project,
                                               input_params={"fields": {"region": True}})["region"]
        except Exception:
            err_exit()
        projects_by_region = {region: project}

    try:
        if mode == "applet" and working_project is None and dxpy.WORKSPACE_ID is None:
            parser.error("Can't create an applet without specifying a destination project; please use the -d/--destination flag to explicitly specify a project")

        if "buildOptions" in app_json:
            if app_json["buildOptions"].get("dx_toolkit_autodep") is False:
                dx_toolkit_autodep = False

        # Perform check for existence of applet with same name in
        # destination for case in which neither "-f" nor "-a" is
github dnanexus / dx-toolkit / src / python / dxpy / scripts / dx_build_app.py View on Github external
projects_by_region = {region: dest_project}

            for result in dxpy.find_data_objects(classname="applet", name=dest_name, folder=dest_folder,
                                                 project=dest_project, recurse=False):
                dest_path = dest_folder + dest_name
                msg = "An applet already exists at {} (id {}) and neither".format(dest_path, result["id"])
                msg += " -f/--overwrite nor -a/--archive were given."
                raise dxpy.app_builder.AppBuilderException(msg)

        if dry_run:
            # Set a dummy "projects_by_region" so that we can exercise the dry
            # run flows for uploading resources bundles and applets below.
            projects_by_region = {"dummy-cloud:dummy-region": "project-dummy"}

        if mode == "applet" and projects_by_region is None:
            project = app_json.get("project", False) or dxpy.WORKSPACE_ID

            try:
                region = dxpy.api.project_describe(project,
                                                   input_params={"fields": {"region": True}})["region"]
            except Exception:
                err_exit()
            projects_by_region = {region: project}

        if projects_by_region is None:
            raise AssertionError("'projects_by_region' should not be None at this point")

        resources_bundles_by_region = {}
        for region, project in projects_by_region.items():
            resources_bundles_by_region[region] = dxpy.app_builder.upload_resources(
                src_dir,
                project=project,
github dnanexus / dx-toolkit / src / python / dxpy / scripts / dx_build_app.py View on Github external
dx_toolkit_autodep = False

        # Perform check for existence of applet with same name in
        # destination for case in which neither "-f" nor "-a" is
        # given BEFORE uploading resources.
        if mode == "applet" and not overwrite and not archive:
            try:
                dest_name = override_applet_name or app_json.get('name') or os.path.basename(os.path.abspath(src_dir))
            except:
                raise dxpy.app_builder.AppBuilderException("Could not determine applet name from specification + "
                                                           "(dxapp.json) or from working directory (%r)" % (src_dir,))
            dest_folder = override_folder or app_json.get('folder') or '/'
            if not dest_folder.endswith('/'):
                dest_folder = dest_folder + '/'

            dest_project = working_project if working_project else dxpy.WORKSPACE_ID
            try:
                region = dxpy.api.project_describe(dest_project,
                                                   input_params={"fields": {"region": True}})["region"]
            except Exception:
                err_exit()
            projects_by_region = {region: dest_project}

            for result in dxpy.find_data_objects(classname="applet", name=dest_name, folder=dest_folder,
                                                 project=dest_project, recurse=False):
                dest_path = dest_folder + dest_name
                msg = "An applet already exists at {} (id {}) and neither".format(dest_path, result["id"])
                msg += " -f/--overwrite nor -a/--archive were given."
                raise dxpy.app_builder.AppBuilderException(msg)

        if dry_run:
            # Set a dummy "projects_by_region" so that we can exercise the dry
github dnanexus / dx-toolkit / src / python / dxpy / bindings / __init__.py View on Github external
*dxid*. Associates the handler with the copy of the object in
        *project* (if no project is explicitly specified, the default
        data container is used).

        '''
        if is_dxlink(dxid):
            dxid, project_from_link = get_dxlink_ids(dxid)
            if project is None:
                project = project_from_link

        if dxid is not None:
            verify_string_dxid(dxid, self._class)
        self._dxid = dxid

        if project is None:
            self._proj = dxpy.WORKSPACE_ID
        elif project is not None:
            verify_string_dxid(project, ['project', 'container'])
            self._proj = project
github dnanexus / dx-toolkit / src / python / dxpy / bindings / dxapp_container_functions.py View on Github external
if 'project' in kwargs:
        raise DXError('Unexpected kwarg: "project"')
    if dxpy.JOB_ID is None:
        raise DXError('Not called by a job')
    if 'DX_PROJECT_CACHE_ID' not in os.environ:
        raise DXError('Project cache ID could not be found in the environment variable DX_PROJECT_CACHE_ID')

    kwargs['project'] = os.environ.get('DX_PROJECT_CACHE_ID')
    kwargs['return_handler'] = True

    cached_object = find_one_data_object(**kwargs)

    if cached_object is None:
        return None

    return cached_object.clone(dxpy.WORKSPACE_ID)
github ENCODE-DCC / chip-seq-pipeline / dnanexus / histone_workflow.py View on Github external
%(prog)s --idr

    Build and run a workflow, specifying fastq's for two replicates and matched controls, including naive peaks and IDR.
    %(prog)s --rep1 r1.fastq.gz --rep2 r2.fastq.gz --ctl1 c1.fastq.gz --ctl2 c2.fastq.gz --idr --yes

    Build and run a workflow, skipping mapping and starting from tagAligns from paired-end data, reporting both naive and IDR-processed peaks.
    %(prog)s --rep1 f1.tagAlign.gz --rep2 r2.tagAlign.gz --ctl1 c1.tagAlign.gz --ctl2 c2.tagAlign.gz --rep1_ended PE --rep2_ended PE --idr --yes

'''

WF_NAME = 'histone_chip_seq'
WF_TITLE = 'Histone ChIP-seq'
WF_DESCRIPTION = 'ENCODE Histone ChIP-Seq Pipeline'

DEFAULT_APPLET_PROJECT = dxpy.WORKSPACE_ID
DEFAULT_OUTPUT_PROJECT = dxpy.WORKSPACE_ID
DEFAULT_OUTPUT_FOLDER = '/analysis_run'

MAPPING_APPLET_NAME = 'encode_map'
FILTER_QC_APPLET_NAME = 'filter_qc'
XCOR_APPLET_NAME = 'xcor'
XCOR_ONLY_APPLET_NAME = 'xcor_only'
SPP_APPLET_NAME = 'spp'
POOL_APPLET_NAME = 'pool'
PSEUDOREPLICATOR_APPLET_NAME = 'pseudoreplicator'
ENCODE_SPP_APPLET_NAME = 'encode_spp'
ENCODE_MACS2_APPLET_NAME = 'encode_macs2'
IDR_APPLET_NAME='idr'
ENCODE_IDR_APPLET_NAME='encode_idr'
OVERLAP_PEAKS_APPLET_NAME='overlap_peaks'

APPLETS = {}
github dnanexus / dx-toolkit / src / python / dxpy / bindings / __init__.py View on Github external
def _get_creation_params(kwargs):
        common_creation_params = {"project", "name", "tags", "types", "hidden", "properties", "details", "folder", "parents"}

        dx_hash = {p: kwargs[p] for p in kwargs if p in common_creation_params and kwargs[p] is not None}
        remaining_kwargs = {p: kwargs[p] for p in kwargs if p not in common_creation_params}

        if "project" not in dx_hash:
            dx_hash["project"] = dxpy.WORKSPACE_ID

        return dx_hash, remaining_kwargs
github ENCODE-DCC / chip-seq-pipeline / dnanexus / chip_workflow.py View on Github external
'histone': {
        'wf_name': 'histone_chip_seq',
        'wf_title': 'Histone ChIP-seq',
        'wf_description': 'ENCODE histone ChIP-seq Analysis Pipeline',
        'run_idr': False
    },
    'tf': {
        'wf_name': 'tf_chip_seq',
        'wf_title': 'TF ChIP-seq',
        'wf_description': 'ENCODE TF ChIP-seq Analysis Pipeline',
        'run_idr': True
    }
}

DEFAULT_APPLET_PROJECT = dxpy.WORKSPACE_ID
DEFAULT_OUTPUT_PROJECT = dxpy.WORKSPACE_ID
DEFAULT_OUTPUT_FOLDER = '/analysis_run'

MAPPING_APPLET_NAME = 'encode_map'
FILTER_QC_APPLET_NAME = 'filter_qc'
XCOR_APPLET_NAME = 'xcor'
XCOR_ONLY_APPLET_NAME = 'xcor_only'
SPP_APPLET_NAME = 'spp'
POOL_APPLET_NAME = 'pool'
PSEUDOREPLICATOR_APPLET_NAME = 'pseudoreplicator'
ENCODE_SPP_APPLET_NAME = 'encode_spp'
ENCODE_MACS2_APPLET_NAME = 'encode_macs2'
# IDR_APPLET_NAME='idr'
IDR2_APPLET_NAME = 'idr2'
ENCODE_IDR_APPLET_NAME = 'encode_idr'
OVERLAP_PEAKS_APPLET_NAME = 'overlap_peaks'
ACCESSION_ANALYSIS_APPLET_NAME = 'accession_analysis'
github dnanexus / dx-toolkit / src / python / dxpy / cli / exec_io.py View on Github external
except:
                pass
            if proj_name is not None:
                print('Your current working directory is ' + proj_name + ':' + dxpy.config.get('DX_CLI_WD', '/'))
        while True:
            print('Pick an option to find input data:')
            try:
                opt_num = pick(['List and choose from available data in the current project',
                                'List and choose from available data in the DNAnexus Reference Genomes project',
                                'Select another project to list and choose available data',
                                'Select an output from a previously-run job (current project only)',
                                'Return to original prompt (specify an ID or path directly)'])
            except KeyboardInterrupt:
                opt_num = 4
            if opt_num == 0:
                query_project = dxpy.WORKSPACE_ID
            elif opt_num == 1:
                query_project = dxpy.find_one_project(name="Reference Genome Files", public=True, billed_to="org-dnanexus", level="VIEW")['id']
            elif opt_num == 2:
                project_generator = dxpy.find_projects(level='VIEW', describe=True, explicit_perms=True)
                print('\nProjects to choose from:')
                query_project = paginate_and_pick(project_generator, (lambda result: result['describe']['name']))['id']
            if opt_num in range(3):
                result_generator = dxpy.find_data_objects(classname=in_class,
                                                          typename=param_desc.get('type'),
                                                          describe=dict(fields=get_ls_l_desc_fields()),
                                                          project=query_project)
                print('\nAvailable data:')
                result_choice = paginate_and_pick(result_generator,
                                                  (lambda result: get_ls_l_desc(result['describe'])))
                if result_choice == 'none found':
                    print('No compatible data found')
github dnanexus / dx-toolkit / src / python / dxpy / cli / workflow.py View on Github external
def new_workflow(args):
    try_call(process_dataobject_args, args)
    try_call(process_single_dataobject_output_args, args)
    init_from = None
    if args.init is not None:
        if is_analysis_id(args.init):
            init_from = args.init
        else:
            init_project, _init_folder, init_result = try_call(resolve_existing_path,
                                                               args.init,
                                                               expected='entity')
            init_from = dxpy.get_handler(init_result['id'], project=init_project)
    if args.output is None:
        project = dxpy.WORKSPACE_ID
        folder = dxpy.config.get("DX_CLI_WD", "/")
        name = None
    else:
        project, folder, name = try_call(dxpy.utils.resolver.resolve_path, args.output)
    if args.output_folder is not None:
        try:
            # Try to resolve to a path in the project
            _ignore, args.output_folder, _ignore = resolve_path(args.output_folder, expected='folder')
        except:
            # But if not, just use the value directly
            pass

    try:
        dxworkflow = dxpy.new_dxworkflow(title=args.title, summary=args.summary,
                                         description=args.description,
                                         output_folder=args.output_folder,