001/**
002 * Copyright (C) 2010-2015 The Roslin Institute <contact andy.law@roslin.ed.ac.uk>
003 *
004 * This file is part of JEnsembl: a Java API to Ensembl data sources developed by the
005 * Bioinformatics Group at The Roslin Institute, The Royal (Dick) School of
006 * Veterinary Studies, University of Edinburgh.
007 *
008 * Project hosted at: http://jensembl.sourceforge.net
009 *
010 * This is free software: you can redistribute it and/or modify
011 * it under the terms of the GNU General Public License (version 3) as published by
012 * the Free Software Foundation.
013 *
014 * This software is distributed in the hope that it will be useful,
015 * but WITHOUT ANY WARRANTY; without even the implied warranty of
016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017 * GNU General Public License for more details.
018 *
019 * You should have received a copy of the GNU General Public License
020 * in this software distribution. If not, see: http://opensource.org/licenses/gpl-3.0.html
021 */
022package uk.ac.roslin.ensembl.datasourceaware.core;
023
024import org.biojava3.core.sequence.Strand;
025import uk.ac.roslin.ensembl.dao.factory.DAOCoreFactory;
026import uk.ac.roslin.ensembl.exception.DAOException;
027import uk.ac.roslin.ensembl.exception.RangeException;
028import uk.ac.roslin.ensembl.model.core.AssembledDNASequence;
029
030/**
031 *
032 * @author paterson
033 */
034public class DAAssembledDNASequence extends DADNASequence implements AssembledDNASequence {
035
036    DAAssembly completeAssembly = null;
037
038    public DAAssembledDNASequence() {
039        super();
040    }
041
042    public DAAssembledDNASequence(DAOCoreFactory factory) {
043        super(factory);
044    }
045
046    @Override
047    public DAAssembly getCompleteAssembly() {
048        if (completeAssembly == null) {
049            completeAssembly = DAAssembly.getAssembly(this);
050        }
051        return completeAssembly;
052    }
053   
054    /**
055     * Method to get a string representation for the given range of the assembled sequence. 
056     * Arguments outwith the extent of the sequence (i.e. greater than its length, or less than the start site of +1) 
057     * will throw a (Runtime) RangeException (try using getPaddedSequenceAsString(int,int)).
058     * @param begin
059     * @param end
060     * @return String representation of the Sequence
061     */
062    @Override
063    public String getSequenceAsString(Integer begin, Integer end) throws RangeException  {
064
065        String out = "";
066        
067        try {
068            out = this.getCompleteAssembly().getSequenceAsString(begin, end);
069            if (out==null) {
070                out = "";
071            }
072//        } catch (RangeException ex) {
073        } catch (DAOException ex) {
074
075        }
076
077        return out;
078    }
079    
080    @Override
081    public String getPaddedSequenceAsString(Integer begin, Integer end) {
082
083        String out = "";
084        
085        try {
086            out = this.getCompleteAssembly().getPaddedSequenceAsString(begin, end);
087            if (out==null) {
088                out = "";
089            }
090        } catch (DAOException ex) {
091
092        }
093
094        return out;
095    }
096     /**
097     * Don't use: It is ambiguous to use  Strands for getting sequence strings.
098     * Always use getSequenceAsString or getReverseComplementSequenceAsString to guarantee polarity.    
099     * @param begin
100     * @param end
101     * @param strand
102     * @return String representation of the Sequence
103     */
104    @Override
105    @Deprecated
106    public String getSequenceAsString(Integer begin, Integer end, Strand strand) throws RangeException  {
107        
108        if (strand != null && strand==org.biojava3.core.sequence.Strand.NEGATIVE) {
109            return getReverseComplementSequenceAsString(begin, end);
110        } else {
111            return getSequenceAsString(begin, end);
112        }
113
114    }
115
116    /**
117     * Default case is to assume strand is positive because only CDSSequence 
118     * can be either positive or negative Strand.
119     * @return String representation of the Sequence
120     */
121    @Override
122    public String getSequenceAsString() {
123        if (this.getBioEnd()==0) {
124            return "";
125        }
126        return getSequenceAsString(this.getBioBegin(), this.getBioEnd());
127    }
128
129     /**
130     *
131     * @param begin
132     * @param end
133     * @return String representation of the reverse complement Sequence
134     */
135    @Override
136    public String getReverseComplementSequenceAsString(Integer begin, Integer end) throws RangeException {
137
138        String out = "";
139
140        try {
141            out = this.getCompleteAssembly().getReverseComplementSequenceAsString(begin, end);
142            if (out==null) {
143                out = "";
144            }
145//        } catch (RangeException ex) {            
146        } catch (DAOException ex) {
147
148        }
149
150        return out;
151    }
152    
153    @Override
154    public String getPaddedReverseComplementSequenceAsString(Integer begin, Integer end) throws RangeException {
155
156        String out = "";
157
158        try {
159            out = this.getCompleteAssembly().getPaddedReverseComplementSequenceAsString(begin, end);
160            if (out==null) {
161                out = "";
162            }
163        } catch (DAOException ex) {
164
165        }
166
167        return out;
168    }
169
170    /**
171     * Default case is to assume strand is positive because only CDSSequence can be either positive or negative Strand.
172     * @return String representation of the reverse complement Sequence
173     */
174    @Override
175    public String getReverseComplementSequenceAsString() {
176        if (this.getBioEnd()==0) {
177            return "";
178        }
179        return getReverseComplementSequenceAsString(this.getBioBegin(), this.getBioEnd());
180    }
181
182
183}