def test_ref_equals(): # statements are identical oldref = [ wdi_core.WDExternalID(value='P58742', prop_nr='P352'), wdi_core.WDItemID(value='Q24784025', prop_nr='P527'), wdi_core.WDTime('+2001-12-31T12:01:13Z', prop_nr='P813') ] olditem = wdi_core.WDItemID("Q123", "P123", references=[oldref]) newitem = copy.deepcopy(olditem) assert olditem.equals(newitem, include_ref=False) assert olditem.equals(newitem, include_ref=True) # dates are a month apart newitem = copy.deepcopy(olditem) newitem.references[0][2] = wdi_core.WDTime('+2002-1-31T12:01:13Z', prop_nr='P813') assert olditem.equals(newitem, include_ref=False) assert not olditem.equals(newitem, include_ref=True) # multiple refs newitem = copy.deepcopy(olditem) newitem.references.append( [wdi_core.WDExternalID(value='99999', prop_nr='P352')]) assert olditem.equals(newitem, include_ref=False) assert not olditem.equals(newitem, include_ref=True) olditem.references.append( [wdi_core.WDExternalID(value='99999', prop_nr='P352')]) assert olditem.equals(newitem, include_ref=True)
def create_reference(spl_url,source_type): timeStringNow = datetime.now().strftime("+%Y-%m-%dT00:00:00Z") archived_date = datetime.strptime('9/29/2015','%m/%d/%Y').strftime("+%Y-%m-%dT00:00:00Z") refStatedIn = wdi_core.WDItemID(value="Q73670648", prop_nr="P248", is_reference=True) refRetrieved = wdi_core.WDTime(timeStringNow, prop_nr="P813", is_reference=True) refRetrieved2 = wdi_core.WDTime(archived_date, prop_nr="P2960", is_reference=True) refURL = wdi_core.WDUrl(value=spl_url, prop_nr="P854", is_reference=True) reftype = wdi_core.WDString(value=source_type, prop_nr="P958", is_reference=True) return [refStatedIn, refRetrieved, refRetrieved2, refURL, reftype]
def create_reference(): refStatedIn = wdi_core.WDItemID(value="Q70116865", prop_nr="P248", is_reference=True) timeStringNow = datetime.now().strftime("+%Y-%m-%dT00:00:00Z") refRetrieved = wdi_core.WDTime(timeStringNow, prop_nr="P813", is_reference=True) refStatedIn2 = wdi_core.WDItemID(value="Q21008030", prop_nr="P248", is_reference=True) refRetrieved2 = wdi_core.WDTime(timeStringNow, prop_nr="P813", is_reference=True) return [refStatedIn, refRetrieved, refStatedIn2, refRetrieved2]
def task_processor(self, task, n): ref = [[ wdi_core.WDItemID(value=self.source, prop_nr='P248', is_reference=True), wdi_core.WDUrl(value=self.url_pattern + urllib.parse.quote_plus(str(task[1])), prop_nr='P854', is_reference=True), wdi_core.WDTime(task[2], prop_nr='P813', is_reference=True) ]] data = [] for cited_item in task[3]: data.append( wdi_core.WDItemID(value='Q' + str(cited_item), prop_nr='P2860', references=ref)) itemengine = self.integrator[n]['core'].WDItemEngine( wd_item_id='Q' + str(task[0]), data=data, append_value=self.append_value, good_refs=self.good_refs, keep_good_ref_statements=True) print( itemengine.write(self.integrator[n]['login'], edit_summary=self.edit_summary))
def make_ref(rxnorm): refs = [[ wdi_core.WDItemID(value='Q7383767', prop_nr='P248', is_reference=True), # stated in rxnorm wdi_core.WDExternalID(value=rxnorm, prop_nr='P3345', is_reference=True), # rxcui wdi_core.WDTime(time=time.strftime('+%Y-%m-%dT00:00:00Z'), prop_nr='P813', is_reference=True) # retrieved ]] return refs
def createNCBITaxReference(ncbiTaxId, retrieved): refStatedIn = wdi_core.WDItemID(value="Q13711410", prop_nr="P248", is_reference=True) timeStringNow = retrieved.strftime("+%Y-%m-%dT00:00:00Z") refRetrieved = wdi_core.WDTime(timeStringNow, prop_nr="P813", is_reference=True) refNcbiTaxID = wdi_core.WDString(value=ncbiTaxId, prop_nr="P685", is_reference=True) ncbi_reference = [refStatedIn, refRetrieved, refNcbiTaxID] return ncbi_reference
def create_reference(unii: str, url=None): """ Reference is: retrieved: date stated in: links to pmid items optional reference URL """ # ref = [ wdi_core.WDItemID(ITEMS['Inxight: Drugs Database'], PROPS['stated in'], is_reference=True) ] t = strftime("+%Y-%m-%dT00:00:00Z", gmtime()) ref.append( wdi_core.WDTime(t, prop_nr=PROPS['retrieved'], is_reference=True)) if unii: ref_url = "https://drugs.ncats.io/drug/{}".format(unii) ref.append( wdi_core.WDUrl(ref_url, PROPS['reference URL'], is_reference=True)) if url: for u in url: try: ref.append( wdi_core.WDUrl(u, PROPS['reference URL'], is_reference=True)) except Exception as e: print(e) print(u) return ref
def create_references(self, gdr): references = [] # Reference URL for phenocarta references.append( wdi_core.WDUrl(value=gdr.phenocarta_url, prop_nr=PROPS['reference URL'], is_reference=True)) # Reference URL for genome.gov references.append( wdi_core.WDUrl(value=gdr.link, prop_nr=PROPS['reference URL'], is_reference=True)) # Stated in Phenocarta references.append( wdi_core.WDItemID(value='Q22330995', prop_nr=PROPS['stated in'], is_reference=True)) # Stated in PubMed references.append( wdi_core.WDItemID(value=self.pmid_qid_map[gdr.pmid], prop_nr=PROPS['stated in'], is_reference=True)) # Date retrieved references.append( wdi_core.WDTime(strftime("+%Y-%m-%dT00:00:00Z", gmtime()), prop_nr=PROPS['retrieved'], is_reference=True)) return references
def make_ref(nui): refs = [[ wdi_core.WDItemID(value='Q21008030', prop_nr='P248', is_reference=True), # stated in ndfrt wdi_core.WDExternalID(value=nui, prop_nr='P2115', is_reference=True), # NDF-RT ID wdi_core.WDTime(time=time.strftime('+%Y-%m-%dT00:00:00Z'), prop_nr='P813', is_reference=True) # retrieved ]] return refs
def create_reference(omim, pmid, login=None): """ Reference is: retrieved: date stated in: links to pmid items optional reference URL """ # ref = [ wdi_core.WDItemID(ITEMS['MitoDB'], PROPS['curator'], is_reference=True) ] t = strftime("+%Y-%m-%dT00:00:00Z", gmtime()) ref.append( wdi_core.WDTime(t, prop_nr=PROPS['retrieved'], is_reference=True)) pmid_qid, _, success = PublicationHelper( ext_id=pmid, id_type='pmid', source="europepmc").get_or_create(login) if success is True: ref.append( wdi_core.WDItemID(pmid_qid, PROPS['stated in'], is_reference=True)) ref_url = "http://mitodb.com/symptoms.php?oid={}&symptoms=Show" ref.append( wdi_core.WDUrl(ref_url.format(omim), PROPS['reference URL'], is_reference=True)) return ref
def to_wikidata(self): refs = [[ wdi_core.WDItemID(value='Q278487', prop_nr='P248', is_reference=True), # stated in wdi_core.WDExternalID(value=self.cid, prop_nr='P662', is_reference=True), # source element wdi_core.WDTime(time=time.strftime('+%Y-%m-%dT00:00:00Z'), prop_nr='P813', is_reference=True) # retrieved ]] elements = {'P662': self.cid[3:]} data = [] for k, v in elements.items(): if not v: continue print('{}:'.format(k), v) if isinstance(v, list) or isinstance(v, set): for x in v: data.append( wdi_core.WDString(prop_nr=k, value=x, references=refs)) else: data.append( wdi_core.WDString(prop_nr=k, value=v, references=refs)) return data
def create_reference(source_str, evidence_level, login): """ Reference is: curator: Cancer Biomarkers database retrieved: date stated in: links to pmid items no reference URL """ reference = [ wdi_core.WDItemID(ITEMS['Cancer Biomarkers database'], PROPS['curator'], is_reference=True) ] t = strftime("+%Y-%m-%dT00:00:00Z", gmtime()) reference.append( wdi_core.WDTime(t, prop_nr=PROPS['retrieved'], is_reference=True)) for source in source_str.split(";"): if source.startswith("PMID:"): qid, _, success = wdi_helpers.PublicationHelper( source.replace("PMID:", ""), id_type="pmid", source="europepmc").get_or_create(login) if success: reference.append( wdi_core.WDItemID(qid, PROPS['stated in'], is_reference=True)) elif source in source_map: reference.append( wdi_core.WDItemID(source_map[source], PROPS['stated in'], is_reference=True)) else: print("unknown source: {}".format(source)) return reference
def create_ref_statement(self, doid): if not self.release: self.create_release() stated_in = wdi_core.WDItemID(value=self.release, prop_nr='P248', is_reference=True) ref_doid = wdi_core.WDExternalID(value=doid, prop_nr='P699', is_reference=True) ref_retrieved = wdi_core.WDTime(strftime("+%Y-%m-%dT00:00:00Z", gmtime()), prop_nr='P813', is_reference=True) do_reference = [stated_in, ref_retrieved, ref_doid] return do_reference
def createNCBIGeneReference(ncbiGeneId, retrieved): refStatedIn = wdi_core.WDItemID(value="Q20641742", prop_nr="P248", is_reference=True) timeStringNow = retrieved.strftime("+%Y-%m-%dT00:00:00Z") refRetrieved = wdi_core.WDTime(timeStringNow, prop_nr="P813", is_reference=True) refNcbiGeneID = wdi_core.WDString(value=ncbiGeneId, prop_nr="P351", is_reference=True) ncbi_reference = [refStatedIn, refRetrieved, refNcbiGeneID] return ncbi_reference
def createUniprotReference(uniprotId, retrieved): refStatedIn = wdi_core.WDItemID(value="Q905695", prop_nr="P248", is_reference=True) timeStringNow = retrieved.strftime("+%Y-%m-%dT00:00:00Z") refRetrieved = wdi_core.WDTime(timeStringNow, prop_nr="P813", is_reference=True) refUniprotID = wdi_core.WDString(value=uniprotId, prop_nr="P352", is_reference=True) reference = [refStatedIn, refRetrieved, refUniprotID] return reference
def create_ref_statement(emea_id, url): ref_url = wdi_core.WDUrl(url, prop_nr='P854', is_reference=True) ref_emea = wdi_core.WDExternalID(emea_id, 'P3637', is_reference=True) ref_retrieved = wdi_core.WDTime(strftime("+%Y-%m-%dT00:00:00Z", gmtime()), prop_nr='P813', is_reference=True) reference = [ref_emea, ref_url, ref_retrieved] return reference
def createMONDOReference(id): statedin = wdi_core.WDItemID("Q2", prop_nr="P6", is_reference=True) retrieved = datetime.now() timeStringNow = retrieved.strftime("+%Y-%m-%dT00:00:00Z") refRetrieved = wdi_core.WDTime(timeStringNow, prop_nr="P7", is_reference=True) mondoid = wdi_core.WDExternalID(id, prop_nr="P5", is_reference=True) return [statedin, refRetrieved, mondoid]
def create_qualifiers(date: datetime) -> List[Any]: ref_time_str = f'+{date.isoformat()}Z' point_in_time = wdi_core.WDTime(time=ref_time_str, prop_nr='P585', is_qualifier=True) determination_method = wdi_core.WDItemID(value='Q90878157', prop_nr="P459", is_qualifier=True) return [point_in_time, determination_method]
def create_ref_statement(self): assert self.graph.release_qid, "create the release first (on the graph class)" stated_in = wdi_core.WDItemID(value=self.graph.release_qid, prop_nr=self.helper.get_pid('P248'), is_reference=True) ref_extid = wdi_core.WDExternalID(value=self.id_value, prop_nr=self.id_pid, is_reference=True) ref_retrieved = wdi_core.WDTime(strftime("+%Y-%m-%dT00:00:00Z", gmtime()), prop_nr=self.helper.get_pid('P813'), is_reference=True) reference = [stated_in, ref_retrieved, ref_extid] return reference
def create_reference(genbank_id): stated_in = wdi_core.WDItemID(ITEMS['GenBank'], PROPS['stated in'], is_reference=True) retrieved = wdi_core.WDTime(strftime("+%Y-%m-%dT00:00:00Z", gmtime()), PROPS['retrieved'], is_reference=True) url = "https://www.ncbi.nlm.nih.gov/genome/?term={}".format(genbank_id) ref_url = wdi_core.WDUrl(url, PROPS['reference URL'], is_reference=True) return [stated_in, retrieved, ref_url]
def make_go_ref(curator, pmid_map, external_id, uniprot_id, evidence_wdid, retrieved, pmid=None): # initialize this reference for this evidence code with retrieved reference = [ wdi_core.WDTime(retrieved.strftime('+%Y-%m-%dT00:00:00Z'), prop_nr='P813', is_reference=True) ] # stated in pmid if pmid: if pmid in pmid_map: reference.append( wdi_core.WDItemID(pmid_map[pmid], 'P248', is_reference=True)) else: raise ValueError( "article item for pmid {} not found. skipping item".format( pmid)) # stated in uniprot-GOA Q28018111 reference.append(wdi_core.WDItemID('Q28018111', 'P248', is_reference=True)) # curator if curator in curators_wdids: reference.append( wdi_core.WDItemID(curators_wdids[curator], 'P1640', is_reference=True)) # curator-specific reference URLs # If curator is SGD, add external ID to ref if curator in curator_ref and curator_ref[curator] in external_id: reference.append( wdi_core.WDString(external_id[curator_ref[curator]], PROPS[curator_ref[curator]], is_reference=True)) else: raise ValueError("curator not found: {}".format(curator)) # reference URL # ref_url = "http://www.ebi.ac.uk/QuickGO/GAnnotation?protein={}".format(uniprot_id) ref_url = "http://www.ebi.ac.uk/QuickGO/annotations?protein={}&geneProductId=UniProtKB:{}".format( uniprot_id, uniprot_id) reference.append(wdi_core.WDString(ref_url, 'P854', is_reference=True)) # ref determination method reference.append( wdi_core.WDItemID(evidence_wdid, 'P459', is_reference=True)) return reference
def create_reference(ghr_url): refStatedIn = wdi_core.WDItemID(value="Q62606821", prop_nr="P248", is_reference=True) timeStringNow = datetime.now().strftime("+%Y-%m-%dT00:00:00Z") refRetrieved = wdi_core.WDTime(timeStringNow, prop_nr="P813", is_reference=True) refURL = wdi_core.WDUrl(value=ghr_url, prop_nr="P854", is_reference=True) return [refStatedIn, refRetrieved, refURL]
def create_reference(): refStatedIn = wdi_core.WDItemID(value="Q64403342", prop_nr="P248", is_reference=True) timeStringNow = datetime.now().strftime("+%Y-%m-%dT00:00:00Z") refRetrieved = wdi_core.WDTime(timeStringNow, prop_nr="P813", is_reference=True) refURL = wdi_core.WDUrl((df.loc[index, 'Report Reference URL']), prop_nr="P854", is_reference=True) return [refStatedIn, refRetrieved, refURL]
def buildRefs(refseq): refs = [ wdi_core.WDItemID(value="Q7307074", prop_nr='P248', is_reference=True) ] refs.append( wdi_core.WDTime("+2018-09-12T00:00:00Z", prop_nr='P813', is_reference=True)) refs.append( wdi_core.WDExternalID(value=refseq, prop_nr='P2249', is_reference=True)) return refs
def create_reference(): """Create references for an item.""" stated_in = wdi_core.WDItemID(ITEMS['Schools Portal'], PROPS['stated in'], is_reference=True) retrieved = wdi_core.WDTime(strftime("+%Y-%m-%dT00:00:00Z", gmtime()), PROPS['retrieved'], is_reference=True) url = "http://dati.istruzione.it/opendata/opendata/catalogo/elements1/?area=Scuole" ref_url = wdi_core.WDUrl(url, PROPS['reference URL'], is_reference=True) return [stated_in, retrieved, ref_url]
def create_reference(self): """ Reference is: retrieved: date stated in: links to pmid items no reference URL """ # Drug Indications Extracted from FAERS (Q56863002) ref = [wdi_core.WDItemID("Q56863002", PROPS['stated in'], is_reference=True)] t = strftime("+%Y-%m-%dT00:00:00Z", gmtime()) ref.append(wdi_core.WDTime(t, prop_nr=PROPS['retrieved'], is_reference=True)) self.refs = [ref]
def create_qualifier(start_time: datetime): q = [] if start_time: q.append( wdi_core.WDTime(start_time.strftime('+%Y-%m-%dT00:00:00Z'), PROPS['start time'], is_qualifier=True)) q.append( wdi_core.WDItemID(ITEMS['Food and Drug Administration'], PROPS['approved by'], is_qualifier=True)) return q
def create_reference(dbsnp_id): refStatedIn = wdi_core.WDItemID(value="Q5243761", prop_nr="P248", is_reference=True) retrieved = datetime.datetime.now() timeStringNow = retrieved.strftime("+%Y-%m-%dT00:00:00Z") refRetrieved = wdi_core.WDTime(timeStringNow, prop_nr="P813", is_reference=True) refDbSNP = wdi_core.WDString(value=dbsnp_id, prop_nr="P6861", is_reference=True) return [refStatedIn, refRetrieved, refDbSNP]
def make_ref(mesh_id): refs = [[ wdi_core.WDItemID(value=ITEMS['Medical Subject Headings'], prop_nr='P248', is_reference=True), # stated in mesh wdi_core.WDExternalID(value=mesh_id, prop_nr=PROPS['MeSH ID'], is_reference=True), # mesh id wdi_core.WDTime(time=time.strftime('+%Y-%m-%dT00:00:00Z'), prop_nr='P813', is_reference=True) # retrieved ]] return refs
def create_ref_statement(release_qid, external_prop_id, external_id): stated_in = wdi_core.WDItemID(value=release_qid, prop_nr='P248', is_reference=True) ref_external_id = wdi_core.WDExternalID(value=external_id, prop_nr=external_prop_id, is_reference=True) ref_retrieved = wdi_core.WDTime(strftime("+%Y-%m-%dT00:00:00Z", gmtime()), prop_nr='P813', is_reference=True) do_reference = [stated_in, ref_retrieved, ref_external_id] return do_reference