modified: SpatialOmicsCoord.py
[GalaxyCodeBases.git] / c_cpp / etc / KaKs_Calculator / src / ConcatenatePairs.cpp
blobd0e8c0a3123963114efbb633de29296b425df162
1 /************************************************************
2 * Copyright (C) 2005, BGI of Chinese Academy of Sciences
3 * All rights reserved.
5 * Filename: ConcatenatePairs.cpp
6 * Abstract: Concatenate all pairs of sequences with AXT format
7 to a pair of sequences (maybe very long).
9 * Version: 1.0
10 * Author: Zhang Zhang (zhanghzhang@genomics.org.cn)
11 * Date: Feb.2, 2005
13 * Modified Version:
14 * Modified Author:
15 * Modified Date:
16 *************************************************************/
17 #include<string>
18 #include<iostream>
19 #include<fstream>
21 using namespace std;
23 string result; //Result for outputing into a file
25 bool readFile(const char *filename) {
27 bool flag = true;
28 string seq1, seq2;
29 seq1 = seq2 ="";
31 try {
32 ifstream is(filename);
33 if (!is) {
34 cout<<"\nError in opening file..."<<endl;
35 throw 1;
38 cout<<"\nPlease wait while reading sequences and concatenating..."<<endl;
40 string temp="", name="", str="";
42 while (getline(is, temp, '\n')) {
44 name = temp;
46 getline(is, temp, '\n');
47 while (temp!="") {
48 str += temp;
49 getline(is, temp, '\n');
52 seq1 += str.substr(0, str.length()/2);
53 seq2 += str.substr(str.length()/2, str.length()/2);
54 name = str = "";
57 is.close();
58 is.clear();
60 result += "Concatenate-"; result += filename; result += '\n';
61 result += seq1; result += '\n';
62 result += seq2; result += '\n';
63 result += '\n';
66 catch (...) {
68 flag = false;
71 return flag;
74 bool writeFile(const char *filename, const char *content) {
76 bool flag=true;
78 try {
79 ofstream os(filename);
80 os<<content;
81 os.close();
83 catch (...) {
84 cout<<"Error in writing file..."<<endl;
85 flag = false;
88 return flag;
92 int main(int argc, char* argv[]) {
94 if (argc!=3) {
95 cout<<"Description: Concatenate all pairs of sequences with AXT format to a pair of sequences."<<endl;
96 cout<<"Usage: ConPairs [AXT Filename] [Output Filename]"<<endl;
97 return 0;
100 try {
101 if (!readFile(argv[1])) throw 1;
102 if (!writeFile(argv[2], result.c_str())) throw 1;
103 cout<<"Mission accomplished."<<endl;
106 catch (...) {
107 cout<<"Mission failed."<<endl;
110 return 1;