update
This commit is contained in:
parent
7d96c74496
commit
b1ee6b8d03
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
.xmake
|
||||
.vscode
|
||||
build
|
||||
build
|
||||
filteredReads.txt
|
||||
reversedSequence.txt
|
101
src/main.cpp
101
src/main.cpp
@ -1,3 +1,98 @@
|
||||
int main(){
|
||||
|
||||
}
|
||||
#include <exception>
|
||||
#include<fstream>
|
||||
#include <stdexcept>
|
||||
#include<string>
|
||||
#include<algorithm>
|
||||
#include<iostream>
|
||||
#include <type_traits>
|
||||
#include"tools.hpp"
|
||||
|
||||
// std::string reversedComplement(std::string DNAsequence);
|
||||
|
||||
std::string reverseComplement(std::string DNAsequence)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
string l = "";
|
||||
int i;
|
||||
int q = DNAsequence.length();
|
||||
reverse(DNAsequence.begin(), DNAsequence.end()); //将字符串反过来
|
||||
for (i = 0; i < q; i++)
|
||||
{
|
||||
if (DNAsequence[i] == 'A')
|
||||
l = l + 'T';
|
||||
if (DNAsequence[i] == 'a')
|
||||
l = l + 'T';
|
||||
if (DNAsequence[i] == 'c')
|
||||
l = l + 'G';
|
||||
if (DNAsequence[i] == 'C')
|
||||
l = l + 'G';
|
||||
if (DNAsequence[i] == 'g')
|
||||
l = l + 'C';
|
||||
if (DNAsequence[i] == 'G')
|
||||
l = l + 'C';
|
||||
if (DNAsequence[i] == 't')
|
||||
l = l + 'A';
|
||||
if (DNAsequence[i] == 'T')
|
||||
l = l + 'A';
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
template <class ...Args>
|
||||
void check_fstream_isopen(const Args&...args)noexcept(false){
|
||||
bool is_open=true;
|
||||
(((!args.is_open())?is_open=false:true),...);
|
||||
if(is_open==false){
|
||||
throw std::runtime_error("cannot open file stream ");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
try{
|
||||
std::ios_base::sync_with_stdio(false); //加了没效果
|
||||
using namespace std;
|
||||
|
||||
char buf[50000];
|
||||
int lines = 0;
|
||||
|
||||
|
||||
|
||||
ifstream inputFile("filteredReads.txt");
|
||||
ofstream outputFile("reversedSequence.txt");
|
||||
|
||||
check_fstream_isopen(inputFile,outputFile);
|
||||
|
||||
zt::print("open file ok!");
|
||||
|
||||
string l = "";
|
||||
|
||||
while (inputFile.getline(buf,50000,'\n'))
|
||||
{
|
||||
int m = lines%2;
|
||||
|
||||
if (m == 1)
|
||||
outputFile << reverseComplement(buf) << endl;
|
||||
else
|
||||
outputFile << buf << endl;
|
||||
lines++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}catch(const std::exception &e){
|
||||
zt::print(
|
||||
"Caught an error because:\n",
|
||||
"\t",NAME_VALUE(e.what()),"\n"
|
||||
"closing\n"
|
||||
);
|
||||
}catch(...){
|
||||
zt::print(
|
||||
"Caught an unknown error because:\n",
|
||||
"Closing\n"
|
||||
);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
72
src/tools/tools.hpp
Normal file
72
src/tools/tools.hpp
Normal file
@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
|
||||
#define NAME_VALUE(v)#v," : ",(v)
|
||||
|
||||
namespace zt {
|
||||
template<typename T>
|
||||
class Range{
|
||||
private:
|
||||
const T _start,_end,_step;
|
||||
public:
|
||||
constexpr Range()=delete;
|
||||
constexpr Range(const T start,const T end,const T step)noexcept:_start(start),_end(end),_step(step){}
|
||||
constexpr Range(const T start,const T end)noexcept:Range(start,end,1){}
|
||||
constexpr Range(const T end)noexcept:Range(0,end,1){}
|
||||
|
||||
struct Iterator{
|
||||
T current;
|
||||
const T step;
|
||||
|
||||
constexpr Iterator()=delete;
|
||||
constexpr Iterator(const T start,const T step)noexcept:current(start),step(step){}
|
||||
constexpr bool operator!=(const Iterator &other)const noexcept{
|
||||
return current<other.current;
|
||||
}
|
||||
constexpr Iterator& operator++()noexcept{
|
||||
current+=step;
|
||||
return *this;
|
||||
}
|
||||
constexpr T operator*()const noexcept{
|
||||
return current;
|
||||
}
|
||||
};
|
||||
|
||||
constexpr Iterator begin()const{
|
||||
return Iterator(_start,_step);
|
||||
}
|
||||
constexpr Iterator end()const{
|
||||
return Iterator(_end,_step);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename ...Args>
|
||||
inline void raw_print(std::ostream &os,const Args&...args){
|
||||
std::ostringstream ss;
|
||||
((ss<<args),...);
|
||||
os<<ss.str();
|
||||
return;
|
||||
}
|
||||
|
||||
template<typename ...Args>
|
||||
inline void print(const Args&...args){
|
||||
raw_print(std::cout,args...);
|
||||
return;
|
||||
}
|
||||
inline void print(){
|
||||
return;
|
||||
}
|
||||
|
||||
template<typename ...Args>
|
||||
inline void eprint(const Args&...args){
|
||||
raw_print(std::cerr,args...);
|
||||
return;
|
||||
}
|
||||
|
||||
inline void eprint(){
|
||||
return;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user