|
MASA-Core
|
00001 /******************************************************************************* 00002 * 00003 * Copyright (c) 2010-2015 Edans Sandes 00004 * 00005 * This file is part of MASA-Core. 00006 * 00007 * MASA-Core is free software: you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation, either version 3 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * MASA-Core is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with MASA-Core. If not, see <http://www.gnu.org/licenses/>. 00019 * 00020 ******************************************************************************/ 00021 00022 #include "Sequence.hpp" 00023 #include <stdio.h> 00024 #include <stdlib.h> 00025 #include <string.h> 00026 00027 00028 Sequence::Sequence( SequenceInfo* info, SequenceModifiers* modifiers ) { 00029 this->info = info; 00030 this->modifiers = modifiers; 00031 this->dataOwner = false; 00032 if (info->getFilename() != "") { 00033 this->data = new SequenceData(info->getFilename(), modifiers); 00034 this->dataOwner = true; 00035 } else if (info->getData() != NULL) { 00036 // TODO 00037 //this->data = new SequenceData(info->getData(), info->getSize(), modifiers); 00038 this->data = NULL; 00039 } else { 00040 this->data = NULL; 00041 } 00042 00043 if (this->data != NULL) { 00044 this->info->setDescription(this->data->getDescription()); 00045 this->info->setSize(this->data->getOriginalSize()); 00046 this->len = this->data->getSize(); 00047 } else { 00048 this->len = 0; 00049 } 00050 setBoundaries(modifiers->getTrimStart(), modifiers->getTrimEnd()); 00051 this->reverseData = modifiers->isReverse(); 00052 //this->paddingLenght = 0; 00053 //this->paddingChar = '\0'; 00054 } 00055 00056 Sequence::Sequence(const Sequence* orig) { 00057 this->info = orig->info; 00058 this->modifiers = orig->modifiers; 00059 this->data = orig->data; 00060 this->len = orig->len; 00061 //this->paddingChar = orig->paddingChar; 00062 //this->paddingLenght = orig->paddingLenght; 00063 this->offset0 = orig->offset0; 00064 this->offset1 = orig->offset1; 00065 this->reverseData = orig->reverseData; 00066 this->dataOwner = false; 00067 } 00068 00069 Sequence::~Sequence() { 00070 if (dataOwner) { 00071 delete data; 00072 } 00073 // TODO desalocar os dados. Atenção para as duplicações de ponteiros 00074 } 00075 00076 00077 void Sequence::copyData(const Sequence* orig) { 00078 this->dataOwner = false; 00079 if (this->modifiers->isCompatible(orig->modifiers)) { 00080 this->data = orig->data; 00081 } else if (orig->info->getFilename() != "") { 00082 this->data = new SequenceData(orig->info->getFilename(), modifiers); 00083 this->dataOwner = true; 00084 } else if (orig->info->getData() != NULL) { 00085 // TODO 00086 //this->data = new SequenceData(orig->info->getData(), modifiers); 00087 this->data = NULL; 00088 } else { 00089 this->data = NULL; 00090 } 00091 } 00092 00093 int Sequence::getLen() const { 00094 //fprintf(stderr, "LEN+PADDING: %d+%d=%d\n", len, padding, len + padding); 00095 return len; 00096 } 00097 00098 void Sequence::reverse() { 00099 this->reverseData = !this->reverseData; 00100 } 00101 00102 void Sequence::trim (int delta0, int delta1) { 00103 if (delta0 <= 0) { 00104 delta0 = 1; 00105 } 00106 if (delta1 <= 0) { 00107 delta1 = len; 00108 } 00109 setBoundaries(offset0 + (delta0-1), offset1 - (len-delta1)); 00110 } 00111 00112 00113 /*void Sequence::setPadding(int length, char c) { 00114 this->paddingLenght = length; 00115 this->paddingChar = c; 00116 } 00117 00118 char Sequence::getPaddingChar() const { 00119 return paddingChar; 00120 } 00121 00122 int Sequence::getPaddingLenght() const { 00123 return paddingLenght; 00124 }*/ 00125 00126 void Sequence::setBoundaries(int trimStart, int trimEnd) { 00127 if (trimStart <= 0) { 00128 trimStart = 1; 00129 } 00130 if (trimEnd <= 0) { 00131 trimEnd = data->getSize(); 00132 } 00133 offset0 = trimStart; 00134 offset1 = trimEnd; 00135 len = trimEnd - trimStart + 1; 00136 printf("TRIM: %d..%d (%d)\n", offset0, offset1, len); 00137 } 00138 00139 // offset: 1-based; relativePos: 1-based 00140 int Sequence::getAbsolutePos(int relativePos) const { 00141 if (reverseData) { 00142 return getInfo()->getSize()+1-relativePos; 00143 } else { 00144 return relativePos; 00145 } 00146 } 00147 00148 bool Sequence::isReversed() const { 00149 return reverseData; 00150 } 00151 00152 SequenceInfo* Sequence::getInfo() const { 00153 return info; 00154 } 00155 00156 void Sequence::setInfo(SequenceInfo* info) { 00157 this->info = info; 00158 } 00159 00160 SequenceModifiers* Sequence::getModifiers() const { 00161 return modifiers; 00162 } 00163 00164 int Sequence::getTrimStart() const { 00165 return offset0; 00166 } 00167 00168 int Sequence::getTrimEnd() const { 00169 return offset1; 00170 } 00171 00172 const char* Sequence::getData(bool reverse) const { 00173 if (reverseData ^ reverse) { 00174 return this->data->getReverseData();// + (this->data->getSize()-offset1); 00175 } else { 00176 return this->data->getForwardData();// + (offset0-1); 00177 } 00178 } 00179 00180 const char* Sequence::getForwardData() const { 00181 return this->data->getForwardData(); 00182 } 00183 00184 00185 const char* Sequence::getReverseData() const { 00186 return this->data->getReverseData(); 00187 } 00188 00189 00190 00191 00192 00193
1.7.6.1