Beispiel #1
0
class Treatment(Item):
    item_type = 'treatment'
    schema = load_schema('encoded:schemas/treatment.json')
    embedded = []
    set_status_up = [
        'biosamples_used',
        'antibodies_used',
    ]
    set_status_down = []
Beispiel #2
0
class Project(FileSet, CalculatedFileSetAssay, CalculatedFileSetBiosample, CalculatedBiosampleSlims, CalculatedBiosampleSynonyms, CalculatedAssaySynonyms):
    item_type = 'project'
    schema = load_schema('encoded:schemas/project.json')
    embedded = FileSet.embedded + [
        'files.dataset',
        'files.replicate.library',
        'files.replicate.experiment.target',
        'organism'
    ]
Beispiel #3
0
class HiglassViewConfig(Item):
    """
    Item type which contains a `view_config` property and other metadata.
    """

    item_type = 'higlass_view_config'
    schema = load_schema('encoded:schemas/higlass_view_config.json')
    embedded_list = []
    name_key = 'name'
Beispiel #4
0
class PublicationData(FileSet, CalculatedFileSetBiosample,
                      CalculatedFileSetAssay, CalculatedBiosampleSlims,
                      CalculatedBiosampleSynonyms, CalculatedAssaySynonyms):
    item_type = 'publication_data'
    schema = load_schema('encoded:schemas/publication_data.json')
    embedded = [
        'organism', 'submitted_by', 'lab', 'award.pi.lab', 'documents.lab',
        'documents.award', 'documents.submitted_by', 'references'
    ]
class Bioproject(BiofileSet, CalculatedFileSetAssay,
                 CalculatedFileSetBiosample, CalculatedAssaySynonyms):
    item_type = 'bioproject'
    schema = load_schema('encoded:schemas/bioproject.json')
    embedded = BiofileSet.embedded + [
        'files.biodataset', 'files.bioreplicate.biolibrary',
        'files.bioreplicate', 'files.bioreplicate.bioexperiment', 'award',
        'lab'
    ]
Beispiel #6
0
class User(Item):
    """The user class."""

    item_type = 'user'
    schema = load_schema('encoded:schemas/user.json')
    embedded_list = [
        'project_roles.role',
        'project_roles.project.name',
        'project_roles.project.description',
        'project_roles.project.pi',
    ]

    # TODO (C4-332): consolidate all acls into once place
    STATUS_ACL = {
        'current': ONLY_OWNER_VIEW_PROFILE_ACL,
        'deleted': DELETED_USER_ACL,
        'revoked': DELETED_USER_ACL,
        'inactive': ONLY_OWNER_VIEW_PROFILE_ACL,
    }

    @calculated_property(schema={
        "title": "Title",
        "type": "string",
    })
    def title(self, first_name, last_name):
        """return first and last name."""
        title = u'{} {}'.format(first_name, last_name)
        return title

    @calculated_property(
        schema={
            "title": "Display Title",
            "description": "A calculated title for every object in 4DN",
            "type": "string"
        })
    def display_title(self, first_name, last_name):
        return self.title(first_name, last_name)

    @calculated_property(
        schema={
            "title": "Contact Email",
            "description":
            "E-Mail address by which this person should be contacted.",
            "type": "string",
            "format": "email"
        })
    def contact_email(self, email, preferred_email=None):
        """Returns `email` if `preferred_email` is not defined."""
        if preferred_email:
            return preferred_email
        else:
            return email

    def __ac_local_roles__(self):
        """return the owner user."""
        owner = 'userid.%s' % self.uuid
        return {owner: 'role.owner'}
Beispiel #7
0
class Library(Item):
    item_type = 'library'
    schema = load_schema('encoded:schemas/library.json')
    name_key = 'accession'
    embedded = [
        'biosample',
        'biosample.donor',
        'biosample.donor.organism',
    ]
class Bioseries(Biodataset, CalculatedSeriesAssay, CalculatedSeriesBiosample,
                CalculatedSeriesTarget, CalculatedSeriesTreatment,
                CalculatedAssaySynonyms):
    item_type = 'bioseries'
    base_types = ['Bioseries'] + Biodataset.base_types
    schema = load_schema('encoded:schemas/bioseries.json')
    embedded = Biodataset.embedded + [
        'references', 'related_datasets.biospecimen', 'related_datasets.files',
        'related_datasets.lab', 'related_datasets.submitted_by',
        'related_datasets.award.pi.lab',
        'related_datasets.bioreplicate.biolibrary',
        'related_datasets.bioreplicate.biolibrary.biospecimen.submitted_by',
        'related_datasets.bioreplicate.biolibrary.biospecimen',
        'related_datasets.bioreplicate.biolibrary.biospecimen.donor',
        'related_datasets.possible_controls',
        'related_datasets.possible_controls.lab',
        'related_datasets.references', 'files.platform', 'files.lab',
        'files.bioreplicate.biolibrary.biospecimen',
        'files.biolibrary.biospecimen', 'award', 'lab'
    ]

    @calculated_property(
        schema={
            "title": "Revoked datasets",
            "type": "array",
            "items": {
                "type": "string",
                "linkTo": "Biofile",
            },
        })
    def revoked_datasets(self, request, related_datasets):
        return [
            path for path in related_datasets
            if item_is_revoked(request, path)
        ]

    @calculated_property(define=True,
                         schema={
                             "title": "Genome assembly",
                             "type": "array",
                             "items": {
                                 "type": "string",
                             },
                         })
    def assembly(self, request, original_files, related_datasets, status):
        combined_assembly = set()
        for assembly_from_original_files in calculate_assembly(
                request, original_files, status):
            combined_assembly.add(assembly_from_original_files)
        for biodataset in related_datasets:

            properties = request.embed(biodataset, '@@object')
            if properties['status'] not in ('deleted', 'replaced'):
                for assembly_from_related_dataset in properties['assembly']:
                    combined_assembly.add(assembly_from_related_dataset)
        return list(combined_assembly)
Beispiel #9
0
class Page(Item):
    """Links to StaticSections"""
    item_type = 'page'
    schema = load_schema('encoded:schemas/page.json')
    embedded_list = ['content.*']

    # STATUS_ACL = StaticSection.STATUS_ACL

    class Collection(Item.Collection):
        pass
Beispiel #10
0
class Tvp_a2(Item):
    item_type = "tvp_a2"
    schema = load_schema("encoded:schemas/tvp_a2.json")
    embedded = [
    ]
    rev = {
    }
    audit_inherit = []
    set_status_up = []
    set_status_down = []
Beispiel #11
0
class AnalysisStepVersion(Item):
    item_type = 'analysis_step_version'
    schema = load_schema('encoded:schemas/analysis_step_version.json')

    def unique_keys(self, properties):
        keys = super(AnalysisStepVersion, self).unique_keys(properties)
        value = u'{analysis_step}/{version}'.format(**properties)
        keys.setdefault('analysis_step_version:analysis_step_version',
                        []).append(value)
        return keys
Beispiel #12
0
class Fvp_b7(Item):
    item_type = "fvp_b7"
    schema = load_schema("encoded:schemas/fvp_b7.json")
    embedded = [
    ]
    rev = {
    }
    audit_inherit = []
    set_status_up = []
    set_status_down = []
Beispiel #13
0
class GeneticModification(Item):
    item_type = 'genetic_modification'
    schema = load_schema('encoded:schemas/genetic_modification.json')
    name_key = 'accession'
    embedded = [
        'characterizations', 'modified_site_by_target_id', 'treatments', 'lab'
    ]

    rev = {
        'biosamples_modified': ('Biosample', 'genetic_modifications'),
        'donors_modified': ('Donor', 'genetic_modifications'),
        'characterizations':
        ('GeneticModificationCharacterization', 'characterizes')
    }

    @calculated_property(
        schema={
            "title": "Biosamples modified",
            "description":
            "Biosamples genetically altered using this modification",
            "type": "array",
            "items": {
                "type": ['string', 'object'],
                "linkFrom": "Biosample.genetic_modifications",
            },
        })
    def biosamples_modified(self, request, biosamples_modified):
        return paths_filtered_by_status(request, biosamples_modified)

    @calculated_property(
        schema={
            "title": "Donors modified",
            "description":
            "Donors genetically altered using this modification",
            "type": "array",
            "items": {
                "type": ['string', 'object'],
                "linkFrom": "Donor.genetic_modifications",
            },
        })
    def donors_modified(self, request, donors_modified):
        return paths_filtered_by_status(request, donors_modified)

    @calculated_property(
        schema={
            "title": "Characterizations",
            "type": "array",
            "items": {
                "type": ['string', 'object'],
                "linkFrom":
                "GeneticModificationCharacterization.characterizes",
            },
        })
    def characterizations(self, request, characterizations):
        return paths_filtered_by_status(request, characterizations)
Beispiel #14
0
class LabResults(Item):
    item_type = 'lab_results'
    schema = load_schema('encoded:schemas/lab_results.json')
    embedded = ['patient']

    def __ac_local_roles__(self):
        # Use patient object for access control.
        properties = self.upgrade_properties()
        root = find_root(self)
        patient = root.get_by_uuid(properties['patient'])
        return patient.__ac_local_roles__()
Beispiel #15
0
class Platform(Item):
    item_type = 'platform'
    schema = load_schema('encoded:schemas/platform.json')
    name_key = 'term_id'

    @calculated_property(schema={
        "title": "Title",
        "type": "string",
    })
    def title(self, term_name):
        return term_name
Beispiel #16
0
class SoftwareVersion(Item):
    item_type = 'software_version'
    schema = load_schema('encoded:schemas/software_version.json')
    embedded = ['software', 'software.references']

    def __ac_local_roles__(self):
        # Use lab/award from parent software object for access control.
        properties = self.upgrade_properties()
        root = find_root(self)
        software = root.get_by_uuid(properties['software'])
        return software.__ac_local_roles__()
Beispiel #17
0
class M1(Item):
    item_type = "m1"
    schema = load_schema("encoded:schemas/m1.json")
    embedded = [
       
    ]
    rev = {
    }
    audit_inherit = []
    set_status_up = []
    set_status_down = []
Beispiel #18
0
class Award(Item):
    item_type = 'award'
    schema = load_schema('encoded:schemas/award.json')
    name_key = 'name'
    embedded = ['pi.lab']
    STATUS_ACL = {
        'current': ALLOW_CURRENT,
        'deleted': DELETED,
        'replaced': DELETED,
        'disabled': ALLOW_CURRENT
    }
Beispiel #19
0
class Ivp_b6(Item):
    item_type = "ivp_b6"
    schema = load_schema("encoded:schemas/ivp_b6.json")
    embedded = [
       
    ]
    rev = {
    }
    audit_inherit = []
    set_status_up = []
    set_status_down = []
Beispiel #20
0
class AntibodyApproval(Item):
    schema = load_schema('encoded:schemas/antibody_approval.json')
    item_type = 'antibody_approval'

    __acl__ = DELETED

    def unique_keys(self, properties):
        keys = super(AntibodyApproval, self).unique_keys(properties)
        value = u'{antibody}/{target}'.format(**properties)
        keys.setdefault('antibody_approval:lot_target', []).append(value)
        return keys
Beispiel #21
0
class MouseDonor(Donor):
    item_type = 'mouse_donor'
    schema = load_schema('encoded:schemas/mouse_donor.json')
    embedded = Donor.embedded + [
        'references', 'genetic_modifications',
        'genetic_modifications.modified_site_by_target_id',
        'genetic_modifications.treatments'
    ]

    def __ac_local_roles__(self):
        # Disallow lab submitter edits
        return {Authenticated: 'role.viewing_group_member'}
Beispiel #22
0
class Library(Item):
    item_type = 'library'
    schema = load_schema('encoded:schemas/library.json')
    name_key = 'accession'
    embedded = [
        'biosample',
        'biosample.donor',
        'biosample.donor.organism',
    ]
    set_status_up = [
        'biosample',
        'documents',
        'source',
        'treatments',
    ]
    set_status_down = []

    @calculated_property(condition='nucleic_acid_term_name',
                         schema={
                             "title": "nucleic_acid_term_id",
                             "type": "string",
                         })
    def nucleic_acid_term_id(self, request, nucleic_acid_term_name):
        term_lookup = {
            'DNA': 'SO:0000352',
            'RNA': 'SO:0000356',
            'polyadenylated mRNA': 'SO:0000871',
            'miRNA': 'SO:0000276',
            'protein': 'SO:0000104'
        }
        term_id = None
        if nucleic_acid_term_name in term_lookup:
            term_id = term_lookup.get(nucleic_acid_term_name)
        return term_id

    @calculated_property(condition='depleted_in_term_name',
                         schema={
                             "title": "depleted_in_term_id",
                             "type": "string",
                         })
    def depleted_in_term_id(self, request, depleted_in_term_name):
        term_lookup = {
            'rRNA': 'SO:0000252',
            'polyadenylated mRNA': 'SO:0000871',
            'capped mRNA': 'SO:0000862'
        }
        term_id = list()
        for term_name in depleted_in_term_name:
            if term_name in term_lookup:
                term_id.append(term_lookup.get(term_name))
            else:
                term_id.append('Term ID unknown')
        return term_id
class StructuralVariant(Item):
    """ Structural variant class """

    item_type = "structural_variant"
    name_key = "annotation_id"
    schema = load_schema("encoded:schemas/structural_variant.json")
    embedded_list = build_structural_variant_embedded_list()

    @classmethod
    def create(cls, registry, uuid, properties, sheets=None):
        """
        Sets the annotation_id field on this structural variant prior to passing on.
        """
        properties[ANNOTATION_ID] = build_structural_variant_display_title(
            properties["SV_TYPE"],
            properties["CHROM"],
            properties["START"],
            properties["END"],
        )
        return super().create(registry, uuid, properties, sheets)

    @calculated_property(
        schema={
            "title": "Display Title",
            "description": "A calculated title for every object in CGAP",
            "type": "string",
        }
    )
    def display_title(self, SV_TYPE, CHROM, START, END):
        return build_structural_variant_display_title(SV_TYPE, CHROM, START, END)

    @calculated_property(
        schema={
            "title": "Start position (genome coordinates)",
            "description": "Start absolute position in genome coordinates",
            "type": "integer",
        }
    )
    def START_ABS(self, CHROM, START):
        chrom_info = nc.get_chrominfo("hg38")
        return nc.chr_pos_to_genome_pos("chr" + CHROM, START, chrom_info)

    @calculated_property(
        schema={
            "title": "End position (genome coordinates)",
            "description": "End absolute position in genome coordinates",
            "type": "integer",
        }
    )
    def END_ABS(self, CHROM, END):
        chrom_info = nc.get_chrominfo("hg38")
        return nc.chr_pos_to_genome_pos("chr" + CHROM, END, chrom_info)
Beispiel #24
0
class Snowflake(Item):
    item_type = 'snowflake'
    schema = load_schema('snowflakes:schemas/snowflake.json')
    name_key = 'accession'

    embedded = [
        'lab',
        'submitted_by',
    ]
    audit_inherit = [
        'lab',
        'submitted_by',
    ]
Beispiel #25
0
class Disorder(Item):
    item_type = 'disorder'
    schema = load_schema('encoded:schemas/disorder.json')
    embedded_list = []
    name_key = 'disorder_id'

    @calculated_property(schema={
        "title": "Display Title",
        "description": "A calculated title for every object in 4DN",
        "type": "string"
    })
    def display_title(self, disorder_name):
        return disorder_name
class AnalysisStepRun(Item):
    item_type = 'analysis_step_run'
    schema = load_schema('encoded:schemas/analysis_step_run.json')
    embedded = [
        'analysis_step_version.analysis_step',
    ]
    audit_inherit = ['*']
    # Avoid using reverse links on this object as invalidating a
    # step_run can cause thousands of objects to be reindexed.
    set_status_up = [
        'analysis_step_version',
    ]
    set_status_down = []
Beispiel #27
0
class AnalysisStep(Item):
    item_type = 'analysis_step'
    schema = load_schema('encoded:schemas/analysis_step.json')
    name_key = 'name'
    rev = {
        'pipelines': ('Pipeline', 'analysis_steps'),
        'versions': ('AnalysisStepVersion', 'analysis_step')
    }
    embedded = [
        'current_version', 'current_version.software_versions',
        'current_version.software_versions.software', 'parents'
    ]

    @calculated_property(
        schema={
            "title": "Pipelines",
            "type": "array",
            "items": {
                "type": 'string',
                "linkTo": "Pipeline",
            },
        })
    def pipelines(self, request, pipelines):
        return paths_filtered_by_status(request, pipelines)

    @calculated_property(
        schema={
            "title": "Current version",
            "type": "string",
            "linkTo": "AnalysisStepVersion",
        })
    def current_version(self, request, versions):
        version_objects = [
            request.embed(path, '@@object')
            for path in paths_filtered_by_status(request, versions)
        ]
        if version_objects:
            current = max(version_objects, key=lambda obj: obj['version'])
            return current['@id']

    @calculated_property(
        schema={
            "title": "Versions",
            "type": "array",
            "items": {
                "type": 'string',
                "linkTo": "AnalysisStepVersion",
            },
        })
    def versions(self, request, versions):
        return paths_filtered_by_status(request, versions)
Beispiel #28
0
class FileFormat(Item, ItemWithAttachment):
    """The class to store information about 4DN file formats"""
    item_type = 'file_format'
    schema = load_schema('encoded:schemas/file_format.json')
    name_key = 'file_format'

    @calculated_property(
        schema={
            "title": "Display Title",
            "description": "File Format name or extension.",
            "type": "string"
        })
    def display_title(self, file_format):
        return file_format
Beispiel #29
0
class AntibodyLot(SharedItem):
    item_type = 'antibody_lot'
    schema = load_schema('encoded:schemas/antibody_lot.json')
    name_key = 'accession'
    rev = {
        'characterizations': ('AntibodyCharacterization', 'characterizes'),
    }
    embedded = [
        'source', 'host_organism', 'targets', 'targets.organism',
        'characterizations.award', 'characterizations.documents',
        'characterizations.lab', 'characterizations.submitted_by',
        'characterizations.target.organism', 'lot_reviews.targets',
        'lot_reviews.targets.organism', 'lot_reviews.organisms'
    ]
    audit_inherit = [
        'source', 'host_organism', 'targets', 'targets.organism',
        'characterizations', 'characterizations.documents',
        'lot_reviews.targets', 'lot_reviews.targets.organism',
        'lot_reviews.organisms'
    ]

    def unique_keys(self, properties):
        keys = super(AntibodyLot, self).unique_keys(properties)
        source = properties['source']
        product_id = properties['product_id']
        lot_ids = [properties['lot_id']] + properties.get('lot_id_alias', [])
        values = (u'{}/{}/{}'.format(source, product_id, lot_id)
                  for lot_id in lot_ids)
        keys.setdefault('antibody_lot:source_product_lot', []).extend(values)
        return keys

    @calculated_property(schema={
        "title": "Title",
        "type": "string",
    })
    def title(self, accession):
        return accession

    @calculated_property(
        schema={
            "title": "Characterizations",
            "type": "array",
            "items": {
                "type": ['string', 'object'],
                "linkFrom": "AntibodyCharacterization.characterizes",
            },
        })
    def characterizations(self, request, characterizations):
        return paths_filtered_by_status(request, characterizations)
Beispiel #30
0
class StaticSection(UserContent):
    """The Software class that contains the software... used."""
    item_type = 'static_section'
    schema = load_schema('encoded:schemas/static_section.json')

    @calculated_property(
        schema={
            "title": "Content",
            "description": "Content for the page",
            "type": "string"
        })
    def content(self, request, body=None, file=None):

        if isinstance(body, str) or isinstance(body, dict) or isinstance(
                body, list):
            # Don't need to load in anything. We don't currently support dict/json body (via schema) but could in future.
            return body

        if isinstance(file, str):
            if file[0:4] == 'http' and '://' in file[4:8]:  # Remote File
                return get_remote_file_contents(file)
            else:  # Local File
                file_path = os.path.abspath(
                    os.path.dirname(os.path.realpath(__file__)) + "/../../.." +
                    file)  # Go to top of repo, append file
                return get_local_file_contents(file_path)

        return None

    @calculated_property(
        schema={
            "title": "File Type",
            "description": "Type of file used for content",
            "type": "string"
        })
    def filetype(self, request, body=None, file=None, options=None):
        if options and options.get('filetype') is not None:
            return options['filetype']
        if isinstance(body, str):
            return 'txt'
        if isinstance(body, dict) or isinstance(body, list):
            return 'json'
        if isinstance(file, str):
            filename_parts = file.split('.')
            if len(filename_parts) > 1:
                return filename_parts[len(filename_parts) - 1]
            else:
                return 'txt'  # Default if no file extension.
        return None
Beispiel #31
0
                "type" : "object"
            }
        },
        "value" : { # This is used in place of run_data.file, e.g. for a parameter string value, that does not actually have a file.
            "title" : "Value",
            "type" : "string",
            "description" : "Value used for this output argument."
        },
        "type" : {
            "type" : "string",
            "title" : "I/O Type"
        }
    }
}

workflow_schema = load_schema('encoded:schemas/workflow.json')
workflow_steps_property_schema = workflow_schema.get('properties', {}).get('steps')

# This is the schema used for WorkflowRun.steps. Extends Workflow.steps schema.
workflow_run_steps_property_schema = copy.deepcopy(workflow_steps_property_schema)
workflow_run_steps_property_schema['items']['properties']['inputs']['items']['properties']['run_data'] = steps_run_data_schema
workflow_run_steps_property_schema['items']['properties']['outputs']['items']['properties']['run_data'] = steps_run_data_schema


def get_unique_key_from_at_id(at_id):
    if not at_id:
        return None
    at_id_parts = at_id.split('/')
    return at_id_parts[2]