modified: myjupyterlab.sh
[GalaxyCodeBases.git] / BGI / SOAPsnp / FileListManager.h
bloba41ac80643e00e3b4aacd5685bd783fcc29767f7
1 /*
2 ******************************************************************************
3 *Copyright 2010
4 * BGI-SHENZHEN
5 *All Rights Reserved
6 *ATHUOR : Bill Tang
7 *CREATE DATE : 2010-8-9
8 *CLASS NAME: FileListManager
9 *FUNCTION : a class that can control file list. support open, readline, close etc
10 * file functions.
11 *FILE NAME : FileListManager.h
12 *UPDATE DATE : 2010-8-19
13 *UPDATE BY : Bill Tang
14 *UPDATA DATA : 2010-8.30
15 *UPDATA BY :ZHOU GUYUE
16 *UPDATE: 2010-11-2 change the m_soap_file_vec's type, to vector<*igzstream>.
17 change the interface which is related to soap file.
18 *UPDATA BY :BIll Tang
19 *******************************************************************************
22 #pragma once
24 /*define some error number*/
25 #define CNSFILE_ERROR -2 //can not open cnsFile
26 #define BASEFILE_ERROR -1 //can not open listFile
27 #define SOAPFILE_ERROR -2 //can not open soapFile
28 #define SAMFILE_ERROR -2 //can not open sam/bamFile
29 #define SETLIMIT_ERROR -3 //can not set limit
31 #define SETLIMIT_OK 3
32 #define INDEX_OVER_FLOW NULL // index is over flow
33 #define COUNT_ERROR -3 // the readwin_vec size not equal to the out files number.
34 #define INPUT_ERROR -4 // the input files has something wrong.
35 #define FILE_END 2 // file is end.
37 #include "SamCtrl.h"
38 #include "Readwin.h"
39 #include "soap_snp.h"
40 #include "CThreadPool.h"
41 #include "Call_winManager.h"
43 using namespace std;
45 class FileListManager
47 int m_file_number; // file number in file list.
48 my_ifstream m_base_file; // the handle of the file that contain file list.
49 vector<igzstream*> m_soap_file_vec; // the handle vector of the files which are soap format.
50 vector<SamCtrl*> m_sam_file_vec; // the handle vector of the files which are sam/bam format.
51 vector<gzoutstream*> m_cns_file_vec; // the handle vector of the output files.
52 vector<fstream*> m_matrix_file_vec; // a vector stored the file handle which are matrix files
53 int m_stop_pos; // record the position once one of the samples reach a break point that the chromosome changed.
54 int m_endfile_count; // record the file's count that reach the end.
55 public:
56 FileListManager();
57 virtual ~FileListManager();
58 // open output file function
59 virtual int openCnsFile(const string& path, const string& outdir, const char* mode, Parameter * para);
60 // open all the file in the file list
61 virtual int openAli(const string& listfilename, const char* mode);
62 // open sam/bam file
63 virtual int openSamFile(const string& listfilename, const char* mode);
64 // open soap format file
65 virtual int openSoapFile(const string& listfilename);
66 // read a line from the *vec[index]
67 virtual int readLine(string& line, const int index);
68 // close alignment files
69 virtual void closeAliFiles(void);
70 // close consensus files
71 virtual void closeCnsFiles(void);
72 // read lines to the readwin_vec. The lines' start position must inside a win size. When the lines' end position exceed the win,put it to the next win.
73 virtual int readWin(vector<Readwin>& readwin_vec, Parameter * para);
74 // get the soap file handle pointer m_soap_file_vec[index]
75 virtual igzstream * getSoapFile(const int index);
76 // get the soap file handle pointer m_soap_file_vec[index]
77 virtual SamCtrl* getSamFile(const int index);
78 // read record from soapfile and send to the readwin.
79 virtual int readWinFromSoap(Readwin& readwin, igzstream& soapfile);
80 // read record from samCtrl and send to the readwin.
81 virtual int readWinFromSam(Readwin& readwin, SamCtrl& samCtrl);
82 // get the file number
83 virtual int getFileNum(void);
84 // get handle of consensus file.
85 virtual gzoutstream* getCnsFile(const int index);
86 // open matrix files with open_mode mode
87 virtual int openMatrixFile(const std::string matrix_list, std::ios_base::open_mode mode, const std::string alignment_list = "");
88 // get the matrix file handle
89 virtual fstream* getMatrixFile(const int index);
90 //set limit of file number;
91 //virtual int setlimit(int filenumber); //update by zhukai on 2010-12-28
95 //2010-11-08
97 typedef struct _read_win_args
99 //FileListManager * fileListManager_p;
100 Readwin * readwin_p;
101 igzstream * m_soap_file_p;
102 SamCtrl * m_sam_file_p;
103 int * ret_p;
104 int index;
106 inline _read_win_args(Readwin * b, igzstream *c, SamCtrl * f,int * d, int e)
108 //fileListManager_p = a;
109 readwin_p = b;
110 m_soap_file_p = c;
111 m_sam_file_p = f;
112 //cerr <<"111 ret_p = d "<<endl;
113 ret_p = d;
114 index = e;
116 /*inline _read_win_args(Readwin * b,SamCtrl *c, int * d, int e)
118 //fileListManager_p = a;
119 readwin_p = b;
120 m_sam_file_p = c;
121 m_soap_file_p = NULL;
122 ret_p = d;
123 index = e;
124 };*/
125 inline _read_win_args()
127 //fileListManager_p = NULL;
128 readwin_p = NULL;
129 m_soap_file_p = NULL;
130 m_sam_file_p = NULL;
131 ret_p = NULL;
132 index = 0;
134 }READ_WIN_ARGS;
136 class Read_win_Task : public CTask
138 public:
139 FileListManager fileListManager;
140 // overload the function Run().
141 int Run();
143 _call_winManager_soap2cns_norm(this->m_ptrData);
144 return 1;
148 // 2010-11-12 the function readWin's parameter structure.
149 typedef struct _big_read_win_args
151 FileListManager * fileListManager;
152 vector<Readwin> * readwin_vec;
153 Parameter * para;
155 inline _big_read_win_args(FileListManager * a, vector<Readwin> * b, Parameter * c)
157 fileListManager = a;
158 readwin_vec = b;
159 para = c;
162 inline _big_read_win_args()
164 fileListManager = NULL;
165 readwin_vec = NULL;
166 para = NULL;
168 } BIG_READ_WIN_ARGS;
170 void *_flieListManager_readWin(void * args);