001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 * Created on DATE 021 * 022 */ 023package org.biojava.nbio.core.sequence; 024 025import org.biojava.nbio.core.util.Equals; 026import org.biojava.nbio.core.util.Hashcoder; 027 028/** 029 * Used in Sequences as the unique identifier. If possible, set the {@link DataSource} to know the 030 * source of the id. This allows a SequenceProxy to gather features or related sequences 031 * Protein->Gene as an example. When parsing a Blast file it is also possible 032 * to identify the type of ID 033 * 034 * @author Scooter Willis 035 * @author Jacek Grzebyta 036 */ 037public class AccessionID { 038 039 private String id = null; 040 private DataSource source = DataSource.LOCAL; 041 private Integer version; 042 private String identifier = null; 043 044 /** 045 * Default constructor sets id t empty string 046 */ 047 public AccessionID(){ 048 id = ""; 049 } 050 051 /** 052 * Creates an id with default DataSource.LOCAL source 053 * @param id non-null 054 */ 055 public AccessionID(String id) { 056 this(id, DataSource.LOCAL); 057 } 058 059 /** 060 * @param id 061 * @param source 062 */ 063 public AccessionID(String id, DataSource source) { 064 this.id = id.trim(); 065 this.source = source; 066 } 067 068 public AccessionID(String id, DataSource source, Integer version, String identifier) { 069 this.id = id; 070 this.source = source; 071 this.version = version; 072 this.identifier = identifier; 073 } 074 075 /** 076 * @return the id 077 */ 078 public String getID() { 079 return id; 080 } 081 082 /** 083 * @return the source 084 */ 085 public DataSource getDataSource() { 086 return source; 087 } 088 089 @Override 090 public boolean equals(Object o) { 091 boolean equals = false; 092 if (Equals.classEqual(this, o)) { 093 AccessionID l = (AccessionID) o; 094 equals = (Equals.equal(getID(), l.getID()) 095 && Equals.equal(getDataSource(), l.getDataSource()) 096 && Equals.equal(getIdentifier(), l.getIdentifier()) 097 && Equals.equal(getVersion(), l.getVersion())); 098 } 099 return equals; 100 } 101 102 @Override 103 public int hashCode() { 104 int r = Hashcoder.SEED; 105 r = Hashcoder.hash(r, getID()); 106 r = Hashcoder.hash(r, getDataSource()); 107 r = Hashcoder.hash(r, getIdentifier()); 108 r = Hashcoder.hash(r, getVersion()); 109 return r; 110 } 111 112 /** 113 * In case if the {@link #getID() } is not unique keeps the id version. 114 * @return the version 115 */ 116 public Integer getVersion() { 117 return version; 118 } 119 120 public void setVersion(Integer version) { 121 this.version = version; 122 } 123 124 /** 125 * In case if {@link #getID() } is not unique, keeps the alternative id, e.g. NCBI GI number. 126 * This may be null. 127 * @return 128 */ 129 public String getIdentifier() { 130 return identifier; 131 } 132 133 public void setIdentifier(String identifier) { 134 this.identifier = identifier; 135 } 136 137 138 @Override 139 public String toString() { 140 return id; 141 } 142}