MASA-Core
SequenceInfo.cpp
Go to the documentation of this file.
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 "SequenceInfo.hpp"
00023 #include "Constants.hpp"
00024 
00025 #include <stdio.h>
00026 
00027 SequenceInfo::SequenceInfo() {
00028         // TODO detectar automaticamente
00029         this->type = SEQUENCE_TYPE_DNA;
00030 }
00031 
00032 bool SequenceInfo::isEqual(const SequenceInfo* other) const {
00033         bool hashEqual = (hash.length() == 0 || other->hash.length() ==0 || hash == other->hash);
00034         bool sizeEqual = (size == 0 || other->size == 0 || size == other->size);
00035         bool descriptionEqual = (description.length() == 0 || other->description.length() ==0 || description == other->description);
00036         bool typeEqual = (type == SEQUENCE_TYPE_UNKNOWN || other->type == SEQUENCE_TYPE_UNKNOWN || type == other->type);
00037         bool fileEqual = (filename.length() == 0 || other->filename.length() ==0 || filename == other->filename);
00038 
00039         //printf("SequenceInfo::operator == %d %d %d %d %d\n", hashEqual , sizeEqual , descriptionEqual , typeEqual , fileEqual);
00040 
00041         return hashEqual && sizeEqual && descriptionEqual && typeEqual && fileEqual;
00042 }
00043 
00044 char* SequenceInfo::getData() const {
00045         return data;
00046 }
00047 
00048 void SequenceInfo::setData(char* data) {
00049         this->data = data;
00050 }
00051 
00052 string SequenceInfo::getDescription() const {
00053         return description;
00054 }
00055 
00056 void SequenceInfo::setDescription(string description) {
00057         this->description = description;
00058 
00059         if (description[0] == '>') {
00060                 this->description = description.substr(1);
00061         } else {
00062                 this->description = description;
00063         }
00064         int nl = this->description.find('\n');
00065         if (nl != string::npos) {
00066                 this->description = this->description.substr(0, nl);
00067         }
00068 
00069     int pos = -1;
00070     int lastpos = 0;
00071         for (int i=0; i<4; i++) {
00072                 lastpos = pos;
00073             pos = description.find('|', lastpos+1);
00074             if (pos == description.length()) break;
00075         }
00076         if (pos == string::npos) {
00077                 accession = description;
00078         } else {
00079                 accession = description.substr(lastpos+1, pos-lastpos-1);
00080         }
00081 }
00082 
00083 string SequenceInfo::getAccession() const {
00084         return accession;
00085 }
00086 
00087 string SequenceInfo::getFilename() const {
00088         return filename;
00089 }
00090 
00091 void SequenceInfo::setFilename(string filename) {
00092         this->filename = filename;
00093 }
00094 
00095 string SequenceInfo::getHash() const {
00096         return hash;
00097 }
00098 
00099 void SequenceInfo::setHash(string hash) {
00100         this->hash = hash;
00101 }
00102 
00103 int SequenceInfo::getSize() const {
00104         return size;
00105 }
00106 
00107 void SequenceInfo::setSize(int size) {
00108         this->size = size;
00109 }
00110 
00111 int SequenceInfo::getType() const {
00112         return type;
00113 }
00114 
00115 void SequenceInfo::setType(int type) {
00116         this->type = type;
00117 }
00118 
00119 int SequenceInfo::getIndex() const {
00120         return index;
00121 }
00122 
00123 void SequenceInfo::setIndex(int index) {
00124         this->index = index;
00125 }
00126 
00127