pubmed/functions.py
def download_pubmed(pmids,download_folder,ftp=None):
    """download_pubmed
    Download full text of articles with pubmed ids pmids to folder
        pmids: 
            list of pubmed ids to download
        download_folder: 
            destination folder
        ftp: 
            pandas data frame of pubmed ftp. If not provided,
            will be obtained and read programatically. If this function is
            being run in a cluster environment, it is recommended to save
            this ftp object, and read in from file for the function.
    """

    # If no ftp object is provided, retrieve it
    if ftp == None:
        ftp = get_ftp()

    if isinstance(pmids,str):
        pmids = [pmids]
    
    subset = pandas.DataFrame(columns=ftp.columns)
    for p in pmids:
        row = ftp.loc[ftp.index[ftp.PMCID == p]]
        subset = subset.append(row)
    
    # Now for each, assemble the URL
    for row in subset.iterrows():
        url = "ftp://ftp.ncbi.nlm.nih.gov/pub/pmc/%s" % (row[1]["URL"])
        download_place = "%s/" %(download_folder)
        basename = os.path.basename(row[1]["URL"])
        if not os.path.isfile("%s/%s" %(download_folder,basename)):
            print "Downloading %s" % (url)       
            os.system("wget \"%s\" -P %s" % (url,download_place))
download_pubmed
    Download full text of articles with pubmed ids pmids to folder
        pmids: 
            list of pubmed ids to download
        download_folder: 
            destination folder
        ftp: 
            pandas data frame of pubmed ftp. If not provided,
            will be obtained and read programatically. If this function is
            being run in a cluster environment, it is recommended to save
            this ftp object, and read in from file for the function.
    
download_pubmed
Download full text of articles with pubmed ids pmids to folder
pmids:
list of pubmed ids to download
download_folder:
destination folder
ftp:
pandas data frame of pubmed ftp. If not provided,
will be obtained and read programatically. If this function is
being run in a cluster environment, it is recommended to save
this ftp object, and read in from file for the function.
download_pubmed Download full text of articles with pubmed ids pmids to folder pmids : list of pubmed ids to download download_folder : destination folder ftp : pandas data frame of pubmed ftp . If not provided will be obtained and read programatically . If this function is being run in a cluster environment it is recommended to save this ftp object and read in from file for the function .
def download_pubmed(pmids,download_folder,ftp=None):
    if ftp == None:
        ftp = get_ftp()
    if isinstance(pmids,str):
        pmids = [pmids]
    subset = pandas.DataFrame(columns=ftp.columns)
    for p in pmids:
        row = ftp.loc[ftp.index[ftp.PMCID == p]]
        subset = subset.append(row)
    for row in subset.iterrows():
        url = "ftp://ftp.ncbi.nlm.nih.gov/pub/pmc/%s" % (row[1]["URL"])
        download_place = "%s/" %(download_folder)
        basename = os.path.basename(row[1]["URL"])
        if not os.path.isfile("%s/%s" %(download_folder,basename)):
            print "Downloading %s" % (url)       
            os.system("wget \"%s\" -P %s" % (url,download_place))
def download_pubmed ( pmids , download_folder , ftp = None ) : if ftp == None : ftp = get_ftp ( ) if isinstance ( pmids , str ) : pmids = [ pmids ] subset = pandas . DataFrame ( columns = ftp . columns ) for p in pmids : row = ftp . loc [ ftp . index [ ftp . PMCID == p ] ] subset = subset . append ( row ) for row in subset . iterrows ( ) : url = "ftp://ftp.ncbi.nlm.nih.gov/pub/pmc/%s" % ( row [ 1 ] [ "URL" ] ) download_place = "%s/" % ( download_folder ) basename = os . path . basename ( row [ 1 ] [ "URL" ] ) if not os . path . isfile ( "%s/%s" % ( download_folder , basename ) ) : print "Downloading %s" % ( url ) os . system ( "wget \"%s\" -P %s" % ( url , download_place ) )
download_pubmed
Download full text of articles with pubmed ids pmids to folder
pmids:
list of pubmed ids to download
download_folder:
destination folder
ftp:
pandas data frame of pubmed ftp.
download_pubmed Download full text of articles with pubmed ids pmids to folder pmids : list of pubmed ids to download download_folder : destination folder ftp : pandas data frame of pubmed ftp .
"""download_pubmed
    Download full text of articles with pubmed ids pmids to folder
        pmids: 
            list of pubmed ids to download
        download_folder: 
            destination folder
        ftp: 
            pandas data frame of pubmed ftp. If not provided,
            will be obtained and read programatically. If this function is
            being run in a cluster environment, it is recommended to save
            this ftp object, and read in from file for the function.
    """ # If no ftp object is provided, retrieve it # Now for each, assemble the URL
pmids
download_folder
ftp