Download Bioinformatics Toolbox User's Guide

Transcript
Get Information from Web Database
9
Use the urlread function to submit the search URL, retrieve the search results,
and return the results (as text in the MEDLINE report type) in medlineText, a
character array.
medlineText = urlread(searchURL);
10 Use the MATLAB regexp function and regular expressions to parse and extract
the information in medlineText into hits, a cell array, where each cell contains
the MEDLINE-formatted text for one article. The first input is the character array
to search, the second input is a search expression, which tells the regexp function
to find all records that start with PMID-, while the third input, 'match', tells
the regexp function to return the actual records, rather than the positions of the
records.
hits = regexp(medlineText,'PMID-.*?(?=PMID|</pre>$)','match');
11 Instantiate the pmstruct structure returned by getpubmed to contain six fields.
pmstruct = struct('PubMedID','','PublicationDate','','Title','',...
'Abstract','','Authors','','Citation','');
12 Use the MATLAB regexp function and regular expressions to loop through each
article in hits and extract the PubMed ID, publication date, title, abstract, authors,
and citation. Place this information in the pmstruct structure array.
for n = 1:numel(hits)
pmstruct(n).PubMedID = regexp(hits{n},'(?<=PMID- ).*?(?=\n)','match', 'once');
pmstruct(n).PublicationDate = regexp(hits{n},'(?<=DP - ).*?(?=\n)','match', 'once');
pmstruct(n).Title = regexp(hits{n},'(?<=TI - ).*?(?=PG -|AB -)','match', 'once');
pmstruct(n).Abstract = regexp(hits{n},'(?<=AB - ).*?(?=AD -)','match', 'once');
pmstruct(n).Authors = regexp(hits{n},'(?<=AU - ).*?(?=\n)','match');
pmstruct(n).Citation = regexp(hits{n},'(?<=SO - ).*?(?=\n)','match', 'once');
end
13 Select File > Save As.
When you are done, your file should look similar to the getpubmed.m file included
with the Bioinformatics Toolbox software. The sample getpubmed.m file, including
help, is located at:
matlabroot\toolbox\bioinfo\biodemos\getpubmed.m
Note: The notation matlabroot is the MATLAB root directory, which is the
directory where the MATLAB software is installed on your system.
1-31