def print_protocol_info(self,
                            entity,
                            entity_type,
                            include_uuid=False,
                            include_test_group=False):
        group_id = self.get_dict_attrib(
            entity, "provenance_group_uuid").strip().lower()
        if string_helper.isBlank(group_id):
            return
        if not include_test_group:
            if self.test_group_id == group_id:
                return
        group_name = self.get_dict_attrib(entity, "provenance_group_name")
        display_doi = self.get_dict_attrib(entity, "display_doi")
        uuid = self.get_dict_attrib(entity, "uuid")
        display_id = self.get_dict_attrib(entity, "hubmap_identifier")
        protocols = self.get_dict_attrib(entity, "protocols")
        prot_files = []
        prot_globus_urls = []
        prot_dois = []
        if not string_helper.isBlank(protocols):
            prots = json.loads(protocols.replace("'", '"'))
            for prot in prots:
                if "protocol_file" in prot and not string_helper.isBlank(
                        prot['protocol_file']):
                    prot_files.append(prot['protocol_file'])
                    prot_globus_urls.append(
                        self.convert_to_globus_url(prot['protocol_file']))
                if "protocol_url" in prot and not string_helper.isBlank(
                        prot['protocol_url']):
                    prot_dois.append(prot['protocol_url'])
        protocol = self.get_dict_attrib(entity, "protocol")
        if not string_helper.isBlank(protocol):
            prot_dois.append(protocol)
        protocol_file = self.get_dict_attrib(entity, "protocol_file")
        if not string_helper.isBlank(protocol_file):
            prot_files.append(protocol_file)
            prot_globus_urls.append(self.convert_to_globus_url(protocol_file))

        vals = []
        vals.append(entity_type)
        vals.append(group_name)
        vals.append(display_id)
        vals.append(display_doi)
        if include_uuid:
            vals.append(uuid)
        vals.append(string_helper.listToDelimited(prot_dois,
                                                  delimitChar=" | "))
        vals.append(
            string_helper.listToDelimited(prot_globus_urls, delimitChar=" | "))
        vals.append(
            string_helper.listToDelimited(prot_files, delimitChar=" | "))
        print(string_helper.listToCommaSeparated(vals))
Beispiel #2
0
    def update_collection(self, uuid, record):
        if (HubmapConst.UUID_ATTRIBUTE in record
                or HubmapConst.DOI_ATTRIBUTE in record
                or HubmapConst.DISPLAY_DOI_ATTRIBUTE in record
                or HubmapConst.ENTITY_TYPE_ATTRIBUTE in record):
            raise HTTPException("ID attributes cannot be changed", 400)

        not_allowed = []
        for attrib in record.keys():
            if not attrib in self.allowed_collection_update_attributes:
                not_allowed.append(attrib)

        if len(not_allowed) > 0:
            raise HTTPException(
                "Attribute(s) not allowed: " +
                string_helper.listToDelimited(not_allowed, " "), 400)

        if HubmapConst.COLLECTION_CREATORS_ATTRIBUTE in record:
            creators = record[HubmapConst.COLLECTION_CREATORS_ATTRIBUTE]
            for creator in creators:
                for attrib in creator.keys():
                    if not attrib in self.allowed_creator_attributes and not attrib in not_allowed:
                        not_allowed.append(attrib)

            if len(not_allowed) > 0:
                raise HTTPException(
                    "Creator Aattribute(s) not allowed: " +
                    string_helper.listToDelimited(not_allowed, " "), 400)

        save_record = {}
        for attrib in record.keys():
            if attrib == HubmapConst.COLLECTION_CREATORS_ATTRIBUTE:
                save_record[attrib] = json.dumps(record[attrib])
            else:
                save_record[attrib] = record[attrib]

        rval = self.get_py2neo_conn().run(
            "match(c:Collection {uuid: {uuid}}) set c += {params} return c.uuid",
            uuid=uuid,
            params=save_record).data()
        if len(rval) == 0:
            raise HTTPException(
                "Update failed for collection with uuid " + uuid +
                ".  UUID possibly not found.", 400)
        else:
            if rval[0]['c.uuid'] != uuid:
                raise HTTPException(
                    "Update failed, wrong uuid returned while trying to update "
                    + uuid + " returned: " + rval[0]['c.uuid'])
def write_tsv(row, datatype):
    uuid = row['hmuuid']
    if string_helper.isBlank(uuid):
        print("ERROR: no uuid for row in datatype: " + datatype)
        return

    output_path = output_dir + "/" + row['hmuuid'] + "-" + datatype + ".tsv"
    with open(output_path, 'w') as writer:
        keys = []
        data = []
        base_submission_path = None
        if not uuid in dataset_info_by_uuid:
            print("WARNING: dataset information not found for " + uuid)
        else:
            base_submission_path = dataset_info_by_uuid[uuid]['local_path']
            if not base_submission_path.lower().startswith('/hive/hubmap/lz'):
                print(
                    "WARNING: dataset local path doesn't start with /hive/hubmap/lz: "
                    + uuid)
            else:
                base_submission_path = base_submission_path[15:].lower()

        for key in row.keys():
            if not key == 'hmuuid':
                val = row[key]
                keyl = key.lower()
                if keyl == 'metadata_path' or key == 'data_path':
                    if base_submission_path is None:
                        print("ERROR: no base_submittion_path set on " + key +
                              ": " + val)
                    if val is None:
                        print("WARNING: no path found for " + key +
                              " for type: " + datatype + " on uuid: " + uuid)
                    elif not val.lower().startswith(base_submission_path):
                        print("WARNING: path " + key + ": " + val +
                              " does not start with base path: " +
                              base_submission_path)
                    val = val[len(base_submission_path):]
                keys.append(key)
                data.append(val)

        writer.write(
            string_helper.listToDelimited(keys, delimitChar='\t') + '\n')
        writer.write(
            string_helper.listToDelimited(data, delimitChar='\t') + '\n')
def resolveToMultipleUUIDs(hmids):
    underscore_idx = hmids.rfind("_")
    dash_idx = hmids.rfind("-")
    if underscore_idx == -1 or dash_idx == -1 or dash_idx > underscore_idx:
        return "No UUIDs Found"
    baseId = getDisplayId(hmids)
    idx1 = hmids[dash_idx + 1:underscore_idx]
    idx2 = hmids[underscore_idx + 1:]
    if not idx1.isdigit() or not idx2.isdigit():
        return "No UUIDs Found"
    uuids = []
    for idx in range(int(idx1), int(idx2) + 1):
        uuids.append(resolveToUUID(baseId + "-" + str(idx)))
    suuids = string_helper.listToDelimited(uuids, "|")
    return suuids
Beispiel #5
0
        last_dot = output_base.rfind(".")
        if not last_dot == -1:
            numeric = output_base[last_dot + 1:]
            if numeric.isdigit():
                next_file = int(numeric) + 1
                output_base = output_base[:last_dot]
            else:
                next_file = 1
        else:
            next_file = 1
            
        output_path = output_base + "." + str(next_file) +".tsv"                    
        while os.path.isfile(output_path):
            next_file = next_file + 1
            output_path = output_base + "." + str(next_file) +".tsv"
        with open(output_path, 'w') as writer:
            first = True
            for info_line in ingest_worker.dataset_info:
                if first:
                    first = False
                    line_keys = info_line.keys()
                    writer.write(string_helper.listToDelimited(line_keys, delimitChar='\t') + '\n')
                line = []
                for key in line_keys:
                    val = info_line[key]
                    if val is None: val = ''
                    line.append(val)
                writer.write(string_helper.listToDelimited(line, delimitChar='\t') + '\n')