modified: pixi.toml
[GalaxyCodeBases.git] / released / pIRS.old / stat_illumina_reads / gcvgstater / main.cpp
blob7976a66b519259ed942f3158ebd39575d5cfc0b8
1 #include <iostream>
2 #include <string>
3 #include <vector>
4 #include <map>
5 #include <iterator>
6 #include <cstdlib>
7 #include "gzstream.h"
8 #include "self_util.h"
9 #include "stat_soap_coverage.h"
11 using namespace std;
13 void usage()
15 cerr << "Description:" << endl
16 << " it is a program to stat about the gc_depth and base coverage ratio and base_depth with *.soap.coverage result." << endl
17 << "Program:" << endl
18 << "Name: gc_coverage_bias" << endl
19 << "Compile Date: 2011-08-03" << endl
20 << "Author: ganjun" << endl
21 << "Version: 1.01" << endl
22 << "Contact: ganjun@genomics.org,cn" << endl;
24 cerr << "\n\nUsage:\tgc_coverage_bias [options] <*.soap.coverage>" << endl
25 << "Option: -r <string> a reference sequence file about FA format " << endl
26 << " -o <string> the the prefix about output file" << endl
27 << " -w <string> the window length[such as:100,200,300] " << endl
28 << " --gcdump output the gc ratio in the window length " << endl
29 << " --depwindump output the avg depth in the window length " << endl;
31 cerr << "\n\nUsage:" << endl
32 << "\t./gc_coverage_bias -r test.fa -o test -w 40,50 [--gcdump --depwindump] test.depth" << endl;
33 exit(EXIT_FAILURE);
37 map<string, string> DealReference(string str_ref_file_name);
38 map<string, vector<vector<uint64_t, uint64_t, uint64_t> >, uint64_t> DealSoapCoverage()
42 int main(int argc, char* argv[])
44 if(argc < 8)
46 usage();
49 string str_argv;
50 string str_ref_file_name;
51 string str_width;
52 string str_output_prefix;
53 bool b_gcdump = false;
54 bool b_depwindump = false;
55 vector<string> vec_soap_file_name;
56 vector<string> vec_width;
58 for(int i=1; i<argc; ++i)
60 str_argv = argv[i];
62 if(str_argv.compare("-r") == 0)
64 ++i;
65 str_ref_file_name = argv[i];
66 continue;
69 if(str_argv.compare("-o") == 0)
71 ++i;
72 str_output_prefix = argv[i];
73 continue;
76 if(str_argv.compare("-w") == 0)
78 ++i;
79 str_width = argv[i];
80 continue;
83 if(str_argv.compare("--gcdump") == 0)
85 b_gcdump = true;
86 continue;
89 if(str_argv.compare("--depwindump") == 0)
91 b_depwindump = true;
92 continue;
95 vec_soap_file_name.push_back(argv[i]);
98 if(str_ref_file_name.empty())
100 usage();
101 }else
103 igzstream in(str_ref_file_name.c_str());
105 if(!in)
107 cerr << "can't open the reference file " << str_ref_file_name << ", please check!" << endl;
108 exit(EXIT_FAILURE);
111 in.close();
114 if(str_output_prefix.empty())
116 usage();
119 if(str_width.empty())
121 usage();
123 else
125 vec_width = splitString(str_width, ",");
128 //cerr << vec_soap_file_name.size() << endl;
129 for(vector<string>::iterator it = vec_soap_file_name.begin(); it != vec_soap_file_name.end(); ++it)
131 igzstream in((*it).c_str());
133 if(!in)
135 cerr << "can't open the reference file " << *it << ", please check!" << endl;
136 exit(EXIT_FAILURE);
139 in.close();
142 stat_soap_coverage test(str_ref_file_name, str_output_prefix, vec_soap_file_name, vec_width, b_gcdump, b_depwindump);
146 map<string, string> DealReference(string str_ref_file_name)
148 igzstream in(str_ref_file.name);
149 string line;
150 map<string, string> map_reference_base;
151 string keyname;
152 string sequence;
154 while(getline(in, line))
156 TrimLeft(line);
157 TrimRight(line);
159 if(line[0] == '>')
161 if(sequence.length() != 0)
163 map_reference_base[keyname] = sequence;
165 int index;
166 if(((index = line.find(" ")) == string::npos) || ((index = line.find("\t")) == string::npos) || ((index = line.find("\n")) == string::npos))
168 keyname = line.substr(1, index);
170 sequence.clear();
171 continue;
174 sequence += line;
177 if(sequence.length() != 0)
179 map_reference_base[keyname] = sequence;
182 in.close();