3 // FORESTER -- software libraries and applications
4 // for evolutionary biology research and applications.
6 // Copyright (C) 2008-2009 Christian M. Zmasek
7 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 // Contact: phylosoft @ gmail . com
25 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
27 package org.forester.protein;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.SortedSet;
32 import java.util.TreeSet;
34 import org.forester.species.BasicSpecies;
35 import org.forester.species.Species;
36 import org.forester.util.ForesterUtil;
38 // Note: when implementing any "equals" method need to keep in mind that
39 // proteins could have the same name and/or id!
40 public class BasicProtein implements Protein {
42 private final ProteinId _id;
43 private final int _length;
44 private final Species _species;
47 private String _accession;
48 private final List<Domain> _protein_domains;
50 public BasicProtein( final String id_str, final String species_str, final int length ) {
52 throw new IllegalArgumentException( "attempt to create protein of length " + length );
54 if ( ForesterUtil.isEmpty( id_str ) ) {
55 throw new IllegalArgumentException( "attempt to create protein with null or empty identifier" );
57 if ( ForesterUtil.isEmpty( species_str ) ) {
58 throw new IllegalArgumentException( "attempt to create protein with null or empty species" );
60 _id = new ProteinId( id_str );
61 _species = new BasicSpecies( species_str );
63 _protein_domains = new ArrayList<Domain>();
68 public void addProteinDomain( final Domain protein_domain ) {
69 getProteinDomains().add( protein_domain );
74 * If in_nc_order is set to true, this returns true only and only if
75 * the order in List 'domains' and this protein (as determined by the start positions
76 * of the domains of this proteins, _not_ by their index) are the same
77 * (interspersing, 'other', domains in this are ignored).
78 * If in_nc_order is set to false, this returns true only and only if
79 * this contains all domains listed in 'domains' (order and count do not matter).
81 * @param domains a list of domain ids in a certain order.
82 * @param in_nc_order to consider order
85 public boolean contains( final List<DomainId> query_domain_ids, final boolean in_nc_order ) {
87 for( final DomainId query_domain_id : query_domain_ids ) {
88 if ( !getProteinDomainIds().contains( query_domain_id ) ) {
95 int current_start_position = -1;
96 I: for( final DomainId query_domain_id : query_domain_ids ) {
97 if ( getProteinDomainIds().contains( query_domain_id ) ) {
98 final List<Domain> found_domains = getProteinDomains( query_domain_id );
99 final SortedSet<Integer> ordered_start_positions = new TreeSet<Integer>();
100 for( final Domain found_domain : found_domains ) {
101 ordered_start_positions.add( found_domain.getFrom() );
103 for( final int start_position : ordered_start_positions ) {
104 if ( start_position > current_start_position ) {
105 current_start_position = start_position;
120 public String getAccession() {
125 public String getDescription() {
130 public String getName() {
135 public int getNumberOfProteinDomains() {
136 return getProteinDomains().size();
140 public Domain getProteinDomain( final int index ) {
141 return _protein_domains.get( index );
145 public int getProteinDomainCount( final DomainId domain_id ) {
146 return getProteinDomains( domain_id ).size();
149 private List<DomainId> getProteinDomainIds() {
150 final List<DomainId> ids = new ArrayList<DomainId>( getProteinDomains().size() );
151 for( final Domain domain : getProteinDomains() ) {
152 ids.add( domain.getDomainId() );
158 public List<Domain> getProteinDomains() {
159 return _protein_domains;
163 public List<Domain> getProteinDomains( final DomainId domain_id ) {
164 final List<Domain> domains = new ArrayList<Domain>();
165 for( final Domain domain : getProteinDomains() ) {
166 if ( domain.getDomainId().equals( domain_id ) ) {
167 domains.add( domain );
174 public ProteinId getProteinId() {
179 public Species getSpecies() {
183 private void init() {
189 public void setAccession( final String accession ) {
190 _accession = accession;
193 public void setDescription( final String description ) {
197 public void setName( final String name ) {
202 public int getLength() {