com.hfg.bio.seq.format.genbank.GenBankReference 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.bio.seq.format.genbank;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.hfg.math.Range;
import com.hfg.util.CompareUtil;
import com.hfg.util.StringUtil;
//------------------------------------------------------------------------------
/**
* Literature citation container.
*
* @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]
//------------------------------------------------------------------------------
public class GenBankReference implements Comparable
{
private List mAuthors;
private String mTitle;
private String mJournal;
private String mSubmissionRecordInfo;
private Integer mVolume;
private Integer mIssue;
private Integer mYear;
private Range mPages;
private Integer mPubmedId;
private static final Pattern sJournalPattern = Pattern.compile("^(.+?)\\s+(\\d+)\\s+\\((\\d+)\\),\\s+(\\d+)-(\\d+)\\s+\\((\\d{4})\\)$");
//##########################################################################
// PUBLIC METHODS
//##########################################################################
//--------------------------------------------------------------------------
@Override
public boolean equals(Object inObj2)
{
boolean result = false;
if (inObj2 != null
&& inObj2 instanceof GenBankReference)
{
result = (0 == compareTo((GenBankReference)inObj2));
}
return result;
}
//--------------------------------------------------------------------------
@Override
public int hashCode()
{
int hashCode = getAuthorString().hashCode();
hashCode += 31 * (getTitle() != null ? getTitle().hashCode() : 0);
hashCode += 31 * (getJournal() != null ? getJournal().hashCode() : 0);
hashCode += 31 * (getVolume() != null ? getVolume().hashCode() : 0);
hashCode += 31 * (getIssue() != null ? getIssue().hashCode() : 0);
hashCode += 31 * (getYear() != null ? getYear().hashCode() : 0);
hashCode += 31 * (getPages() != null ? getPages().hashCode() : 0);
return hashCode;
}
//--------------------------------------------------------------------------
@Override
public int compareTo(GenBankReference inObj2)
{
int result = 0;
if (null == inObj2)
{
result = 1;
}
else
{
result = CompareUtil.compare(getTitle(), inObj2.getTitle());
if (0 == result)
{
if (getPages() != null)
{
if (inObj2.getPages() != null)
{
result = getPages().compareTo(inObj2.getPages());
}
else
{
result = 1;
}
}
else if (inObj2.getPages() != null)
{
result = -1;
}
if (0 == result)
{
result = CompareUtil.compare(getAuthorString(), inObj2.getAuthorString());
if (0 == result)
{
result = CompareUtil.compare(getYear(), inObj2.getYear());
if (0 == result)
{
result = CompareUtil.compare(getVolume(), inObj2.getVolume());
if (0 == result)
{
result = CompareUtil.compare(getIssue(), inObj2.getIssue());
if (0 == result)
{
result = CompareUtil.compare(getJournal(), inObj2.getJournal());
}
}
}
}
}
}
}
return result;
}
//--------------------------------------------------------------------------
public GenBankReference setAuthors(String inAuthorList)
{
String[] authors = inAuthorList.split("[;,]");
for (String author : authors)
{
addAuthor(author);
}
return this;
}
//--------------------------------------------------------------------------
public GenBankReference addAuthor(String inAuthor)
{
if (null == mAuthors)
{
mAuthors = new ArrayList(25);
}
mAuthors.add(inAuthor);
return this;
}
//--------------------------------------------------------------------------
public List getAuthors()
{
return mAuthors;
}
//--------------------------------------------------------------------------
public String getAuthorString()
{
return (mAuthors != null ? StringUtil.join(mAuthors, ", ") : "");
}
//--------------------------------------------------------------------------
public GenBankReference setTitle(String inValue)
{
mTitle = inValue;
return this;
}
//--------------------------------------------------------------------------
public String getTitle()
{
return mTitle;
}
//--------------------------------------------------------------------------
// Simple example:
// J. Exp. Med. 181 (3), 1245-1250 (1995)
//
// Submission record example:
// Submitted (07-NOV-1994) Giachino C., Basel Institute for
// Immunology, Grenzacherstrasse 487, Basel, Switzerland, 4005
//
public void parseJournalString(String inValue)
{
if (inValue.startsWith("Submitted"))
{
mSubmissionRecordInfo = inValue;
}
else
{
Matcher m = sJournalPattern.matcher(inValue);
if (m.matches())
{
mJournal = m.group(1);
mVolume = Integer.parseInt(m.group(2));
mIssue = Integer.parseInt(m.group(3));
mPages = new Range<>(Integer.parseInt(m.group(4)), Integer.parseInt(m.group(5)));
mYear = Integer.parseInt(m.group(6));
}
else
{
mJournal = inValue;
}
}
}
//--------------------------------------------------------------------------
public GenBankReference setJournal(String inValue)
{
mJournal = inValue;
return this;
}
//--------------------------------------------------------------------------
public String getJournal()
{
return mJournal;
}
//--------------------------------------------------------------------------
public String getSubmissionRecordInfo()
{
return mSubmissionRecordInfo;
}
//--------------------------------------------------------------------------
public GenBankReference setVolume(Integer inValue)
{
mVolume = inValue;
return this;
}
//--------------------------------------------------------------------------
public Integer getVolume()
{
return mVolume;
}
//--------------------------------------------------------------------------
public GenBankReference setIssue(Integer inValue)
{
mIssue = inValue;
return this;
}
//--------------------------------------------------------------------------
public Integer getIssue()
{
return mIssue;
}
//--------------------------------------------------------------------------
public GenBankReference setYear(Integer inValue)
{
mYear = inValue;
return this;
}
//--------------------------------------------------------------------------
public Integer getYear()
{
return mYear;
}
//--------------------------------------------------------------------------
public GenBankReference setPubmedId(Integer inValue)
{
mPubmedId = inValue;
return this;
}
//--------------------------------------------------------------------------
public Integer getPubmedId()
{
return mPubmedId;
}
//--------------------------------------------------------------------------
public GenBankReference setPages(Range inValue)
{
mPages = inValue;
return this;
}
//--------------------------------------------------------------------------
public Range getPages()
{
return mPages;
}
}