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 021 package uk.ac.roslin.ensembl.datasourceaware.core; 022 023 import org.biojava3.core.sequence.Strand; 024 025 /** 026 * 027 * @author paterson 028 */ 029 public class GapSequence extends DADNASequence { 030 031 private static final String base = "N"; 032 private StringBuffer seq = null; 033 034 public static GapSequence makeGap(Integer length) { 035 if (length == null || length <0 ) { 036 return null; 037 } 038 return new GapSequence(length); 039 } 040 041 private static String getGapString(Integer length) { 042 StringBuffer sb = new StringBuffer(); 043 for (int i = 0; i < length; i++) { 044 sb= sb.append(base); 045 } 046 return sb.toString(); 047 } 048 049 private GapSequence(Integer length) { 050 super(); 051 this.setDBSeqLength(length); 052 this.setBioBegin(1); 053 this.setBioEnd(length); 054 this.setName("Gap of "+length); 055 } 056 057 058 @Override 059 public String getSequenceAsString() { 060 return this.getSequenceAsString(this.getBioBegin(), this.getBioEnd(), null); 061 } 062 063 @Override 064 public String getReverseComplementSequenceAsString() { 065 return this.getSequenceAsString(this.getBioBegin(), this.getBioEnd(), null); 066 } 067 068 @Override 069 public String getSequenceAsString(Integer start, Integer stop) { 070 return this.getSequenceAsString(start, stop, Strand.POSITIVE); 071 } 072 073 @Override 074 public String getSequenceAsString(Integer start, Integer stop, Strand strand){ 075 076 077 Integer begin = start; 078 Integer end = stop; 079 080 081 if (end == null || end > this.getBioEnd()) { 082 end = this.getBioEnd(); 083 } 084 if (begin == null || begin<this.getBioBegin()) { 085 begin = this.getBioBegin(); 086 } 087 return GapSequence.getGapString(end-begin+1); 088 089 } 090 091 @Override 092 public String getReverseComplementSequenceAsString(Integer start, Integer stop){ 093 094 return this.getSequenceAsString(start, stop, null); 095 096 } 097 098 @Override 099 public String toString() { 100 return name; 101 } 102 103 @Override 104 public int getLength() { 105 return this.getDBSeqLength().intValue(); 106 } 107 }