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: www.phylosoft.org/forester
27 package org.forester.surfacing;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.SortedSet;
32 import java.util.TreeSet;
34 public class BasicProtein implements Protein {
36 private final ProteinId _id;
37 private final Species _species;
40 private String _accession;
41 private final List<Domain> _protein_domains;
43 public BasicProtein( final String id_str, final String species_str ) {
44 _id = new ProteinId( id_str );
45 _species = new BasicSpecies( species_str );
46 _protein_domains = new ArrayList<Domain>();
51 public void addProteinDomain( final Domain protein_domain ) {
52 getProteinDomains().add( protein_domain );
57 * If in_nc_order is set to true, this returns true only and only if
58 * the order in List 'domains' and this protein (as determined by the start positions
59 * of the domains of this proteins, _not_ by their index) are the same
60 * (interspersing, 'other', domains in this are ignored).
61 * If in_nc_order is set to false, this returns true only and only if
62 * this contains all domains listed in 'domains' (order and count do not matter).
64 * @param domains a list of domain ids in a certain order.
65 * @param in_nc_order to consider order
68 public boolean contains( final List<DomainId> query_domain_ids, final boolean in_nc_order ) {
70 for( final DomainId query_domain_id : query_domain_ids ) {
71 if ( !getProteinDomainIds().contains( query_domain_id ) ) {
78 int current_start_position = -1;
79 I: for( final DomainId query_domain_id : query_domain_ids ) {
80 if ( getProteinDomainIds().contains( query_domain_id ) ) {
81 final List<Domain> found_domains = getProteinDomains( query_domain_id );
82 final SortedSet<Integer> ordered_start_positions = new TreeSet<Integer>();
83 for( final Domain found_domain : found_domains ) {
84 ordered_start_positions.add( found_domain.getFrom() );
86 for( final int start_position : ordered_start_positions ) {
87 if ( start_position > current_start_position ) {
88 current_start_position = start_position;
103 public String getAccession() {
108 public String getDescription() {
113 public String getName() {
118 public int getNumberOfProteinDomains() {
119 return getProteinDomains().size();
123 public Domain getProteinDomain( final int index ) {
124 return _protein_domains.get( index );
128 public int getProteinDomainCount( final DomainId domain_id ) {
129 return getProteinDomains( domain_id ).size();
132 private List<DomainId> getProteinDomainIds() {
133 final List<DomainId> ids = new ArrayList<DomainId>( getProteinDomains().size() );
134 for( final Domain domain : getProteinDomains() ) {
135 ids.add( domain.getDomainId() );
141 public List<Domain> getProteinDomains() {
142 return _protein_domains;
146 public List<Domain> getProteinDomains( final DomainId domain_id ) {
147 final List<Domain> domains = new ArrayList<Domain>();
148 for( final Domain domain : getProteinDomains() ) {
149 if ( domain.getDomainId().equals( domain_id ) ) {
150 domains.add( domain );
157 public ProteinId getProteinId() {
162 public Species getSpecies() {
166 private void init() {
172 public void setAccession( final String accession ) {
173 _accession = accession;
176 public void setDescription( final String description ) {
180 public void setName( final String name ) {