Example #1
0
 def doi_article(ref, user=None):
     article_array = []
     fetch = PubMedFetcher()
     for doi in Reference.doi(ref):
         article = fetch.article_by_doi(doi)
         article_array.append(article)
     return article
Example #2
0
 def doi_article(ref, user=None):
     article_array = []
     fetch = PubMedFetcher()
     for doi in Reference.doi(ref):
         article = fetch.article_by_doi(doi)
         article_array.append(article)
     return article
Example #3
0
def get_info_by_DOI(DOI: str) -> Dict:
    '''This function takes a DOI str, requests information about the corresponding
	article via metapub or crossref and checks if all necessary information has been retrieved.'''
    article_dict = {}
    fetch = PubMedFetcher()
    try:
        article = fetch.article_by_doi(DOI)
        # Save information in Dict
        for info in dir(article):
            if info[0] != '_':
                article_dict[info] = eval('article.' + info)
        # Add data retrieval info to the dict
        article_dict = add_retrieval_information(article_dict, 'MetaPub',
                                                 'DOI', DOI)
    except MetaPubError:
        # If it does not work via Metapub, do it via Crossref Api
        # If there is a timeout, try again (5 times)
        for _ in range(5):
            try:
                works = Works()
                article_dict = works.doi(DOI)
                break
            except:
                pass
        #article_dict = normalize_crossref_dict(article_dict)
        # Add data retrieval info to the dict
        #if contains_minimal_information(article_dict):
        article_dict = add_retrieval_information(article_dict, 'Crossref',
                                                 'DOI', DOI)
    return article_dict
Example #4
0
def fetch_pubmed(pub_id, id_type = "pmid"):
    """
        Fetches and formats pub data from
        pubmed
    """
    pm = PubMedFetcher()
    if id_type == 'doi':
        try:
            result = pm.article_by_doi(pub_id)
        except (AttributeError, MetaPubError, EutilsNCBIError):
            return None
    elif id_type == "pmid":
        try:
            result = pm.article_by_pmid(pub_id)
        except (AttributeError, InvalidPMID, EutilsNCBIError):
            return None
    elif id_type == "pmc":
        try:
            result = pm.article_by_pmcid('PMC' + str(pub_id))
        except (AttributeError, MetaPubError, EutilsNCBIError):
            return None
    result = result.to_dict()

    # Set link using DOI
    if result.get('doi'):
        result['url'] = "http://dx.doi.org/" + result.get('doi')
    else:
        result['url'] = result.get('url')

    # Provide PDF if possible
    if result.get('pmc'):
        result['pdf_url'] = f"https://www.ncbi.nlm.nih.gov/pmc/articles/PMC{result['pmc']}/pdf"
    

    out = {"pub_title": result.get('title'),
           "pub_authors": result.get('authors'),
           "pub_abstract": result.get('abstract'),
           "pub_doi": result.get('doi'),
           "pub_pmid": result.get('pmid'),
           "pub_pmc": pub_id if id_type == 'pmc' else None,
           "pub_url": result.get('url'),
           "pub_pdf_url": result.get('pdf_url') or 'searching',
           "pub_journal": result.get('journal'),
           "pub_date": result['history'].get('pubmed')}
    return out
Example #5
0
def search(entry):
    fetch = PubMedFetcher()
    try:
        article = fetch.article_by_pmid(entry['pmid'])
    except:
        try:
            article = fetch.article_by_pmcid(entry['pmcid'])
        except:
            try:
                article = fetch.article_by_doi(entry['doi'])
            except:
                try:
                    pmids = fetch.pmids_for_citation(authors=entry['author'], journal=entry['journal'], year=entry['year'], volume=entry['volume'])
                    # pmids2 = fetch.pmids_for_query(entry['title'])
                    article = fetch.article_by_pmid(pmids[0])
                except:
                    return None
    return article
Example #6
0
    def handle(self, *args, **options):
        csvfile = "pmids.csv"
        with open(csvfile, 'rU') as f:
            reader = csv.reader(f)

            count = 0
            for row in reader:
                pmid = self.get_pmid(row)

                if count == 0:
                    count += 1
                    continue #skip first header row
                if Publication.objects.filter(pmid=pmid).count() > 0:
                    count += 1
                    continue
                if count == 3000: break
                ref_id = row[0]
                ref_type = row[1]

                year = row[3]
                article_title = row[4]
                secondary_author = row[5]
                journal_title = row[6]
                place_published = row[7]
                publisher = row[8]
                volume = row[9]
                issue = row[10]
                pages = row[11]
                date = row[12] #bad data in csv, don't use...
                alt_journal = row[13]
                doi = self.get_doi(row)
                print doi
                #pmid_from_ref = row[15]
                #pmid_from_updates = row[16]

                abstract = row[17]


                url = row[18]
                file_attachments = row[19]
                author_address_from_pubmed = row[20] #empty column
                figure = row[21]
                cis_acc = row[22]
                access_date = row[23]
                luminex_product = row[24]
                db_name = row[25]
                db_provider = row[26]
                language = row[27]
                reprint_author_name = row[28]
                blank = row[29]
                reprint_author_email = row[30]



                ecopy = row[39]
                paper_type = row[40]
                species = row[41]
                assay = row[42]
                sample_type = row[43] #this is the article title...
                whos_kit = row[44]
                misc = row[45]
                application = row[46]
                market_segment = row[47]
                subsidiary_author = row[48]
                custom_6 = row[49]

                issn = row[51]


                pub = Publication(
                    title=sample_type,
                    pmid=pmid,
                    doi=doi,
                    abstract=abstract,
                )
                fresh_data = None
                if len(pmid) < 1:
                    fetch = PubMedFetcher()
                    try:
                        fresh_data = fetch.article_by_doi(doi)
                        fresh_data = fresh_data.to_dict()
                    except:
                        pass
                    else:
                        pub.pmid = fresh_data['pmid']

                pub.save()
                self.add_cis_tags(pub, row)
                authors = self.get_authors(row)
                for author in authors:
                    pub.authors.add(author)
                lab = self.get_lab(row)

                if lab:
                    for author in authors:
                        author.labs.add(lab)
                    pub.labs.add(lab)




                count += 1