| #include <string> |
| #include <iostream> |
| #include <fstream> |
| #include <pwd.h> |
| #include <cstdlib> |
| #include <unistd.h> |
| |
| #include "nlsr_sm.hpp" |
| |
| namespace nlsr |
| { |
| |
| using namespace std; |
| |
| void |
| SequencingManager::splittSequenceNo(uint64_t seqNo) |
| { |
| combinedSeqNo=seqNo; |
| adjLsaSeq = (combinedSeqNo & 0xFFFFF); |
| corLsaSeq = ((combinedSeqNo >> 20) & 0xFFFFF); |
| nameLsaSeq = ((combinedSeqNo >> 40) & 0xFFFFF); |
| } |
| |
| void |
| SequencingManager::combineSequenceNo() |
| { |
| combinedSeqNo=0; |
| combinedSeqNo = combinedSeqNo | adjLsaSeq; |
| combinedSeqNo = combinedSeqNo | (corLsaSeq<<20); |
| combinedSeqNo = combinedSeqNo | (nameLsaSeq<<40); |
| } |
| |
| void |
| SequencingManager::writeSeqNoToFile() |
| { |
| std::ofstream outputFile(seqFileNameWithPath.c_str(),ios::binary); |
| outputFile<<combinedSeqNo; |
| outputFile.close(); |
| } |
| |
| void |
| SequencingManager::initiateSeqNoFromFile() |
| { |
| cout<<"Seq File Name: "<< seqFileNameWithPath<<endl; |
| std::ifstream inputFile(seqFileNameWithPath.c_str(),ios::binary); |
| if ( inputFile.good() ) |
| { |
| inputFile>>combinedSeqNo; |
| splittSequenceNo(combinedSeqNo); |
| adjLsaSeq+=10; |
| corLsaSeq+=10; |
| nameLsaSeq+=10; |
| combineSequenceNo(); |
| inputFile.close(); |
| } |
| else |
| { |
| splittSequenceNo(0); |
| } |
| } |
| |
| void |
| SequencingManager::setSeqFileName(string filePath) |
| { |
| seqFileNameWithPath=filePath; |
| if( seqFileNameWithPath.empty() ) |
| { |
| seqFileNameWithPath=getUserHomeDirectory(); |
| } |
| seqFileNameWithPath=seqFileNameWithPath+"/nlsrSeqNo.txt"; |
| } |
| |
| string |
| SequencingManager::getUserHomeDirectory() |
| { |
| string homeDirPath(getpwuid(getuid())->pw_dir); |
| if( homeDirPath.empty() ) |
| { |
| homeDirPath = getenv("HOME"); |
| } |
| return homeDirPath; |
| } |
| |
| ostream& |
| operator <<(ostream& os, const SequencingManager& sm) |
| { |
| std::cout<<"----SequencingManager----"<<std::endl; |
| std::cout<<"Adj LSA seq no: "<<sm.getAdjLsaSeq()<<endl; |
| std::cout<<"Cor LSA Seq no: "<<sm.getCorLsaSeq()<<endl; |
| std::cout<<"Name LSA Seq no: "<<sm.getNameLsaSeq()<<endl; |
| std::cout<<"Combined LSDB Seq no: "<<sm.getCombinedSeqNo()<<endl; |
| return os; |
| } |
| |
| }//namespace nlsr |
| |
| |