com.hfg.citation.ncbi.MedlineCitation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com_hfg Show documentation
Show all versions of com_hfg Show documentation
com.hfg xml, html, svg, and bioinformatics utility library
package com.hfg.citation.ncbi;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.hfg.bio.seq.format.SeqCitation;
import com.hfg.citation.Author;
import com.hfg.citation.Journal;
import com.hfg.util.BooleanUtil;
import com.hfg.util.StringUtil;
import com.hfg.util.collection.CollectionUtil;
import com.hfg.xml.XMLTag;
//------------------------------------------------------------------------------
/**
Data object for holding MEDLINE citation data.
See:
https://www.nlm.nih.gov/bsd/licensee/elements_descriptions.html
@author J. Alex Taylor, hairyfatguy.com
*/
//------------------------------------------------------------------------------
// com.hfg XML/HTML Coding Library
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
// [email protected]
//------------------------------------------------------------------------------
// TODO: Parse ReferenceList
public class MedlineCitation extends SeqCitation
{
private MedlineCitationStatus mStatus;
private String mOwner;
private Date mDateCompleted;
private Date mDateRevised;
private List mMeshHeadings;
private List mReferences;
//###########################################################################
// CONSTRUCTORS
//###########################################################################
//---------------------------------------------------------------------------
public MedlineCitation()
{
}
//---------------------------------------------------------------------------
public MedlineCitation(XMLTag inXMLTag)
{
inXMLTag.verifyTagName(PubmedXML.MEDLINE_CITATION);
String statusString = inXMLTag.getAttributeValue(PubmedXML.STATUS_ATT);
if (StringUtil.isSet(statusString))
{
setStatus(MedlineCitationStatus.valueOf(statusString));
}
setOwner(inXMLTag.getAttributeValue(PubmedXML.OWNER_ATT));
XMLTag dateCompletedTag = inXMLTag.getOptionalSubtagByName(PubmedXML.DATE_COMPLETED);
if (dateCompletedTag != null)
{
setDateCompleted(parseDateTag(dateCompletedTag));
}
XMLTag dateRevisedTag = inXMLTag.getOptionalSubtagByName(PubmedXML.DATE_REVISED);
if (dateRevisedTag != null)
{
setDateRevised(parseDateTag(dateRevisedTag));
}
XMLTag articleTag = inXMLTag.getOptionalSubtagByName(PubmedXML.ARTICLE);
if (articleTag != null)
{
XMLTag journalTag = articleTag.getOptionalSubtagByName(PubmedXML.JOURNAL);
if (journalTag != null)
{
XMLTag issnTag = journalTag.getOptionalSubtagByName(PubmedXML.ISSN);
if (issnTag != null)
{
setISSN(issnTag.getContent().trim());
}
XMLTag journalIssueTag = journalTag.getOptionalSubtagByName(PubmedXML.JOURNAL_ISSUE);
if (journalIssueTag != null)
{
XMLTag volumeTag = journalIssueTag.getOptionalSubtagByName(PubmedXML.VOLUME);
if (volumeTag != null)
{
setVolume(volumeTag.getContent());
}
XMLTag issueTag = journalIssueTag.getOptionalSubtagByName(PubmedXML.ISSUE);
if (issueTag != null)
{
setIssue(issueTag.getContent());
}
XMLTag pubDateTag = journalIssueTag.getOptionalSubtagByName(PubmedXML.PUB_DATE);
if (pubDateTag != null)
{
setYear(Integer.parseInt(pubDateTag.getRequiredSubtagByName(PubmedXML.YEAR).getContent()));
}
}
XMLTag titleTag = journalTag.getOptionalSubtagByName(PubmedXML.TITLE);
if (titleTag != null)
{
Journal journal = new Journal(titleTag.getContent().trim())
.setISSN(getISSN());
XMLTag abbrevTag = journalTag.getOptionalSubtagByName(PubmedXML.ISO_ABBREVIATION);
if (abbrevTag != null)
{
journal.setAbbrev(abbrevTag.getContent().trim());
}
setJournal(journal);
}
}
XMLTag articleTitleTag = articleTag.getOptionalSubtagByName(PubmedXML.ARTICLE_TITLE);
if (articleTitleTag != null)
{
String title = articleTitleTag.getContent().trim();
if (title.endsWith("."))
{
title = title.substring(0, title.length() - 1);
}
setTitle(title);
}
XMLTag paginationTag = articleTag.getOptionalSubtagByName(PubmedXML.PAGINATION);
if (paginationTag != null)
{
setPages(paginationTag.getRequiredSubtagByName(PubmedXML.MEDLINE_PGN).getContent());
}
XMLTag eLocationIdTag = articleTag.getOptionalSubtagByName(PubmedXML.E_LOCATION_ID);
if (eLocationIdTag != null)
{
if (eLocationIdTag.getAttributeValue(PubmedXML.E_ID_TYPE_ATT).equals("doi"))
{
setDOI(eLocationIdTag.getContent());
}
}
XMLTag abstractTag = articleTag.getOptionalSubtagByName(PubmedXML.ABSTRACT);
if (abstractTag != null)
{
setAbstract(abstractTag.getRequiredSubtagByName(PubmedXML.ABSTRACT_TEXT).getContent().trim());
}
XMLTag authorListTag = articleTag.getOptionalSubtagByName(PubmedXML.AUTHOR_LIST);
if (authorListTag != null)
{
List authorTags = authorListTag.getSubtagsByName(PubmedXML.AUTHOR);
for (XMLTag authorTag : authorTags)
{
String firstName = authorTag.getRequiredSubtagByName(PubmedXML.FORE_NAME).getContent();
String lastName = authorTag.getRequiredSubtagByName(PubmedXML.LAST_NAME).getContent();
Author author = new Author((StringUtil.isSet(firstName) ? firstName : "") + " " + lastName);
// TODO: Affiliation
addAuthor(author);
}
}
XMLTag lagnuageTag = articleTag.getOptionalSubtagByName(PubmedXML.LANGUAGE);
if (lagnuageTag != null)
{
setLanguage(lagnuageTag.getContent().trim());
}
}
// MeshHeadings (Keywords)
XMLTag meshHeadingList = inXMLTag.getOptionalSubtagByName(PubmedXML.MESH_HEADING_LIST);
if (meshHeadingList != null)
{
List meshHeadingTags = meshHeadingList.getSubtagsByName(PubmedXML.MESH_HEADING);
if (CollectionUtil.hasValues(meshHeadingTags))
{
for (XMLTag meshHeadingTag : meshHeadingTags)
{
XMLTag descriptorNameTag = meshHeadingTag.getRequiredSubtagByName(PubmedXML.DESCRIPTOR_NAME);
MeshHeading meshHeading = new MeshHeading(descriptorNameTag.getContent().trim())
.setUniqueIdentifier(descriptorNameTag.getAttributeValue(PubmedXML.UI_ATT))
.setIsMajorTopic(BooleanUtil.valueOf(descriptorNameTag.getAttributeValue(PubmedXML.MAJOR_TOPIC_YN_ATT)));
List meshQualifierTags = meshHeadingTag.getSubtagsByName(PubmedXML.QUALIFIER_NAME);
if (CollectionUtil.hasValues(meshQualifierTags))
{
for (XMLTag meshQualifierTag : meshQualifierTags)
{
MeshQualifier meshQualifier = new MeshQualifier(meshQualifierTag.getContent().trim())
.setUniqueIdentifier(meshQualifierTag.getAttributeValue(PubmedXML.UI_ATT))
.setIsMajorTopic(BooleanUtil.valueOf(meshQualifierTag.getAttributeValue(PubmedXML.MAJOR_TOPIC_YN_ATT)));
meshHeading.addQualifier(meshQualifier);
}
}
addMeshHeading(meshHeading);
}
}
}
}
//###########################################################################
// PUBLIC METHODS
//###########################################################################
//---------------------------------------------------------------------------
public MedlineCitation setStatus(MedlineCitationStatus inValue)
{
mStatus = inValue;
return this;
}
//---------------------------------------------------------------------------
public MedlineCitationStatus getStatus()
{
return mStatus;
}
//---------------------------------------------------------------------------
public MedlineCitation setOwner(String inValue)
{
mOwner = inValue;
return this;
}
//---------------------------------------------------------------------------
public String getOwner()
{
return mOwner;
}
//---------------------------------------------------------------------------
public MedlineCitation setDateCompleted(Date inValue)
{
mDateCompleted = inValue;
return this;
}
//---------------------------------------------------------------------------
public Date getDateCompleted()
{
return mDateCompleted;
}
//---------------------------------------------------------------------------
public MedlineCitation setDateRevised(Date inValue)
{
mDateRevised = inValue;
return this;
}
//---------------------------------------------------------------------------
public Date getDateRevised()
{
return mDateRevised;
}
//---------------------------------------------------------------------------
public MedlineCitation addMeshHeading(MeshHeading inValue)
{
if (null == mMeshHeadings)
{
mMeshHeadings = new ArrayList<>(10);
}
mMeshHeadings.add(inValue);
return this;
}
//---------------------------------------------------------------------------
public List getMeshHeadings()
{
return mMeshHeadings;
}
//---------------------------------------------------------------------------
public MedlineCitation addReference(MedlineCitation inValue)
{
if (null == mReferences)
{
mReferences = new ArrayList<>(10);
}
mReferences.add(inValue);
return this;
}
//---------------------------------------------------------------------------
public MedlineCitation setReferences(List inValues)
{
mReferences = inValues;
return this;
}
//---------------------------------------------------------------------------
public List getReferences()
{
return mReferences;
}
//###########################################################################
// PRIVATE METHODS
//###########################################################################
//---------------------------------------------------------------------------
private Date parseDateTag(XMLTag inTag)
{
GregorianCalendar cal = new GregorianCalendar();
cal.setTimeZone(TimeZone.getDefault());
cal.set(Calendar.YEAR, Integer.parseInt(inTag.getRequiredSubtagByName(PubmedXML.YEAR).getContent()));
cal.set(Calendar.MONTH, Integer.parseInt(inTag.getRequiredSubtagByName(PubmedXML.MONTH).getContent()) - 1);
cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(inTag.getRequiredSubtagByName(PubmedXML.DAY).getContent()));
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
}