annotate PsiCLASS-1.0.2/classes.cpp @ 0:903fc43d6227 draft default tip

Uploaded
author lsong10
date Fri, 26 Mar 2021 16:52:45 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
1 #include <stdio.h>
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
2 #include <getopt.h>
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
3 #include <vector>
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
4 #include <pthread.h>
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
5
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
6 #include "alignments.hpp"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
7 #include "SubexonGraph.hpp"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
8 #include "SubexonCorrelation.hpp"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
9 #include "Constraints.hpp"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
10 #include "TranscriptDecider.hpp"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
11
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
12 char usage[] = "./classes [OPTIONS]:\n"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
13 "Required:\n"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
14 "\t-s STRING: path to the subexon file.\n"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
15 "\t-b STRING: path to the BAM file.\n"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
16 "\t\tor\n"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
17 "\t--lb STRING: path to the file of the list of BAM files.\n"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
18 "Optional:\n"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
19 "\t-p INT: number of threads. (default: 1)\n"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
20 "\t-o STRING: the prefix of the output file. (default: not used)\n"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
21 "\t-c FLOAT: only use the subexons with classifier score <= than the given number. (default: 0.05)\n"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
22 "\t-f FLOAT: filter the transcript from the gene if its abundance is lower than the given number percent of the most abundant one. (default: 0.05)\n"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
23 "\t-d FLOAT: filter the transcript whose average read depth is less than the given number. (default: 2.5)\n"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
24 "\t--ls STRING: path to the file of the list of single-sample subexon files. (default: not used)\n"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
25 "\t--hasMateIdSuffix: the read id has suffix such as .1, .2 for a mate pair. (default: false)\n"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
26 "\t--maxDpConstraintSize: the maximum number of subexons a constraint can cover in dynamic programming. (default: 7; -1 for inf)\n"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
27 "\t--primaryParalog: use primary alignment to retain paralog genes instead of unique alignments. (default: not used)\n"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
28 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
29
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
30 static const char *short_options = "s:b:f:o:d:p:c:h" ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
31 static struct option long_options[] =
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
32 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
33 { "ls", required_argument, 0, 10000 },
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
34 { "lb", required_argument, 0, 10001 },
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
35 { "hasMateIdSuffix", no_argument, 0, 10002 },
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
36 { "primaryParalog", no_argument, 0, 10003 },
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
37 { "maxDpConstraintSize", required_argument, 0, 10004 },
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
38 { (char *)0, 0, 0, 0}
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
39 } ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
40
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
41 struct _getAlignmentsInfoThreadArg
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
42 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
43 std::vector<Alignments> *pAlignmentFiles ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
44 int numThreads ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
45 int tid ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
46 } ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
47
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
48 struct _getConstraintsThreadArg
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
49 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
50 std::vector<Constraints> *pMultiSampleConstraints ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
51 int numThreads ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
52 int tid ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
53
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
54 struct _subexon *subexons ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
55 int seCnt ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
56 int start, end ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
57 } ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
58
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
59 void *GetAlignmentsInfo_Thread( void *pArg )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
60 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
61 int i ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
62 std::vector <Alignments> &alignmentFiles = *( ( (struct _getAlignmentsInfoThreadArg *)pArg )->pAlignmentFiles ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
63 int tid = ( (struct _getAlignmentsInfoThreadArg *)pArg )->tid ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
64 int numThreads = ( (struct _getAlignmentsInfoThreadArg *)pArg )->numThreads ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
65 int size = alignmentFiles.size() ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
66 for ( i = 0 ; i < size ; ++i )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
67 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
68 if ( i % numThreads == tid )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
69 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
70 alignmentFiles[i].GetGeneralInfo( true ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
71 alignmentFiles[i].Rewind() ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
72 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
73 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
74
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
75 pthread_exit( NULL ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
76 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
77
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
78
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
79 void *GetConstraints_Thread( void *pArg )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
80 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
81 int i ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
82 struct _getConstraintsThreadArg &arg = *( (struct _getConstraintsThreadArg *)pArg ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
83 std::vector<Constraints> &multiSampleConstraints = *( arg.pMultiSampleConstraints ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
84 int tid = arg.tid ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
85 int numThreads = arg.numThreads ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
86 int size = multiSampleConstraints.size() ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
87 for ( i = 0 ; i < size ; ++i )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
88 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
89 if ( i % numThreads == tid )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
90 multiSampleConstraints[i].BuildConstraints( arg.subexons, arg.seCnt, arg.start, arg.end ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
91 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
92 pthread_exit( NULL ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
93 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
94
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
95 int main( int argc, char *argv[] )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
96 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
97 int i, j ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
98 int size ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
99
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
100 if ( argc <= 1 )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
101 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
102 printf( "%s", usage ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
103 return 0 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
104 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
105
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
106 int c, option_index ; // For getopt
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
107 option_index = 0 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
108 FILE *fpSubexon = NULL ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
109 double FPKMFraction = 0.05 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
110 double classifierThreshold ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
111 double txptMinReadDepth = 2.5 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
112 char outputPrefix[1024] = "" ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
113 int numThreads = 1 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
114 bool hasMateReadIdSuffix = false ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
115 bool usePrimaryAsUnique = false ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
116 int maxDpConstraintSize = 7 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
117
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
118 std::vector<Alignments> alignmentFiles ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
119 SubexonCorrelation subexonCorrelation ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
120
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
121 classifierThreshold = 0.05 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
122 while ( 1 )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
123 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
124 c = getopt_long( argc, argv, short_options, long_options, &option_index ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
125 if ( c == -1 )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
126 break ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
127
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
128 if ( c == 's' )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
129 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
130 fpSubexon = fopen( optarg, "r" ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
131 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
132 else if ( c == 'b' )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
133 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
134 Alignments a ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
135 a.Open( optarg ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
136 //a.SetAllowClip( false ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
137 alignmentFiles.push_back( a ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
138 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
139 else if ( c == 'c' )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
140 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
141 classifierThreshold = atof( optarg ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
142 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
143 else if ( c == 'f' )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
144 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
145 FPKMFraction = atof( optarg ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
146 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
147 else if ( c == 'o' )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
148 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
149 strcpy( outputPrefix, optarg ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
150 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
151 else if ( c == 'd' )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
152 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
153 txptMinReadDepth = atof( optarg ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
154 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
155 else if ( c == 'p' )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
156 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
157 numThreads = atoi( optarg ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
158 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
159 else if ( c == 10000 ) // the list of subexon files.
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
160 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
161 subexonCorrelation.Initialize( optarg ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
162 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
163 else if ( c == 10001 ) // the list of bam files.
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
164 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
165 FILE *fp = fopen( optarg, "r" ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
166 char buffer[1024] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
167 while ( fgets( buffer, sizeof( buffer ), fp ) != NULL )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
168 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
169 int len = strlen( buffer ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
170 if ( buffer[len - 1] == '\n' )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
171 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
172 buffer[len - 1] = '\0' ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
173 --len ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
174
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
175 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
176 Alignments a ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
177 a.Open( buffer ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
178 alignmentFiles.push_back( a ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
179 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
180 fclose( fp ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
181 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
182 else if ( c == 10002 ) // the mate pair read id has suffix.
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
183 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
184 hasMateReadIdSuffix = true ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
185 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
186 else if ( c == 10003 ) // do not check unique alignment
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
187 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
188 usePrimaryAsUnique = true ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
189 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
190 else if ( c == 10004 ) // maxDpConstraintSize
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
191 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
192 maxDpConstraintSize = atoi(optarg) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
193 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
194 else
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
195 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
196 printf( "%s", usage ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
197 exit( 1 ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
198 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
199 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
200 if ( fpSubexon == NULL )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
201 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
202 printf( "Cannot find combined subexon file.\n" ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
203 exit( 1 ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
204 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
205 if ( alignmentFiles.size() < 1 )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
206 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
207 printf( "Must use -b option to specify BAM files.\n" ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
208 exit( 1 ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
209 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
210
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
211
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
212 if ( alignmentFiles.size() < 50 )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
213 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
214 size = alignmentFiles.size() ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
215 for ( i = 0 ; i < size ; ++i )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
216 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
217 alignmentFiles[i].GetGeneralInfo( true ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
218 alignmentFiles[i].Rewind() ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
219 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
220 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
221 else
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
222 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
223 struct _getAlignmentsInfoThreadArg *args = new struct _getAlignmentsInfoThreadArg[ numThreads ] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
224 pthread_attr_t pthreadAttr ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
225 pthread_t *threads ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
226
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
227 pthread_attr_init( &pthreadAttr ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
228 pthread_attr_setdetachstate( &pthreadAttr, PTHREAD_CREATE_JOINABLE ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
229
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
230 threads = new pthread_t[ numThreads ] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
231
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
232 for ( i = 0 ; i < numThreads ; ++i )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
233 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
234 args[i].pAlignmentFiles = &alignmentFiles ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
235 args[i].tid = i ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
236 args[i].numThreads = numThreads ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
237
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
238 pthread_create( &threads[i], &pthreadAttr, GetAlignmentsInfo_Thread, &args[i] ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
239 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
240
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
241 for ( i = 0 ; i < numThreads ; ++i )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
242 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
243 pthread_join( threads[i], NULL ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
244 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
245
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
246 pthread_attr_destroy( &pthreadAttr ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
247 delete[] args ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
248 delete[] threads ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
249 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
250
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
251 // Build the subexon graph
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
252 SubexonGraph subexonGraph( classifierThreshold, alignmentFiles[0], fpSubexon ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
253 subexonGraph.ComputeGeneIntervals() ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
254
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
255 // Solve gene by gene
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
256 int sampleCnt = alignmentFiles.size() ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
257 std::vector<Constraints> multiSampleConstraints ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
258 for ( i = 0 ; i < sampleCnt ; ++i )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
259 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
260 Constraints constraints( &alignmentFiles[i] ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
261 constraints.SetHasMateReadIdSuffix( hasMateReadIdSuffix ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
262 constraints.SetUsePrimaryAsUnique( usePrimaryAsUnique ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
263 multiSampleConstraints.push_back( constraints ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
264 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
265 MultiThreadOutputTranscript outputHandler( sampleCnt, alignmentFiles[0] ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
266 outputHandler.SetOutputFPs( outputPrefix ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
267
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
268 if ( numThreads <= 1 )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
269 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
270 TranscriptDecider transcriptDecider( FPKMFraction, classifierThreshold, txptMinReadDepth, sampleCnt, alignmentFiles[0] ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
271
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
272 transcriptDecider.SetMultiThreadOutputHandler( &outputHandler ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
273 transcriptDecider.SetNumThreads( numThreads ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
274 transcriptDecider.SetMaxDpConstraintSize( maxDpConstraintSize ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
275
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
276 int giCnt = subexonGraph.geneIntervals.size() ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
277 for ( i = 0 ; i < giCnt ; ++i )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
278 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
279 struct _geneInterval gi = subexonGraph.geneIntervals[i] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
280 struct _subexon *intervalSubexons = new struct _subexon[ gi.endIdx - gi.startIdx + 1 ] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
281 subexonGraph.ExtractSubexons( gi.startIdx, gi.endIdx, intervalSubexons ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
282 printf( "%d: %d %s %d %d\n", i, gi.endIdx - gi.startIdx + 1,
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
283 alignmentFiles[0].GetChromName( intervalSubexons[0].chrId ),
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
284 gi.start + 1, gi.end + 1 ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
285 fflush( stdout ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
286
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
287 subexonCorrelation.ComputeCorrelation( intervalSubexons, gi.endIdx - gi.startIdx + 1, alignmentFiles[0] ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
288 for ( j = 0 ; j < sampleCnt ; ++j )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
289 multiSampleConstraints[j].BuildConstraints( intervalSubexons, gi.endIdx - gi.startIdx + 1, gi.start, gi.end ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
290
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
291 transcriptDecider.Solve( intervalSubexons, gi.endIdx - gi.startIdx + 1, multiSampleConstraints, subexonCorrelation ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
292
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
293 for ( j = 0 ; j < gi.endIdx - gi.startIdx + 1 ; ++j )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
294 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
295 delete[] intervalSubexons[j].prev ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
296 delete[] intervalSubexons[j].next ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
297 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
298 delete[] intervalSubexons ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
299 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
300 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
301 else // multi-thread case.
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
302 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
303 --numThreads ; // one thread is used for read in the data.
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
304
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
305 // Allocate memory
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
306 struct _transcriptDeciderThreadArg *pArgs = new struct _transcriptDeciderThreadArg[ numThreads ] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
307 pthread_mutex_t ftLock ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
308 int *freeThreads ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
309 int ftCnt ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
310 pthread_cond_t fullWorkCond ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
311 pthread_attr_t pthreadAttr ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
312 pthread_t *threads ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
313 pthread_t *getConstraintsThreads ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
314 bool *initThreads ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
315
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
316 pthread_mutex_init( &ftLock, NULL ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
317 pthread_cond_init( &fullWorkCond, NULL ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
318 pthread_attr_init( &pthreadAttr ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
319 pthread_attr_setdetachstate( &pthreadAttr, PTHREAD_CREATE_JOINABLE ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
320
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
321 threads = new pthread_t[ numThreads ] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
322 getConstraintsThreads = new pthread_t[ numThreads ] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
323 initThreads = new bool[numThreads] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
324 freeThreads = new int[ numThreads ] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
325 ftCnt = numThreads ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
326 for ( i = 0 ; i < numThreads ; ++i )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
327 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
328 pArgs[i].tid = i ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
329 pArgs[i].sampleCnt = sampleCnt ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
330 pArgs[i].numThreads = numThreads ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
331 pArgs[i].maxDpConstraintSize = maxDpConstraintSize ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
332 pArgs[i].FPKMFraction = FPKMFraction ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
333 pArgs[i].classifierThreshold = classifierThreshold ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
334 pArgs[i].txptMinReadDepth = txptMinReadDepth ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
335 pArgs[i].alignments = &alignmentFiles[0] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
336 //pArgs[i].constraints = new std::vector<Constraints> ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
337 pArgs[i].outputHandler = &outputHandler ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
338
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
339 freeThreads[i] = i ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
340 pArgs[i].freeThreads = freeThreads ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
341 pArgs[i].ftCnt = &ftCnt ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
342 pArgs[i].ftLock = &ftLock ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
343 pArgs[i].fullWorkCond = &fullWorkCond ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
344
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
345 for ( j = 0 ; j < sampleCnt ; ++j )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
346 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
347 Constraints constraints( &alignmentFiles[j] ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
348 pArgs[i].constraints.push_back( constraints ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
349 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
350
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
351 initThreads[i] = false ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
352 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
353
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
354
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
355 // Read in and distribute the work
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
356 int giCnt = subexonGraph.geneIntervals.size() ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
357 for ( i = 0 ; i < giCnt ; ++i )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
358 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
359 struct _geneInterval gi = subexonGraph.geneIntervals[i] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
360 struct _subexon *intervalSubexons = new struct _subexon[ gi.endIdx - gi.startIdx + 1 ] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
361 subexonGraph.ExtractSubexons( gi.startIdx, gi.endIdx, intervalSubexons ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
362 subexonCorrelation.ComputeCorrelation( intervalSubexons, gi.endIdx - gi.startIdx + 1, alignmentFiles[0] ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
363 printf( "%d: %d %s %d %d. Free threads: %d/%d\n", i, gi.endIdx - gi.startIdx + 1,
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
364 alignmentFiles[0].GetChromName( intervalSubexons[0].chrId ),
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
365 gi.start + 1, gi.end + 1, ftCnt, numThreads + 1 ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
366 fflush( stdout ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
367
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
368 int gctCnt = ftCnt ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
369 if ( gctCnt > 1 && sampleCnt > 1 )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
370 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
371 gctCnt = ( gctCnt < sampleCnt ? gctCnt : sampleCnt ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
372 struct _getConstraintsThreadArg *args = new struct _getConstraintsThreadArg[ gctCnt ] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
373 for ( j = 0 ; j < gctCnt ; ++j )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
374 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
375 args[j].pMultiSampleConstraints = &multiSampleConstraints ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
376 args[j].numThreads = gctCnt ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
377 args[j].tid = j ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
378 args[j].subexons = intervalSubexons ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
379 args[j].seCnt = gi.endIdx - gi.startIdx + 1 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
380 args[j].start = gi.start ; args[j].end = gi.end ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
381 pthread_create( &getConstraintsThreads[j], &pthreadAttr, GetConstraints_Thread, &args[j] ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
382 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
383
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
384
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
385
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
386 for ( j = 0 ; j < gctCnt ; ++j )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
387 pthread_join( getConstraintsThreads[j], NULL ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
388
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
389 delete[] args ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
390 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
391 else
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
392 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
393 for ( j = 0 ; j < sampleCnt ; ++j )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
394 multiSampleConstraints[j].BuildConstraints( intervalSubexons, gi.endIdx - gi.startIdx + 1, gi.start, gi.end ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
395 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
396
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
397 // Search for the free queue.
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
398 int tag = -1 ; // get the working thread.
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
399 pthread_mutex_lock( &ftLock ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
400 if ( ftCnt == 0 )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
401 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
402 pthread_cond_wait( &fullWorkCond, &ftLock ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
403 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
404 tag = freeThreads[ ftCnt - 1 ] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
405 --ftCnt ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
406 pthread_mutex_unlock( &ftLock ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
407
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
408 if ( initThreads[tag] )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
409 pthread_join( threads[tag], NULL ) ; // Make sure the chosen thread exits.
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
410
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
411 // Assign the subexons, the constraints and correlation content.
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
412 pArgs[tag].subexons = new struct _subexon[gi.endIdx - gi.startIdx + 1] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
413 pArgs[tag].seCnt = gi.endIdx - gi.startIdx + 1 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
414 for ( j = 0 ; j < pArgs[tag].seCnt ; ++j )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
415 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
416 pArgs[tag].subexons[j] = intervalSubexons[j] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
417 int cnt = intervalSubexons[j].prevCnt ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
418 pArgs[tag].subexons[j].prev = new int[cnt] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
419 memcpy( pArgs[tag].subexons[j].prev, intervalSubexons[j].prev, sizeof( int ) * cnt ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
420 cnt = intervalSubexons[j].nextCnt ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
421 pArgs[tag].subexons[j].next = new int[cnt] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
422 memcpy( pArgs[tag].subexons[j].next, intervalSubexons[j].next, sizeof( int ) * cnt ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
423 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
424
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
425 for ( j = 0 ; j < sampleCnt ; ++j )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
426 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
427 pArgs[tag].constraints[j].Assign( multiSampleConstraints[ j ] ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
428 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
429 pArgs[tag].subexonCorrelation.Assign( subexonCorrelation ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
430 pthread_create( &threads[tag], &pthreadAttr, TranscriptDeciderSolve_Wrapper, &pArgs[tag] ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
431 initThreads[tag] = true ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
432 for ( j = 0 ; j < gi.endIdx - gi.startIdx + 1 ; ++j )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
433 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
434 delete[] intervalSubexons[j].prev ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
435 delete[] intervalSubexons[j].next ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
436 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
437 delete[] intervalSubexons ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
438 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
439
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
440 for ( i = 0 ; i < numThreads ; ++i )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
441 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
442 if ( initThreads[i] )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
443 pthread_join( threads[i], NULL ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
444 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
445
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
446 // Release memory
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
447 for ( i = 0 ; i < numThreads ; ++i )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
448 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
449 std::vector<Constraints>().swap( pArgs[i].constraints ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
450 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
451 delete []pArgs ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
452 pthread_attr_destroy( &pthreadAttr ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
453 pthread_mutex_destroy( &ftLock ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
454 pthread_cond_destroy( &fullWorkCond ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
455
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
456 delete[] threads ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
457 delete[] getConstraintsThreads ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
458 delete[] initThreads ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
459 delete[] freeThreads ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
460 } // end of else for multi-thread.
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
461
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
462 outputHandler.OutputCommandInfo( argc, argv ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
463 for ( i = 0 ; i < sampleCnt ; ++i )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
464 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
465 char buffer[1024] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
466 alignmentFiles[i].GetFileName( buffer ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
467 int separator = -1 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
468
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
469 // deprive the directory.
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
470 for ( j = 0 ; buffer[j] ; ++j )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
471 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
472 if ( buffer[j] == '/' )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
473 separator = j ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
474 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
475 if ( separator != -1 )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
476 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
477 ++separator ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
478 for ( j = separator ; buffer[j] ; ++j )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
479 buffer[j - separator] = buffer[j] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
480 buffer[j - separator] = '\0' ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
481 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
482 outputHandler.OutputCommentToSampleGTF( i, buffer ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
483 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
484 outputHandler.ComputeFPKMTPM( alignmentFiles ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
485 outputHandler.Flush() ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
486
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
487 for ( i = 0 ; i < sampleCnt ; ++i )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
488 alignmentFiles[i].Close() ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
489 fclose( fpSubexon ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
490 return 0 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
491 }