|
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 "InitialCellsReader.hpp" 00023 #include "../../libmasa/IManager.hpp" 00024 #include <stdio.h> 00025 00026 #define DEBUG (0) 00027 00028 InitialCellsReader::InitialCellsReader(int startOffset) { 00029 this->type = INIT_WITH_ZEROES; 00030 this->startOffset = startOffset; 00031 initialize(); 00032 } 00033 00034 InitialCellsReader::InitialCellsReader(const int gapOpen, const int gapExt, int startOffset) { 00035 this->gapOpen = gapOpen; 00036 this->gapExt = gapExt; 00037 if (gapOpen == 0 && gapExt == 0) { 00038 this->type = INIT_WITH_ZEROES; 00039 } else if (gapOpen == 0) { 00040 this->type = INIT_WITH_GAPS_OPENED; 00041 } else { 00042 this->type = INIT_WITH_GAPS; 00043 } 00044 this->startOffset = startOffset; 00045 initialize(); 00046 } 00047 00048 InitialCellsReader::~InitialCellsReader() { 00049 // Does nothing 00050 } 00051 00052 void InitialCellsReader::close() { 00053 // Does nothing 00054 } 00055 00056 void InitialCellsReader::seek(int position) { 00057 this->position = startOffset + position; 00058 } 00059 00060 int InitialCellsReader::getOffset() { 00061 return position - startOffset; 00062 } 00063 00064 InitialCellsReader* InitialCellsReader::clone(int offset) { 00065 if (type == INIT_WITH_GAPS || type == INIT_WITH_GAPS_OPENED) { 00066 return new InitialCellsReader(gapOpen, gapExt, this->startOffset + offset); 00067 } else { 00068 return new InitialCellsReader(this->startOffset + offset); 00069 } 00070 } 00071 00072 int InitialCellsReader::getStartOffset() { 00073 return startOffset; 00074 } 00075 00076 void InitialCellsReader::initialize() { 00077 this->position = startOffset; 00078 } 00079 00080 int InitialCellsReader::getType() { 00081 return this->type; 00082 } 00083 00084 int InitialCellsReader::read(cell_t* buffer, int len) { 00085 if (DEBUG) fprintf(stdout, "InitialCellsReader::read(%p, %d) - pos: %d\n", buffer, len, position); 00086 if (buffer != NULL) { 00087 if (type == INIT_WITH_GAPS || type == INIT_WITH_GAPS_OPENED) { 00088 // Pre-defined initialization functions 00089 int k = 0; 00090 if (position == 0) { 00091 buffer[0].h = 0; 00092 buffer[0].f = -INF; 00093 k++; 00094 } 00095 for (; k < len; k++) { 00096 buffer[k].h = -gapExt*(position+k) - gapOpen; 00097 buffer[k].e = -INF; 00098 } 00099 } else if (type == INIT_WITH_ZEROES) { 00100 for (int k = 0; k < len; k++) { 00101 buffer[k].h = 0; 00102 buffer[k].e = -INF; 00103 } 00104 } 00105 } 00106 position += len; 00107 return len; 00108 } 00109
1.7.6.1