How to use the dxpy.get_handler 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 ENCODE-DCC / long-rna-seq-pipeline / dnanexus / tools / parse_property.py View on Github external
try:
        dxlink = json.loads(filePath.strip("'"))
    except:
        dxlink = None

    if project != None:

        try:
            if dxlink != None:
                dxfile = dxpy.get_handler(dxlink,project=project)
            else:
                dxfile = dxpy.get_handler(filePath,project=project)
        except:
            try:
                dxlink = dxpy.dxlink(filePath,project=project)
                dxfile = dxpy.get_handler(dxlink)
            except:
                try:
                    proj_id = env_get_current_project_id()
                    dxfile = dxpy.DXFile(filePath,project=proj_id)
                except:
                    sys.stderr.write('ERROR: unable to find file "' + filePath + '": \n')
                    sys.exit(0)  # Do not error on tool run in dx script

    else:

        try:
            if dxlink != None:
                dxfile = dxpy.get_handler(dxlink)
            else:
                dxfile = dxpy.get_handler(filePath)
        except:
github ENCODE-DCC / long-rna-seq-pipeline / dnanexus / tools / parse_property.py View on Github external
dxfile = None
    #if filePath.find("$dnanexus_link") != -1:
    #    filePath = filePath.split(' ')[1]
    #    filePath = filePath.replace("'","").replace('"','').replace("}","").replace("{","")
    try:
        dxlink = json.loads(filePath.strip("'"))
    except:
        dxlink = None

    if project != None:

        try:
            if dxlink != None:
                dxfile = dxpy.get_handler(dxlink,project=project)
            else:
                dxfile = dxpy.get_handler(filePath,project=project)
        except:
            try:
                dxlink = dxpy.dxlink(filePath,project=project)
                dxfile = dxpy.get_handler(dxlink)
            except:
                try:
                    proj_id = env_get_current_project_id()
                    dxfile = dxpy.DXFile(filePath,project=proj_id)
                except:
                    sys.stderr.write('ERROR: unable to find file "' + filePath + '": \n')
                    sys.exit(0)  # Do not error on tool run in dx script

    else:

        try:
            if dxlink != None:
github ENCODE-DCC / chip-seq-pipeline / dnanexus / call_chip_from_tas.py View on Github external
def resolve_project(identifier, privs='r'):
    project = dxpy.find_one_project(
        name=identifier, level='VIEW', name_mode='exact', return_handler=True,
        zero_ok=True)
    if project is None:
        try:
            project = dxpy.get_handler(identifier)
        except:
            logging.error(
                'Could not find a unique project with name or id %s'
                % (identifier))
            raise ValueError(identifier)
    logging.debug(
        'Project %s access level is %s'
        % (project.name, project.describe()['level']))
    if privs == 'w' and project.describe()['level'] == 'VIEW':
        logging.error('Output project %s is read-only' % (identifier))
        raise ValueError(identifier)
    return project
github dnanexus / dx-toolkit / src / python / dxpy / app_builder.py View on Github external
if project is None:
        dest_project = applet_spec['project']
    else:
        dest_project = project
        applet_spec['project'] = project

    resources_dir = os.path.join(src_dir, "resources")
    if os.path.exists(resources_dir) and len(os.listdir(resources_dir)) > 0:
        logger.debug("Uploading in " + src_dir)

        with tempfile.NamedTemporaryFile(suffix=".tar.gz") as tar_fh:
            subprocess.check_call(['tar', '-C', resources_dir, '-czf', tar_fh.name, '.'])
            if 'folder' in applet_spec:
                try:
                    dxpy.get_handler(dest_project).new_folder(applet_spec['folder'], parents=True)
                except dxpy.exceptions.DXAPIError:
                    pass # TODO: make this better
            target_folder = applet_spec['folder'] if 'folder' in applet_spec else folder
            dx_resource_archive = dxpy.upload_local_file(tar_fh.name, wait_on_close=True,
                                                         project=dest_project, folder=target_folder, hidden=True)
            archive_link = dxpy.dxlink(dx_resource_archive.get_id())
            return [{'name': 'resources.tar.gz', 'id': archive_link}]
    else:
        return []
github ENCODE-DCC / chip-seq-pipeline / dnanexus / call_peaks_from_ta.py View on Github external
def resolve_project(identifier, privs='r'):
	project = dxpy.find_one_project(name=identifier, level='VIEW', name_mode='exact', return_handler=True, zero_ok=True)
	if project == None:
		try:
			project = dxpy.get_handler(identifier)
		except:
			logging.error('Could not find a unique project with name or id %s' %(identifier))
			raise ValueError(identifier)
	logging.debug('Project %s access level is %s' %(project.name, project.describe()['level']))
	if privs == 'w' and project.describe()['level'] == 'VIEW':
		logging.error('Output project %s is read-only' %(identifier))
		raise ValueError(identifier)
	return project
github dnanexus / dx-toolkit / src / python / dxpy / utils / completer.py View on Github external
folderpath, typespec=typespec,
                                                    visibility=visibility)
            except:
                pass
    else:
        # project is given by a path, but attempt to resolve to an
        # object or folder anyway
        try:
            proj_ids, folderpath, entity_name = resolve_path(text, multi_projects=True)
        except ResolutionError as details:
            sys.stderr.write("\n" + fill(str(details)))
            return matches
        for proj in proj_ids:
            # protects against dxpy.WORKSPACE_ID being garbage
            try:
                dxproj = dxpy.get_handler(proj)
                matches += get_folder_matches(text, delim_pos, dxproj, folderpath)
                if expected != 'folder':
                    if classes is not None:
                        for classname in classes:
                            matches += get_data_matches(text, delim_pos, dxproj,
                                                        folderpath, classname=classname,
                                                        typespec=typespec, visibility=visibility)
                    else:
                        matches += get_data_matches(text, delim_pos, dxproj,
                                                    folderpath, typespec=typespec,
                                                    visibility=visibility)
            except:
                pass
    return matches
github ENCODE-DCC / chip-seq-pipeline / dnanexus / map_only.py View on Github external
def resolve_project(identifier, privs='r'):
    project = dxpy.find_one_project(name=identifier, level='VIEW', name_mode='exact', return_handler=True, zero_ok=True)
    if project == None:
        try:
            project = dxpy.get_handler(identifier)
        except:
            logging.error('Could not find a unique project with name or id %s' %(identifier))
            raise ValueError(identifier)
    logging.debug('Project %s access level is %s' %(project.name, project.describe()['level']))
    if privs == 'w' and project.describe()['level'] == 'VIEW':
        logging.error('Output project %s is read-only' %(identifier))
        raise ValueError(identifier)
    return project
github dnanexus / dx-toolkit / src / python / dxpy / sugar / objects.py View on Github external
Raises:
        dxpy.DXSearchError if the data object does exist and `exists is False` or if
        the data object does not exist and `exists is True`.
    """
    if data_obj_desc is None:
        raise ValueError("'data_obj_desc' cannot be None")

    project = get_project(project, exists=True)
    data_obj = None
    search = True

    if isinstance(data_obj_desc, dxpy.DXDataObject):
        data_obj = data_obj_desc
        search = False
    elif resolver.is_data_obj_id(data_obj_desc):
        data_obj = dxpy.get_handler(data_obj_desc, project.get_id())

    if data_obj:
        try:
            data_obj.describe()
            if classname not in ("*", None):
                dxpy.verify_string_dxid(data_obj.get_id(), classname)
        except dxpy.DXError:
            data_obj = None

    if data_obj is None and search:
        folder, name, recurse = _parse_object_name(data_obj_desc)
        kwargs["return_handler"] = True
        if project is not None:
            kwargs["project"] = project.get_id()
        if "folder" not in kwargs:
            kwargs["folder"] = folder
github ENCODE-DCC / chip-seq-pipeline / dnanexus / input_shield / src / input_shield.py View on Github external
def resolve_project(identifier, privs='r'):
    logger.debug("In resolve_project with identifier %s" % (identifier))
    project = dxpy.find_one_project(
        name=identifier, level='VIEW', name_mode='exact',
        return_handler=True, zero_ok=True)
    if project is None:
        try:
            project = dxpy.get_handler(identifier)
        except:
            logger.error(
                'Could not find a unique project with name or id %s'
                % (identifier))
            raise ValueError(identifier)
    logger.debug(
        'Project %s access level is %s'
        % (project.name, project.describe()['level']))
    if privs == 'w' and project.describe()['level'] == 'VIEW':
        logger.error('Output project %s is read-only' % (identifier))
        raise ValueError(identifier)
    return project
github dnanexus / dx-toolkit / src / python / dxpy / bindings / dxdatabase_functions.py View on Github external
'''
    :param project: Project ID to use as context for the listing
    :type project: string
    :param path: Subtree root path
    :type path: string
    :param recurse: Return a complete subfolders tree
    :type recurse: boolean

    Returns a list of subfolders for the remote *path* (included to the result) of the *project*.

    Example::

        list_subfolders("project-xxxx", folder="/input")

    '''
    project_folders = dxpy.get_handler(project).describe(input_params={'folders': True})['folders']
    # TODO: support shell-style path globbing (i.e. /a*/c matches /ab/c but not /a/b/c)
    # return pathmatch.filter(project_folders, os.path.join(path, '*'))
    if recurse:
        return (f for f in project_folders if f.startswith(path))
    else:
        return (f for f in project_folders if f.startswith(path) and '/' not in f[len(path)+1:])