001    /**
002     * Copyright (C) 2010 The Roslin Institute <contact andy.law@roslin.ed.ac.uk>
003     *
004     * This file is part of the Ensembl Java API demonstration project developed by the
005     * Bioinformatics Group at The Roslin Institute, The Royal (Dick) School of
006     * Veterinary Studies, University of Edinburgh.
007     *
008     * This is free software: you can redistribute it and/or modify
009     * it under the terms of the GNU General Public License (version 3) as published by
010     * the Free Software Foundation.
011     *
012     * This software is distributed in the hope that it will be useful,
013     * but WITHOUT ANY WARRANTY; without even the implied warranty of
014     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015     * GNU General Public License for more details.
016     *
017     * You should have received a copy of the GNU General Public License
018     * in this software distribution. If not, see <http://www.gnu.org/licenses/gpl-3.0.html/>.
019     */
020    package uk.ac.roslin.ensembl.datasourceaware.compara;
021    
022    import java.util.ArrayList;
023    import java.util.List;
024    import java.util.TreeSet;
025    import uk.ac.roslin.ensembl.dao.factory.DAOComparaFactory;
026    import uk.ac.roslin.ensembl.datasourceaware.DAObject;
027    import uk.ac.roslin.ensembl.datasourceaware.core.DAGene;
028    import uk.ac.roslin.ensembl.model.compara.HomologyAlignmentProperties;
029    import uk.ac.roslin.ensembl.model.compara.HomologyPairRelationship;
030    import uk.ac.roslin.ensembl.model.core.Species;
031    
032    public  class DAHomologyPairRelationship extends DAHomologyRelationship 
033            implements HomologyPairRelationship<DAGene> {
034    
035        public DAHomologyPairRelationship() {
036            super();
037        }
038    
039    //    public DAHomologyPairRelationship(DAOComparaFactory factory) {
040    //        super(factory);
041    //    }
042    
043        DAGene source = null;
044        DAGene target = null;
045    
046        /**
047         * Because a DAHomologyPairRelationship is tyeically instantiated from the
048         * compara databases - the target gene in particular is likely to not
049         * be a core-datasource aware object, and therefore species & and mapping details
050         * are only simple fields grabbed from compara: these are held in properties
051         * objects
052         */
053        HomologyAlignmentProperties sourceProperties = null;
054        HomologyAlignmentProperties targetProperties = null;
055    
056        @Override
057        public TreeSet<DAGene> getMembers() {
058            TreeSet<DAGene> genes = new TreeSet<DAGene>(DAObject.daComparator);
059            if (this.source != null ) {
060                genes.add(this.source);
061            }
062            if (this.target != null ) {
063                genes.add(this.target);
064            }
065            return genes;
066        }
067    
068        @Override
069        public List<Species> getSpecies() {
070            List<Species> spp = new ArrayList<Species>( );
071            if (this.source != null && this.source.getSpecies()!= null) {
072                spp.add(this.source.getSpecies());
073            }
074            if (this.target != null && this.target.getSpecies() != null
075                    && ! spp.contains(this.target.getSpecies())
076                    ) {
077                spp.add(this.target.getSpecies());
078            }
079            return spp;
080        }
081    
082        public HomologyAlignmentProperties getSourceProperties() {
083            return this.sourceProperties;
084        }
085    
086        public HomologyAlignmentProperties getTargetProperties() {
087            return this.targetProperties;
088        }
089    
090        public void setSourceProperties(HomologyAlignmentProperties sourceProperties) {
091            this.sourceProperties = sourceProperties;
092        }
093    
094        public void setTargetProperties(HomologyAlignmentProperties targetProperties) {
095            this.targetProperties = targetProperties;
096        }
097    
098        public void setSource(DAGene source) {
099            this.source = source;
100        }
101    
102        public void setTarget(DAGene target) {
103            this.target = target;
104        }
105    
106        public DAGene getSource() {
107            return this.source;
108        }
109    
110        public DAGene getTarget() {
111            return this.target;
112        }
113    
114    }