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>();
50 public void addProteinDomain( final Domain protein_domain ) {
51 getProteinDomains().add( protein_domain );
56 * If in_nc_order is set to true, this returns true only and only if
57 * the order in List 'domains' and this protein (as determined by the start positions
58 * of the domains of this proteins, _not_ by their index) are the same
59 * (interspersing, 'other', domains in this are ignored).
60 * If in_nc_order is set to false, this returns true only and only if
61 * this contains all domains listed in 'domains' (order and count do not matter).
63 * @param domains a list of domain ids in a certain order.
64 * @param in_nc_order to consider order
67 public boolean contains( final List<DomainId> query_domain_ids, final boolean in_nc_order ) {
69 for( final DomainId query_domain_id : query_domain_ids ) {
70 if ( !getProteinDomainIds().contains( query_domain_id ) ) {
77 int current_start_position = -1;
78 I: for( final DomainId query_domain_id : query_domain_ids ) {
79 if ( getProteinDomainIds().contains( query_domain_id ) ) {
80 final List<Domain> found_domains = getProteinDomains( query_domain_id );
81 final SortedSet<Integer> ordered_start_positions = new TreeSet<Integer>();
82 for( final Domain found_domain : found_domains ) {
83 ordered_start_positions.add( found_domain.getFrom() );
85 for( final int start_position : ordered_start_positions ) {
86 if ( start_position > current_start_position ) {
87 current_start_position = start_position;
102 public String getAccession() {
107 public String getDescription() {
112 public String getName() {
116 public int getNumberOfProteinDomains() {
117 return getProteinDomains().size();
120 public Domain getProteinDomain( final int index ) {
121 return _protein_domains.get( index );
124 public int getProteinDomainCount( final DomainId domain_id ) {
125 return getProteinDomains( domain_id ).size();
128 private List<DomainId> getProteinDomainIds() {
129 final List<DomainId> ids = new ArrayList<DomainId>( getProteinDomains().size() );
130 for( final Domain domain : getProteinDomains() ) {
131 ids.add( domain.getDomainId() );
136 public List<Domain> getProteinDomains() {
137 return _protein_domains;
140 public List<Domain> getProteinDomains( final DomainId domain_id ) {
141 final List<Domain> domains = new ArrayList<Domain>();
142 for( final Domain domain : getProteinDomains() ) {
143 if ( domain.getDomainId().equals( domain_id ) ) {
144 domains.add( domain );
150 public ProteinId getProteinId() {
154 public Species getSpecies() {
158 private void init() {
164 public void setAccession( final String accession ) {
165 _accession = accession;
168 public void setDescription( final String description ) {
172 public void setName( final String name ) {