edu.iastate.jtm.jmed
Class PubMedFetcher

java.lang.Object
  extended by edu.iastate.jtm.jmed.PubMedFetcher

public class PubMedFetcher
extends java.lang.Object

Retrive abstracts from Medline given a list of PMIDs or last query's history.

Author:
Jing Ding

Field Summary
static Limits GET_FASTA
           
static Limits GET_XML
           
 
Constructor Summary
PubMedFetcher()
          Create a new instance of PubMedFetcher with default buffer size.
PubMedFetcher(int size)
          Create a new instance of PubMedFetcher with specified buffer size.
PubMedFetcher(MedlineParser pmp)
          Create a new instance of PubMedFetcher with default buffer size and a specified MedlineParser.
PubMedFetcher(java.lang.String tool, java.lang.String email)
          Create a new instance of PubMedFetcher with a tool name and email address.
 
Method Summary
 void fetchFasta(java.io.File gifile, java.io.File outfile)
           
 void fetchPlain(java.io.File listfile, java.io.File outDir)
          Fetch abstracts given PMIDs in a file.
 void fetchPlain(java.io.File listfile, java.lang.String outDir, int size)
          Fetch abstracts given a PMID file.
 void fetchPlain(Limits history, java.io.File outDir)
          Fetch abstracts given a query history.
 void fetchPlain(Limits history, java.lang.String outDir, int size)
          Fetch abstracts given a query history.
 void fetchPlain(java.lang.String[] pmidList, int listSize, java.io.File outDir)
          Fetch abstracts given a list of PMIDs.
 void fetchPlain(java.lang.String[] pmidList, int listSize, java.lang.String outDir, int size)
          Fetch abstracts given a list of PMIDs.
 java.io.InputStream fetchStream(Limits limits)
          Retrieve abstracts from query history.
 java.io.InputStream fetchStream(java.lang.String[] pmids)
           
 java.io.InputStream fetchStream(java.lang.String[] pmids, int offset, int count)
           
 java.io.InputStream fetchStream(java.lang.String[] pmids, int offset, int count, Limits limits)
           
 java.io.InputStream fetchStream(java.lang.String[] pmids, Limits limits)
           
 void fetchXml(java.io.File listfile, java.io.File output, boolean compress)
          Fetch abstracts given PMIDs in a file.
 void fetchXml(java.io.File listfile, java.lang.String output, int size, boolean compress)
          Fetch abstracts given a PMID file.
 void fetchXml(Limits history, java.io.File output, boolean compress)
          Fetch abstracts given a query history.
 void fetchXml(Limits history, java.lang.String output, int size, boolean compress)
          Fetch abstracts given a query history.
 void fetchXml(java.lang.String[] pmidList, int listSize, java.io.File output, boolean compress)
          Fetch abstracts given a list of PMIDs.
 void fetchXml(java.lang.String[] pmidList, int listSize, java.lang.String output, int size, boolean compress)
          Fetch abstracts given a list of PMIDs.
static java.lang.String[] getPmidFromFile(java.lang.String pfile)
          Read PMID list from a file.
static void main(java.lang.String[] args)
           
 void outputStream(java.io.InputStream stream, java.io.Writer writer)
           
 void setDatabase(int db)
           
 void setParser(MedlineParser p)
          Set the fetcher's parser.
 void setVerbose(boolean v)
          Set verbose mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GET_XML

public static final Limits GET_XML

GET_FASTA

public static final Limits GET_FASTA
Constructor Detail

PubMedFetcher

public PubMedFetcher()
Create a new instance of PubMedFetcher with default buffer size.


PubMedFetcher

public PubMedFetcher(int size)
Create a new instance of PubMedFetcher with specified buffer size.

Parameters:
size - buffer size

PubMedFetcher

public PubMedFetcher(MedlineParser pmp)
Create a new instance of PubMedFetcher with default buffer size and a specified MedlineParser.

Parameters:
pmp - MedlineParser

PubMedFetcher

public PubMedFetcher(java.lang.String tool,
                     java.lang.String email)
Create a new instance of PubMedFetcher with a tool name and email address. They are useful for PubMed's statistics, have no effect on fetching abstracts.

Parameters:
tool - applicaiton name
email - email address
Method Detail

setDatabase

public void setDatabase(int db)

setParser

public void setParser(MedlineParser p)
Set the fetcher's parser.

Parameters:
p - the parser

setVerbose

public void setVerbose(boolean v)
Set verbose mode.

Parameters:
v - whether or not show more info

getPmidFromFile

public static java.lang.String[] getPmidFromFile(java.lang.String pfile)
                                          throws java.io.IOException
Read PMID list from a file.

Parameters:
pfile - the PMID file.
Returns:
the array of PMIDs.
Throws:
java.io.IOException

fetchXml

public void fetchXml(java.io.File listfile,
                     java.io.File output,
                     boolean compress)
              throws java.io.IOException,
                     org.dom4j.DocumentException
Fetch abstracts given PMIDs in a file. Write output to a file in XML format.

Parameters:
listfile - input PMID file
output - output file
compress - compress output files
Throws:
java.io.IOException
org.dom4j.DocumentException

fetchXml

public void fetchXml(java.io.File listfile,
                     java.lang.String output,
                     int size,
                     boolean compress)
              throws java.io.IOException,
                     org.dom4j.DocumentException
Fetch abstracts given a PMID file. Write output to multiple files in XML format.

Parameters:
listfile - the PMID file
output - prefix of output files
size - number of abstracts per file
compress - compress output files
Throws:
java.io.IOException
org.dom4j.DocumentException

fetchXml

public void fetchXml(java.lang.String[] pmidList,
                     int listSize,
                     java.io.File output,
                     boolean compress)
              throws java.io.IOException,
                     org.dom4j.DocumentException
Fetch abstracts given a list of PMIDs. Write output to a file in XML format.

Parameters:
pmidList - the array of PMIDs
listSize - effective size of the array (may smaller than its actual size)
output - output file
compress - compress output files
Throws:
java.io.IOException
org.dom4j.DocumentException

fetchXml

public void fetchXml(java.lang.String[] pmidList,
                     int listSize,
                     java.lang.String output,
                     int size,
                     boolean compress)
              throws java.io.IOException,
                     org.dom4j.DocumentException
Fetch abstracts given a list of PMIDs. Write output to multiple files in XML format

Parameters:
pmidList - the list of PMIDs
listSize - effective size of the list (may be smaller than its actual size)
output - prefix of output files
size - number of abstracts per file
compress - compress output files
Throws:
java.io.IOException
org.dom4j.DocumentException

fetchXml

public void fetchXml(Limits history,
                     java.io.File output,
                     boolean compress)
              throws org.xml.sax.SAXException,
                     java.io.IOException
Fetch abstracts given a query history. Write them to a file in XML format.

Parameters:
history - the query history
output - the output file
compress - compress output files
Throws:
org.xml.sax.SAXException
java.io.IOException

fetchXml

public void fetchXml(Limits history,
                     java.lang.String output,
                     int size,
                     boolean compress)
              throws org.xml.sax.SAXException,
                     org.dom4j.DocumentException,
                     java.io.IOException
Fetch abstracts given a query history. Write output to multiple files in XML format.

Parameters:
history - the query history
output - prefix of output files
size - number of abstracts per file
compress - compress output files
Throws:
org.xml.sax.SAXException
org.dom4j.DocumentException
java.io.IOException

fetchPlain

public void fetchPlain(java.io.File listfile,
                       java.io.File outDir)
                throws java.io.IOException,
                       org.dom4j.DocumentException,
                       org.xml.sax.SAXException
Fetch abstracts given PMIDs in a file. Write them to a directory in plain text format.

Parameters:
listfile - the input file of PMIDs
outDir - output directory
Throws:
java.io.IOException
org.dom4j.DocumentException
org.xml.sax.SAXException

fetchPlain

public void fetchPlain(java.io.File listfile,
                       java.lang.String outDir,
                       int size)
                throws java.io.IOException,
                       org.dom4j.DocumentException,
                       org.xml.sax.SAXException
Fetch abstracts given a PMID file. Write output to multiple directories in plain text format.

Parameters:
listfile - the PMID file
outDir - prefix of output directories
size - number of abstracts per directory
Throws:
java.io.IOException
org.dom4j.DocumentException
org.xml.sax.SAXException

fetchPlain

public void fetchPlain(java.lang.String[] pmidList,
                       int listSize,
                       java.io.File outDir)
                throws java.io.IOException,
                       org.dom4j.DocumentException,
                       org.xml.sax.SAXException
Fetch abstracts given a list of PMIDs. Write them to a directory in plain text format.

Parameters:
pmidList - the list of PMIDs
listSize - effective size of the PMID array (may be smaller than its actual size
outDir - output directory
Throws:
java.io.IOException
org.dom4j.DocumentException
org.xml.sax.SAXException

fetchPlain

public void fetchPlain(java.lang.String[] pmidList,
                       int listSize,
                       java.lang.String outDir,
                       int size)
                throws java.io.IOException,
                       org.dom4j.DocumentException,
                       org.xml.sax.SAXException
Fetch abstracts given a list of PMIDs. Write output to multiple directories in plain text format.

Parameters:
pmidList - the list of PMIDs
listSize - effective list size (may be smaller than its actual size)
outDir - prefix of output directories
size - number of abstracts per directory
Throws:
java.io.IOException
org.dom4j.DocumentException
org.xml.sax.SAXException

fetchPlain

public void fetchPlain(Limits history,
                       java.io.File outDir)
                throws org.xml.sax.SAXException,
                       org.dom4j.DocumentException,
                       java.io.IOException
Fetch abstracts given a query history. Write them to a directory in plain text format.

Parameters:
history - the query history
outDir - output directory
Throws:
org.xml.sax.SAXException
org.dom4j.DocumentException
java.io.IOException

fetchPlain

public void fetchPlain(Limits history,
                       java.lang.String outDir,
                       int size)
                throws org.dom4j.DocumentException,
                       java.io.IOException,
                       org.xml.sax.SAXException
Fetch abstracts given a query history. Write them to multiple directories in plain text format.

Parameters:
history - the query history
outDir - prefix of output directories
size - number of abstracts per directory
Throws:
org.dom4j.DocumentException
java.io.IOException
org.xml.sax.SAXException

fetchFasta

public void fetchFasta(java.io.File gifile,
                       java.io.File outfile)
                throws java.io.IOException
Throws:
java.io.IOException

fetchStream

public java.io.InputStream fetchStream(java.lang.String[] pmids,
                                       Limits limits)
                                throws java.io.IOException
Throws:
java.io.IOException

fetchStream

public java.io.InputStream fetchStream(java.lang.String[] pmids)
                                throws java.io.IOException
Throws:
java.io.IOException

fetchStream

public java.io.InputStream fetchStream(java.lang.String[] pmids,
                                       int offset,
                                       int count)
                                throws java.io.IOException
Throws:
java.io.IOException

fetchStream

public java.io.InputStream fetchStream(java.lang.String[] pmids,
                                       int offset,
                                       int count,
                                       Limits limits)
                                throws java.io.IOException
Throws:
java.io.IOException

fetchStream

public java.io.InputStream fetchStream(Limits limits)
                                throws java.io.IOException
Retrieve abstracts from query history. No limit on number of abstracts.

Parameters:
limits - containing query history.
ps - output destination (may be null).
Returns:
stream containing the retrieved abstracts. Null if already written to ps.
Throws:
java.io.IOException

outputStream

public void outputStream(java.io.InputStream stream,
                         java.io.Writer writer)
                  throws java.io.IOException
Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)
Parameters:
args - the command line arguments