2 ******************************************************************************
7 *CREATE DATE : 2010-8-9
8 *CLASS NAME: FileListManager
9 *FUNCTION : a class that can control file list. support open, readline, close etc
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.
19 *******************************************************************************
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
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.
40 #include "CThreadPool.h"
41 #include "Call_winManager.h"
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.
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
);
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
97 typedef struct _read_win_args
99 //FileListManager * fileListManager_p;
101 igzstream
* m_soap_file_p
;
102 SamCtrl
* m_sam_file_p
;
106 inline _read_win_args(Readwin
* b
, igzstream
*c
, SamCtrl
* f
,int * d
, int e
)
108 //fileListManager_p = a;
112 //cerr <<"111 ret_p = d "<<endl;
116 /*inline _read_win_args(Readwin * b,SamCtrl *c, int * d, int e)
118 //fileListManager_p = a;
121 m_soap_file_p = NULL;
125 inline _read_win_args()
127 //fileListManager_p = NULL;
129 m_soap_file_p
= NULL
;
136 class Read_win_Task
: public CTask
139 FileListManager fileListManager
;
140 // overload the function Run().
143 _call_winManager_soap2cns_norm(this->m_ptrData);
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
;
155 inline _big_read_win_args(FileListManager
* a
, vector
<Readwin
> * b
, Parameter
* c
)
162 inline _big_read_win_args()
164 fileListManager
= NULL
;
170 void *_flieListManager_readWin(void * args
);