Example #1
0
 def __init__(self, obj_json):
     UpdateByJsonMixin.__init__(self, obj_json)
     self.format_name = str(obj_json.get('parent_id')) + ' - ' + str(obj_json.get('child_id'))
     self.display_name = str(obj_json.get('parent_id')) + ' - ' + str(obj_json.get('child_id'))
     if self.relation_type is not None:
         self.format_name = self.format_name + ' - ' + self.relation_type
         self.display_name = self.display_name + ' - ' + self.relation_type
Example #2
0
 def __init__(self, obj_json):
     UpdateByJsonMixin.__init__(self, obj_json)
     if self.format_name is None:
         self.format_name = self.genbank_accession
     if self.display_name is None:
         self.display_name = self.genbank_accession
     self.link = None if self.format_name is None else '/contig/' + self.format_name + '/overview'
Example #3
0
 def __init__(self, obj_json):
     UpdateByJsonMixin.__init__(self, obj_json)
     if self.display_name == 'observable':
         self.display_name = 'Yeast Phenotype Ontology'
         self.format_name = 'ypo'
         self.link = '/ontology/phenotype/ypo/overview'
     else:
         self.format_name = create_format_name(self.display_name.lower())
         self.link = '/observable/' + self.format_name + '/overview'
Example #4
0
 def to_min_json(self, include_description=False):
     obj_json = UpdateByJsonMixin.to_min_json(self, include_description=include_description)
     obj_json['length'] = len(self.residues)
     obj_json['is_chromosome'] = True if self.is_chromosome == 1 else False
     obj_json['centromere_start'] = self.centromere_start
     obj_json['centromere_end'] = self.centromere_end
     return obj_json
Example #5
0
 def to_json(self):
     obj_json = UpdateByJsonMixin.to_json(self)
     new_obj_json = {'id': obj_json['id']}
     for key, value in obj_json.iteritems():
         if key != 'id':
             new_obj_json[key] = value == 1
     return new_obj_json
Example #6
0
    def convert(self, newly_created_obj):
        if self.commit_interval is not None and (self.added_count + self.updated_count + self.deleted_count) % self.commit_interval == 0:
            self.session.commit()

        if newly_created_obj is None:
            self.none_count += 1
            return 'None'
        key = newly_created_obj.unique_key()
        if key not in self.keys_already_seen:
            self.keys_already_seen.add(key)
            current_obj_json = None if key not in self.key_to_current_obj_json else self.key_to_current_obj_json[key]
            newly_created_obj_json = UpdateByJsonMixin.to_json(newly_created_obj)
            if current_obj_json is None:
                if newly_created_obj.id in self.current_obj_ids:
                    current_obj_by_id = self.current_obj_query(self.session).filter_by(id=newly_created_obj.id).first()
                    self.session.delete(current_obj_by_id)
                self.session.add(newly_created_obj)
                self.added_count += 1
                return 'Added'
            elif newly_created_obj.compare(current_obj_json):
                current_obj = self.current_obj_query(self.session).filter_by(id=current_obj_json['id']).first()
                if current_obj is not None:
                    current_obj.update(newly_created_obj_json)
                    self.updated_count += 1
                    return 'Updated'
                else:
                    self.error_count += 1
                    return 'Error'
            else:
                self.no_change_count += 1
                return 'No Change'
        else:
            self.duplicate_count += 1
            return 'Duplicate'
Example #7
0
 def to_json(self):
     obj_json = UpdateByJsonMixin.to_json(self)
     obj_json['reference'] = None if self.reference is None else self.reference.to_json()
     obj_json['datasetcolumns'] = [x.to_min_json() for x in self.datasetcolumns]
     obj_json['tags'] = [x.tag.to_min_json() for x in self.bioitem_tags]
     obj_json['urls'] = [x.to_min_json() for x in self.urls]
     return obj_json
Example #8
0
 def to_json(self):
     obj_json = UpdateByJsonMixin.to_json(self)
     obj_json["references"] = [x.reference.to_min_json() for x in self.alias_references]
     if self.category in {
         "PDB identifier",
         "UniParc ID",
         "UniProtKB/Swiss-Prot ID",
         "UniProtKB/TrEMBL ID",
         "UniProtKB Subcellular Location",
         "Protein version ID",
         "EC number",
         "InterPro ID",
         "RefSeq protein version ID",
         "RefSeq nucleotide version ID",
         "TPA protein version ID",
         "DNA version ID",
         "protein GI",
         "TPA Accession ID",
         "PDB ID",
         "RefSeq Accession ID",
         "TC number",
         "PANTHER",
     }:
         obj_json["protein"] = True
     else:
         obj_json["protein"] = False
     return obj_json
Example #9
0
 def __init__(self, obj_json):
     UpdateByJsonMixin.__init__(self, obj_json)
     if self.display_name == 'biological_process':
         self.display_name = 'biological process'
         self.link = '/ontology/go/biological_process/overview'
         self.format_name = 'biological_process'
     elif self.display_name == 'molecular_function':
         self.display_name = 'molecular function'
         self.link = '/ontology/go/molecular_function/overview'
         self.format_name = 'molecular_function'
     elif self.display_name == 'cellular_component':
         self.display_name = 'cellular component'
         self.link = '/ontology/go/cellular_component/overview'
         self.format_name = 'cellular_component'
     elif self.go_id is not None:
         self.link = '/go/' + self.go_id + '/overview'
         self.format_name = self.go_id
Example #10
0
    def to_json(self):
        obj_json = UpdateByJsonMixin.to_json(self)
        obj_json['locus_count'] = self.locus_count
        obj_json['descendant_locus_count'] = self.descendant_locus_count

        obj_json['urls'] = [x.to_json() for x in sorted(self.urls, key=lambda x: x.display_name)]
        obj_json['aliases'] = [x.display_name for x in sorted(self.aliases, key=lambda x: x.display_name)]
        return obj_json
Example #11
0
    def to_json(self):
        obj_json = UpdateByJsonMixin.to_json(self)
        id_to_reference = dict()
        id_to_reference.update(
            [
                (x.reference_id, x.reference)
                for x in self.go_evidences
                if x.reference_id not in id_to_reference and x.reference_id is not None
            ]
        )
        id_to_reference.update(
            [
                (x.reference_id, x.reference)
                for x in self.geninteraction_evidences
                if x.reference_id not in id_to_reference and x.reference_id is not None
            ]
        )
        id_to_reference.update(
            [
                (x.reference_id, x.reference)
                for x in self.physinteraction_evidences
                if x.reference_id not in id_to_reference and x.reference_id is not None
            ]
        )
        id_to_reference.update(
            [
                (x.reference_id, x.reference)
                for x in self.phenotype_evidences
                if x.reference_id not in id_to_reference and x.reference_id is not None
            ]
        )
        id_to_reference.update(
            [
                (x.reference_id, x.reference)
                for x in self.regulation_evidences
                if x.reference_id not in id_to_reference and x.reference_id is not None
            ]
        )
        id_to_reference.update(
            [
                (x.reference_id, x.reference)
                for x in self.binding_evidences
                if x.reference_id not in id_to_reference and x.reference_id is not None
            ]
        )
        id_to_reference.update(
            [
                (x.reference_id, x.reference)
                for x in self.proteinexperiment_evidences
                if x.reference_id not in id_to_reference and x.reference_id is not None
            ]
        )

        obj_json["references"] = [
            x.to_semi_json()
            for x in sorted(id_to_reference.values(), key=lambda x: (x.year, x.date_published), reverse=True)
        ]
        return obj_json
Example #12
0
    def to_json(self):
        obj_json = UpdateByJsonMixin.to_json(self)

        #Phenotype overview
        phenotype_evidences = []
        for phenotype in self.phenotypes:
            phenotype_evidences.extend(phenotype.phenotype_evidences)

        classical_groups = dict()
        large_scale_groups = dict()
        strain_groups = dict()
        for evidence in phenotype_evidences:
            if evidence.experiment.category == 'classical genetics':
                if evidence.mutant_type in classical_groups:
                    classical_groups[evidence.mutant_type] += 1
                else:
                    classical_groups[evidence.mutant_type] = 1
            elif evidence.experiment.category == 'large-scale survey':
                if evidence.mutant_type in large_scale_groups:
                    large_scale_groups[evidence.mutant_type] += 1
                else:
                    large_scale_groups[evidence.mutant_type] = 1

            if evidence.strain is not None:
                if evidence.strain.display_name in strain_groups:
                    strain_groups[evidence.strain.display_name] += 1
                else:
                    strain_groups[evidence.strain.display_name] = 1
        experiment_categories = []
        mutant_types = set(classical_groups.keys())
        mutant_types.update(large_scale_groups.keys())
        for mutant_type in mutant_types:
            experiment_categories.append([mutant_type, 0 if mutant_type not in classical_groups else classical_groups[mutant_type], 0 if mutant_type not in large_scale_groups else large_scale_groups[mutant_type]])

        strains = []
        for strain, count in strain_groups.iteritems():
            strains.append([strain, count])
        experiment_categories.sort(key=lambda x: x[1] + x[2], reverse=True)
        experiment_categories.insert(0, ['Mutant Type', 'classical genetics', 'large-scale survey'])
        strains.sort(key=lambda x: x[1], reverse=True)
        strains.insert(0, ['Strain', 'Annotations'])
        obj_json['overview'] = {'experiment_categories': experiment_categories,
                                          'strains': strains}

        #Phenotypes
        obj_json['phenotypes'] = []
        for phenotype in self.phenotypes:
            phenotype_json = phenotype.to_min_json()
            phenotype_json['qualifier'] = phenotype.qualifier
            obj_json['phenotypes'].append(phenotype_json)

        #Counts
        obj_json['locus_count'] = self.locus_count
        obj_json['descendant_locus_count'] = self.descendant_locus_count

        return obj_json
Example #13
0
 def to_semi_json(self):
     obj_json = UpdateByJsonMixin.to_min_json(self)
     obj_json['pcl_filename'] = self.pcl_filename
     obj_json['geo_id'] = self.geo_id
     obj_json['short_description'] = self.short_description
     obj_json['condition_count'] = self.condition_count
     obj_json['reference'] = None if self.reference is None else self.reference.to_min_json()
     obj_json['tags'] = [x.tag.to_min_json() for x in self.bioitem_tags]
     obj_json['display_name'] = self.display_name.replace('.', '. ')
     return obj_json
Example #14
0
 def to_json(self, linkit=False):
     obj_json = UpdateByJsonMixin.to_json(self)
     obj_json["references"] = sorted(
         [x.reference.to_semi_json() for x in self.paragraph_references],
         key=lambda x: (x["year"], x["pubmed_id"]),
         reverse=True,
     )
     if linkit:
         obj_json["text"] = obj_json["html"]
     del obj_json["html"]
     return obj_json
Example #15
0
 def to_json(self):
     obj_json = UpdateByJsonMixin.to_json(self)
     obj_json['references'] = [x.reference.to_min_json() for x in self.alias_references]
     if self.category in {'PDB identifier', 'UniParc ID', 'UniProt/Swiss-Prot ID', 'UniProt/TrEMBL ID',
         'UniProtKB Subcellular Location', 'Protein version ID', 'EC number', 'InterPro', 'RefSeq protein version ID',
         'RefSeq nucleotide version ID', 'TPA protein version ID', 'DNA version ID', 'NCBI protein GI', 'TPA Accession',
         'PDB ID', 'RefSeq Accession', 'TC number', 'PANTHER'}:
         obj_json['protein'] = True
     else:
         obj_json['protein'] = False
     return obj_json
Example #16
0
    def to_json(self):
        obj_json = UpdateByJsonMixin.to_json(self)
        overview_counts = {}
        for evidence in [x for x in self.dnasequence_evidences if x.dna_type== 'GENOMIC']:
            if x.locus.bioent_status == 'Active':
                if evidence.locus.locus_type in overview_counts:
                    overview_counts[evidence.locus.locus_type] += 1
                else:
                    overview_counts[evidence.locus.locus_type] = 1

        obj_json['overview'] = [
            ['Feature Type', 'Count']]

        for locus_type in locus_types:
            obj_json['overview'].append([locus_type, (0 if locus_type not in overview_counts else overview_counts[locus_type])])

        obj_json['urls'] = [x.to_min_json() for x in self.urls]

        return obj_json
Example #17
0
    def to_json(self):
        obj_json = UpdateByJsonMixin.to_json(self)
        obj_json['abstract'] = None if len(self.paragraphs) == 0 else self.paragraphs[0].to_json(linkit=True)
        obj_json['bibentry'] = None if self.bibentry is None else self.bibentry.text
        obj_json['reftypes'] = [x.reftype.to_min_json() for x in self.ref_reftypes]
        obj_json['authors'] = [x.author.to_min_json() for x in self.author_references]
        interaction_locus_ids = set()
        interaction_locus_ids.update([x.locus1_id for x in self.physinteraction_evidences])
        interaction_locus_ids.update([x.locus2_id for x in self.physinteraction_evidences])
        interaction_locus_ids.update([x.locus1_id for x in self.geninteraction_evidences])
        interaction_locus_ids.update([x.locus2_id for x in self.geninteraction_evidences])
        regulation_locus_ids = set()
        regulation_locus_ids.update([x.locus1_id for x in self.regulation_evidences])
        regulation_locus_ids.update([x.locus2_id for x in self.regulation_evidences])
        obj_json['urls'] = [x.to_min_json() for x in self.urls]
        obj_json['counts'] = {
            'interaction': len(interaction_locus_ids),
            'go': len(set([x.locus_id for x in self.go_evidences])),
            'phenotype': len(set([x.locus_id for x in self.phenotype_evidences])),
            'regulation': len(regulation_locus_ids)
        }
        obj_json['related_references'] = []
        for child in self.children:
            child_json = child.child.to_semi_json()
            child_json['abstract'] = None if len(child.child.paragraphs) == 0 else child.child.paragraphs[0].to_json(linkit=True)
            child_json['reftypes'] = [x.reftype.to_min_json() for x in child.child.ref_reftypes]
            obj_json['related_references'].append(child_json)
        for parent in self.parents:
            parent_json = parent.parent.to_semi_json()
            parent_json['abstract'] = None if len(parent.parent.paragraphs) == 0 else parent.parent.paragraphs[0].to_json(linkit=True)
            parent_json['reftypes'] = [x.reftype.to_min_json() for x in parent.parent.ref_reftypes]
            obj_json['related_references'].append(parent_json)
        obj_json['urls'] = [x.to_json() for x in self.urls]
        if self.journal is not None:
            obj_json['journal']['med_abbr'] = self.journal.med_abbr

        id_to_dataset = {}
        for expression_evidence in self.expression_evidences:
            if expression_evidence.datasetcolumn.dataset_id not in id_to_dataset:
                id_to_dataset[expression_evidence.datasetcolumn.dataset_id] = expression_evidence.datasetcolumn.dataset
        obj_json['expression_datasets'] = [x.to_semi_json() for x in id_to_dataset.values()]
        return obj_json
Example #18
0
 def __init__(self, session_maker, current_obj_query, name=None, commit_interval=None, commit=False, delete_untouched=False, already_deleted=0):
     self.session = session_maker()
     self.current_obj_query = current_obj_query
     self.name = name
     self.commit_interval = commit_interval
     self.commit = commit
     self.delete_untouched = delete_untouched
     self.key_to_current_obj_json = dict()
     self.current_obj_ids = set()
     for obj in current_obj_query(self.session):
         self.key_to_current_obj_json[obj.unique_key()] = UpdateByJsonMixin.to_json(obj)
         self.current_obj_ids.add(obj.id)
     self.keys_already_seen = set()
     self.none_count = 0
     self.added_count = 0
     self.updated_count = 0
     self.no_change_count = 0
     self.duplicate_count = 0
     self.error_count = 0
     self.deleted_count = already_deleted
Example #19
0
 def __init__(self, obj_json):
     UpdateByJsonMixin.__init__(self, obj_json)
     self.format_name = str(obj_json.get("parent_id")) + " - " + str(obj_json.get("child_id"))
     self.display_name = str(obj_json.get("parent_id")) + " - " + str(obj_json.get("child_id"))
Example #20
0
 def __init__(self, obj_json):
     UpdateByJsonMixin.__init__(self, obj_json)
     self.format_name = create_format_name(obj_json.get('display_name'))
     if obj_json.get('eco_id') in eco_id_to_category:
         self.category = eco_id_to_category[obj_json.get('eco_id')]
Example #21
0
 def __init__(self, obj_json):
     UpdateByJsonMixin.__init__(self, obj_json)
     self.format_name = obj_json['strain'].format_name
Example #22
0
 def __init__(self, obj_json):
     UpdateByJsonMixin.__init__(self, obj_json)
     self.format_name = str(obj_json.get('experiment_id'))
Example #23
0
 def __init__(self, obj_json):
     UpdateByJsonMixin.__init__(self, obj_json)
     self.format_name = str(obj_json.get('parent_id')) + ' - ' + str(obj_json.get('child_id'))
     self.display_name = str(obj_json.get('parent_id')) + ' - ' + str(obj_json.get('child_id'))
Example #24
0
 def to_json(self):
     obj_json = UpdateByJsonMixin.to_json(self)
     obj_json['references'] = [x.reference.to_min_json() for x in self.quality_references]
     return obj_json
Example #25
0
    def to_json(self):
        obj_json = UpdateByJsonMixin.to_json(self)

        # Phenotype overview
        phenotype_paragraphs = [x.to_json() for x in self.paragraphs if x.category == "PHENOTYPE"]
        classical_groups = dict()
        large_scale_groups = dict()
        strain_groups = dict()
        for evidence in self.phenotype_evidences:
            if evidence.experiment.category == "classical genetics":
                if evidence.mutant_type in classical_groups:
                    if evidence.phenotype_id not in classical_groups[evidence.mutant_type]:
                        classical_groups[evidence.mutant_type][evidence.phenotype_id] = evidence.phenotype
                else:
                    classical_groups[evidence.mutant_type] = {evidence.phenotype_id: evidence.phenotype}
            elif evidence.experiment.category == "large-scale survey":
                if evidence.mutant_type in large_scale_groups:
                    if evidence.phenotype_id not in large_scale_groups[evidence.mutant_type]:
                        large_scale_groups[evidence.mutant_type][evidence.phenotype_id] = evidence.phenotype
                else:
                    large_scale_groups[evidence.mutant_type] = {evidence.phenotype_id: evidence.phenotype}

            if evidence.strain is not None:
                if evidence.strain.display_name in strain_groups:
                    strain_groups[evidence.strain.display_name] += 1
                else:
                    strain_groups[evidence.strain.display_name] = 1
        experiment_categories = []
        mutant_types = set(classical_groups.keys())
        mutant_types.update(large_scale_groups.keys())
        for mutant_type in mutant_types:
            experiment_categories.append(
                [
                    mutant_type,
                    0 if mutant_type not in classical_groups else len(classical_groups[mutant_type]),
                    0 if mutant_type not in large_scale_groups else len(large_scale_groups[mutant_type]),
                ]
            )
        strains = []
        for strain, count in strain_groups.iteritems():
            strains.append([strain, count])
        experiment_categories.sort(key=lambda x: x[1] + x[2], reverse=True)
        experiment_categories.insert(0, ["Mutant Type", "classical genetics", "large-scale survey"])
        strains.sort(key=lambda x: x[1], reverse=True)
        strains.insert(0, ["Strain", "Annotations"])
        obj_json["phenotype_overview"] = {
            "paragraph": None if len(phenotype_paragraphs) == 0 else phenotype_paragraphs[0]["text"],
            "experiment_categories": experiment_categories,
            "strains": strains,
            "classical_phenotypes": dict(
                [(x, [phenotype.to_min_json() for phenotype in y.values()]) for x, y in classical_groups.iteritems()]
            ),
            "large_scale_phenotypes": dict(
                [(x, [phenotype.to_min_json() for phenotype in y.values()]) for x, y in large_scale_groups.iteritems()]
            ),
        }

        # Go overview
        man_mf = dict()
        man_bp = dict()
        man_cc = dict()
        htp_mf = dict()
        htp_bp = dict()
        htp_cc = dict()
        for evidence in self.go_evidences:
            goterm = evidence.go
            ev_json = None
            if goterm.go_aspect == "molecular function" and evidence.annotation_type == "manually curated":
                if goterm.id not in man_mf:
                    man_mf[goterm.id] = {"term": goterm.to_min_json(), "evidence_codes": [], "qualifiers": []}
                ev_json = man_mf[goterm.id]

            elif goterm.go_aspect == "molecular function" and evidence.annotation_type == "high-throughput":
                if goterm.id not in htp_mf:
                    htp_mf[goterm.id] = {"term": goterm.to_min_json(), "evidence_codes": [], "qualifiers": []}
                ev_json = htp_mf[goterm.id]

            elif goterm.go_aspect == "biological process" and evidence.annotation_type == "manually curated":
                if goterm.id not in man_bp:
                    man_bp[goterm.id] = {"term": goterm.to_min_json(), "evidence_codes": [], "qualifiers": []}
                ev_json = man_bp[goterm.id]

            elif goterm.go_aspect == "biological process" and evidence.annotation_type == "high-throughput":
                if goterm.id not in htp_bp:
                    htp_bp[goterm.id] = {"term": goterm.to_min_json(), "evidence_codes": [], "qualifiers": []}
                ev_json = htp_bp[goterm.id]

            elif goterm.go_aspect == "cellular component" and evidence.annotation_type == "manually curated":
                if goterm.id not in man_cc:
                    man_cc[goterm.id] = {"term": goterm.to_min_json(), "evidence_codes": [], "qualifiers": []}
                ev_json = man_cc[goterm.id]

            elif goterm.go_aspect == "cellular component" and evidence.annotation_type == "high-throughput":
                if goterm.id not in htp_cc:
                    htp_cc[goterm.id] = {"term": goterm.to_min_json(), "evidence_codes": [], "qualifiers": []}
                ev_json = htp_cc[goterm.id]

            if ev_json is not None:
                if evidence.experiment_id is not None:
                    evidence_code_ids = [x["id"] for x in ev_json["evidence_codes"]]
                    if evidence.experiment_id not in evidence_code_ids:
                        ev_json["evidence_codes"].append(evidence.experiment.to_min_json())
                if evidence.qualifier is not None:
                    qualifiers = ev_json["qualifiers"]
                    if evidence.qualifier not in qualifiers:
                        ev_json["qualifiers"].append(evidence.qualifier)

        go_date_paragraphs = [x.to_json() for x in self.paragraphs if x.category == "GODATE"]
        go_paragraphs = [x.to_json() for x in self.paragraphs if x.category == "GO"]

        obj_json["go_overview"] = {
            "paragraph": None if len(go_paragraphs) == 0 else go_paragraphs[0]["text"],
            "go_slim": sorted(
                dict(
                    [
                        (x.id, x.to_min_json())
                        for x in chain(
                            *[
                                [x.parent for x in y.go.parents if x.relation_type == "GO_SLIM"]
                                for y in self.go_evidences
                            ]
                        )
                    ]
                ).values(),
                key=lambda x: x["display_name"].lower(),
            ),
            "date_last_reviewed": None if len(go_date_paragraphs) == 0 else go_date_paragraphs[0]["text"],
            "computational_annotation_count": len(
                [x for x in self.go_evidences if x.annotation_type == "computational"]
            ),
            "manual_molecular_function_terms": sorted(man_mf.values(), key=lambda x: x["term"]["display_name"].lower()),
            "manual_biological_process_terms": sorted(man_bp.values(), key=lambda x: x["term"]["display_name"].lower()),
            "manual_cellular_component_terms": sorted(man_cc.values(), key=lambda x: x["term"]["display_name"].lower()),
            "htp_molecular_function_terms": sorted(htp_mf.values(), key=lambda x: x["term"]["display_name"].lower()),
            "htp_biological_process_terms": sorted(htp_bp.values(), key=lambda x: x["term"]["display_name"].lower()),
            "htp_cellular_component_terms": sorted(htp_cc.values(), key=lambda x: x["term"]["display_name"].lower()),
        }

        # Interaction
        genetic_interactions = set()
        physical_interactions = set()
        genetic_interactions.update(self.geninteraction_evidences1)
        genetic_interactions.update(self.geninteraction_evidences2)
        physical_interactions.update(self.physinteraction_evidences1)
        physical_interactions.update(self.physinteraction_evidences2)

        genetic_bioentities = set(
            [x.locus2_id if x.locus1_id == self.id else x.locus1_id for x in genetic_interactions]
        )
        physical_bioentities = set(
            [x.locus2_id if x.locus1_id == self.id else x.locus1_id for x in physical_interactions]
        )

        A = len(genetic_bioentities)
        B = len(physical_bioentities)
        C = len(genetic_bioentities & physical_bioentities)
        r, s, x = calc_venn_measurements(A, B, C)

        physical_experiments = dict()
        genetic_experiments = dict()
        experiment_id_to_name = dict()

        for genevidence in genetic_interactions:
            experiment_id = genevidence.experiment_id
            if experiment_id not in experiment_id_to_name:
                experiment_id_to_name[experiment_id] = genevidence.experiment.display_name
            experiment_name = experiment_id_to_name[experiment_id]

            if experiment_name not in genetic_experiments:
                genetic_experiments[experiment_name] = 1
            else:
                genetic_experiments[experiment_name] += 1

        for physevidence in physical_interactions:
            experiment_id = physevidence.experiment_id
            if experiment_id not in experiment_id_to_name:
                experiment_id_to_name[experiment_id] = physevidence.experiment.display_name
            experiment_name = experiment_id_to_name[experiment_id]

            if experiment_name not in physical_experiments:
                physical_experiments[experiment_name] = 1
            else:
                physical_experiments[experiment_name] += 1

        obj_json["interaction_overview"] = {
            "gen_circle_size": r,
            "phys_circle_size": s,
            "circle_distance": x,
            "num_gen_interactors": A,
            "num_phys_interactors": B,
            "num_both_interactors": C,
            "total_interactions": len(genetic_interactions) + len(physical_interactions),
            "total_interactors": len(genetic_bioentities | physical_bioentities),
            "physical_experiments": physical_experiments,
            "genetic_experiments": genetic_experiments,
        }
        # Regulation
        regulation_paragraphs = [x.to_json(linkit=True) for x in self.paragraphs if x.category == "REGULATION"]

        obj_json["regulation_overview"] = {
            "target_count": len(set([x.locus2_id for x in self.regulation_evidences_targets])),
            "regulator_count": len(set([x.locus1_id for x in self.regulation_evidences_regulators])),
            "paragraph": None if len(regulation_paragraphs) == 0 else regulation_paragraphs[0],
        }

        # Literature
        reference_ids = set([x.reference_id for x in self.literature_evidences])
        reference_ids.update([x.reference_id for x in self.geninteraction_evidences1])
        reference_ids.update([x.reference_id for x in self.geninteraction_evidences2])
        reference_ids.update([x.reference_id for x in self.physinteraction_evidences1])
        reference_ids.update([x.reference_id for x in self.physinteraction_evidences2])
        reference_ids.update([x.reference_id for x in self.regulation_evidences_targets])
        reference_ids.update([x.reference_id for x in self.regulation_evidences_regulators])
        obj_json["literature_overview"] = {
            "total_count": len(reference_ids),
            "primary_count": len(
                set([x.reference_id for x in self.literature_evidences if x.topic == "Primary Literature"])
            ),
            "additional_count": len(
                set([x.reference_id for x in self.literature_evidences if x.topic == "Additional Literature"])
            ),
            "review_count": len(set([x.reference_id for x in self.literature_evidences if x.topic == "Reviews"])),
        }

        # Sequence
        obj_json["sequence_overview"] = sorted(
            dict([(x.strain.id, x.strain.to_min_json()) for x in self.dnasequence_evidences]).values(),
            key=lambda x: x["display_name"],
        )

        reference_protein_sequence = None
        for protein_sequence in self.proteinsequence_evidences:
            if protein_sequence.strain_id == 1:
                reference_protein_sequence = protein_sequence
        # Protein
        obj_json["protein_overview"] = {
            "length": None if reference_protein_sequence is None else len(reference_protein_sequence.residues) - 1,
            "molecular_weight": None
            if reference_protein_sequence is None
            else reference_protein_sequence.molecular_weight,
            "pi": None if reference_protein_sequence is None else reference_protein_sequence.pi,
        }

        # Aliases
        obj_json["aliases"] = [x.to_json() for x in self.aliases]

        # Urls
        obj_json["urls"] = [
            x.to_json()
            for x in sorted(self.urls, key=lambda x: x.display_name)
            if x.category is not None and x.category != "NONE"
        ]

        lsp_paragraphs = [x.to_json(linkit=True) for x in self.paragraphs if x.category == "LSP"]
        obj_json["paragraph"] = None if len(lsp_paragraphs) == 0 else lsp_paragraphs[0]

        # History
        note_to_evidences = dict()
        for historyevidence in self.history_evidences:
            if historyevidence.note in note_to_evidences:
                note_to_evidences[historyevidence.note].append(historyevidence)
            else:
                note_to_evidences[historyevidence.note] = [historyevidence]

        historyevidences = []
        for note, evidences in note_to_evidences.iteritems():
            evidence_json = evidences[0].to_json()
            del evidence_json["reference"]
            evidence_json["references"] = [
                x.reference.to_min_json()
                for x in sorted(evidences, key=lambda y: None if y.reference is None else y.reference.year)
                if x.reference_id is not None
            ]
            historyevidences.append(evidence_json)

        obj_json["history"] = historyevidences

        obj_json["paralogs"] = [x.to_json() for x in self.children if x.relation_type == "paralog"]

        obj_json["qualities"] = dict([(x.display_name.lower().replace(" ", "_"), x.to_json()) for x in self.qualities])

        ordered_references = self.get_ordered_references()
        obj_json["references"] = [x.to_semi_json() for x in ordered_references]
        reference_mapping = {}
        for reference in ordered_references:
            reference_mapping[reference.id] = len(reference_mapping) + 1

        obj_json["reference_mapping"] = reference_mapping

        if self.reserved_name is not None:
            obj_json["reserved_name"] = self.reserved_name.to_json()

        obj_json["pathways"] = [x.to_json() for x in self.pathway_evidences]

        obj_json["ecnumbers"] = (
            None if len(self.ecnumber_evidences) == 0 else [x.ecnumber.to_min_json() for x in self.ecnumber_evidences]
        )

        return obj_json
Example #26
0
 def __init__(self, obj_json):
     UpdateByJsonMixin.__init__(self, obj_json)
     self.link = None if obj_json.get("sgdid") is None else "/locus/" + self.sgdid + "/overview"
Example #27
0
 def to_semi_json(self):
     obj_json = UpdateByJsonMixin.to_min_json(self)
     obj_json["description"] = self.description
     return obj_json
Example #28
0
 def to_json(self):
     obj_json = UpdateByJsonMixin.to_json(self)
     obj_json['references'] = [x.reference.to_min_json() for x in self.relation_references]
     obj_json['child'] = self.child.to_min_json()
     obj_json['parent'] = self.parent.to_min_json()
     return obj_json
Example #29
0
 def __init__(self, obj_json):
     UpdateByJsonMixin.__init__(self, obj_json)
     self.format_name = str(obj_json.get("bioentity_id"))
Example #30
0
 def __init__(self, obj_json):
     UpdateByJsonMixin.__init__(self, obj_json)