示例#1
0
文件: item.py 项目: kidaa/encoded
def audit_item_status(value, system):
    if 'status' not in value:
        return

    level = STATUS_LEVEL.get(value['status'], 50)
    if level == 0:
        return

    context = system['context']
    request = system['request']
    linked = set()
    for schema_path in context.type_info.schema_links:
        if schema_path in ['supercedes', 'step_run']:
            continue
        linked.update(simple_path_ids(value, schema_path))

    for path in linked:
        linked_value = request.embed(path + '@@object')
        if 'status' not in linked_value:
            continue
        if linked_value['status'] == 'disabled':
            continue
        if (  # Special case: A revoked file can have a deleted replicate ticket #2938
            'File' in value['@type'] and
            value['status'] == 'revoked' and
            'Replicate' in linked_value['@type'] and
            linked_value['status'] == 'deleted'
        ):
            continue
        linked_level = STATUS_LEVEL.get(linked_value['status'], 50)
        if linked_level == 0:
            detail = '{} {} has {} subobject {}'.format(
                value['status'], value['@id'], linked_value['status'], linked_value['@id'])
            yield AuditFailure('mismatched status', detail, level='ERROR')
        elif linked_level < level:
            detail = '{} {} has {} subobject {}'.format(
                value['status'], value['@id'], linked_value['status'], linked_value['@id'])
            yield AuditFailure('mismatched status', detail, level='DCC_ACTION')
示例#2
0
def metadata_tsv(context, request):

    param_list = parse_qs(request.matchdict['search_params'])
    param_list['field'] = []
    header = []
    file_attributes = []
    for prop in _tsv_mapping:
        header.append(prop)
        param_list['field'] = param_list['field'] + _tsv_mapping[prop]
        if _tsv_mapping[prop][0].startswith('files'):
            file_attributes = file_attributes + [_tsv_mapping[prop][0]]
    param_list['limit'] = ['all']
    path = '/search/?%s' % urlencode(param_list, True)
    results = request.embed(path, as_user=True)
    rows = []
    for row in results['@graph']:
        if row['files']:
            exp_data_row = []
            for column in header:
                if not _tsv_mapping[column][0].startswith('files'):
                    temp = []
                    for c in _tsv_mapping[column]:
                        c_value = []
                        for value in simple_path_ids(row, c):
                            if str(value) not in c_value:
                                c_value.append(str(value))
                        if c == 'replicates.library.biosample.post_synchronization_time' and len(
                                temp):
                            if len(c_value):
                                temp[0] = temp[0] + ' + ' + c_value[0]
                        elif len(temp):
                            if len(c_value):
                                temp = [x + ' ' + c_value[0] for x in temp]
                        else:
                            temp = c_value
                    exp_data_row.append(', '.join(list(set(temp))))
            f_attributes = [
                'files.title', 'files.file_type', 'files.output_type'
            ]
            for f in row['files']:
                if 'files.file_type' in param_list:
                    if f['file_type'] not in param_list['files.file_type']:
                        continue
                f['href'] = request.host_url + f['href']
                f_row = []
                for attr in f_attributes:
                    f_row.append(f[attr[6:]])
                data_row = f_row + exp_data_row
                for prop in file_attributes:
                    if prop in f_attributes:
                        continue
                    path = prop[6:]
                    temp = []
                    for value in simple_path_ids(f, path):
                        temp.append(str(value))
                    if prop == 'files.replicate.rbns_protein_concentration':
                        if 'replicate' in f and 'rbns_protein_concentration_units' in f[
                                'replicate']:
                            temp[0] = temp[0] + ' ' + f['replicate'][
                                'rbns_protein_concentration_units']
                    if prop == 'files.paired_with':
                        # chopping of path to just accession
                        if len(temp):
                            new_values = [t[7:-1] for t in temp]
                            temp = new_values
                    data = list(set(temp))
                    data.sort()
                    data_row.append(', '.join(data))
                rows.append(data_row)
    fout = io.StringIO()
    writer = csv.writer(fout, delimiter='\t')
    writer.writerow(header)
    writer.writerows(rows)
    return Response(content_type='text/tsv',
                    body=fout.getvalue(),
                    content_disposition='attachment;filename="%s"' %
                    'metadata.tsv')
示例#3
0
def metadata_tsv(context, request):

    param_list = parse_qs(request.matchdict["search_params"])
    param_list["field"] = []
    header = []
    file_attributes = []
    for prop in _tsv_mapping:
        header.append(prop)
        param_list["field"] = param_list["field"] + _tsv_mapping[prop]
        if _tsv_mapping[prop][0].startswith("files"):
            file_attributes = file_attributes + [_tsv_mapping[prop][0]]
    param_list["limit"] = ["all"]
    path = "/search/?%s" % urlencode(param_list, True)
    results = request.embed(path, as_user=True)
    rows = []
    for row in results["@graph"]:
        if row["files"]:
            exp_data_row = []
            for column in header:
                if not _tsv_mapping[column][0].startswith("files"):
                    temp = []
                    for c in _tsv_mapping[column]:
                        c_value = []
                        for value in simple_path_ids(row, c):
                            if str(value) not in c_value:
                                c_value.append(str(value))
                        if c == "replicates.library.biosample.post_synchronization_time" and len(temp):
                            if len(c_value):
                                temp[0] = temp[0] + " + " + c_value[0]
                        elif len(temp):
                            if len(c_value):
                                temp = [x + " " + c_value[0] for x in temp]
                        else:
                            temp = c_value
                    exp_data_row.append(", ".join(list(set(temp))))
            f_attributes = ["files.title", "files.file_type", "files.output_type"]
            for f in row["files"]:
                if "files.file_type" in param_list:
                    if f["file_type"] not in param_list["files.file_type"]:
                        continue
                f["href"] = request.host_url + f["href"]
                f_row = []
                for attr in f_attributes:
                    f_row.append(f[attr[6:]])
                data_row = f_row + exp_data_row
                for prop in file_attributes:
                    if prop in f_attributes:
                        continue
                    path = prop[6:]
                    temp = []
                    for value in simple_path_ids(f, path):
                        temp.append(str(value))
                    if prop == "files.replicate.rbns_protein_concentration":
                        if "replicate" in f and "rbns_protein_concentration_units" in f["replicate"]:
                            temp[0] = temp[0] + " " + f["replicate"]["rbns_protein_concentration_units"]
                    if prop == "files.paired_with":
                        # chopping of path to just accession
                        if len(temp):
                            new_values = [t[7:-1] for t in temp]
                            temp = new_values
                    data_row.append(", ".join(list(set(temp))))
                rows.append(data_row)
    fout = io.StringIO()
    writer = csv.writer(fout, delimiter="\t")
    writer.writerow(header)
    writer.writerows(rows)
    return Response(
        content_type="text/tsv", body=fout.getvalue(), content_disposition='attachment;filename="%s"' % "metadata.tsv"
    )