Mercurial > repos > calkan > mrfast
comparison mrfast-2.1.0.5/Output.c @ 1:d4054b05b015 default tip
Version update to 2.1.0.5
author | calkan |
---|---|
date | Fri, 09 Mar 2012 07:35:51 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:7b3dc85dc7fd | 1:d4054b05b015 |
---|---|
1 /* | |
2 * Copyright (c) <2008 - 2012>, University of Washington, Simon Fraser University | |
3 * All rights reserved. | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without modification, | |
6 * are permitted provided that the following conditions are met: | |
7 * | |
8 * Redistributions of source code must retain the above copyright notice, this list | |
9 * of conditions and the following disclaimer. | |
10 * - Redistributions in binary form must reproduce the above copyright notice, this | |
11 * list of conditions and the following disclaimer in the documentation and/or other | |
12 * materials provided with the distribution. | |
13 * - Neither the names of the University of Washington, Simon Fraser University, | |
14 * nor the names of its contributors may be | |
15 * used to endorse or promote products derived from this software without specific | |
16 * prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
26 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 /* | |
32 Authors: | |
33 Farhad Hormozdiari | |
34 Faraz Hach | |
35 Can Alkan | |
36 Emails: | |
37 farhadh AT uw DOT edu | |
38 fhach AT cs DOT sfu DOT ca | |
39 calkan AT uw DOT edu | |
40 */ | |
41 | |
42 | |
43 #include <stdio.h> | |
44 #include <stdlib.h> | |
45 #include <zlib.h> | |
46 #include <string.h> | |
47 #include "Common.h" | |
48 #include "Output.h" | |
49 | |
50 FILE *_out_fp; | |
51 gzFile _out_gzfp; | |
52 | |
53 char buffer[300000]; | |
54 int bufferSize = 0; | |
55 | |
56 | |
57 void finalizeGZOutput() | |
58 { | |
59 gzclose(_out_gzfp); | |
60 } | |
61 | |
62 void finalizeTXOutput() | |
63 { | |
64 fclose(_out_fp); | |
65 } | |
66 | |
67 | |
68 void gzOutputQ(SAM map) | |
69 { | |
70 gzprintf(_out_gzfp, "%s\t%d\t%s\t%d\t%d\t%s\t%s\t%d\t%d\t%s\t%s", | |
71 map.QNAME, | |
72 map.FLAG, | |
73 map.RNAME, | |
74 map.POS, | |
75 map.MAPQ, | |
76 map.CIGAR, | |
77 map.MRNAME, | |
78 map.MPOS, | |
79 map.ISIZE, | |
80 map.SEQ, | |
81 map.QUAL); | |
82 | |
83 int i; | |
84 | |
85 for ( i = 0; i < map.optSize; i++) | |
86 { | |
87 switch (map.optFields[i].type) | |
88 { | |
89 case 'A': | |
90 gzprintf(_out_gzfp, "\t%s:%c:%c", map.optFields[i].tag, map.optFields[i].type, map.optFields[i].cVal); | |
91 break; | |
92 case 'i': | |
93 gzprintf(_out_gzfp, "\t%s:%c:%d", map.optFields[i].tag, map.optFields[i].type, map.optFields[i].iVal); | |
94 break; | |
95 case 'f': | |
96 gzprintf(_out_gzfp, "\t%s:%c:%f", map.optFields[i].tag, map.optFields[i].type, map.optFields[i].fVal); | |
97 break; | |
98 case 'Z': | |
99 case 'H': | |
100 gzprintf(_out_gzfp, "\t%s:%c:%s", map.optFields[i].tag, map.optFields[i].type, map.optFields[i].sVal); | |
101 break; | |
102 } | |
103 } | |
104 gzprintf(_out_gzfp, "\n"); | |
105 } | |
106 | |
107 void outputSAM(FILE *fp, SAM map) | |
108 { | |
109 fprintf(fp, "%s\t%d\t%s\t%d\t%d\t%s\t%s\t%d\t%d\t%s\t%s", | |
110 map.QNAME, | |
111 map.FLAG, | |
112 map.RNAME, | |
113 map.POS, | |
114 map.MAPQ, | |
115 map.CIGAR, | |
116 map.MRNAME, | |
117 map.MPOS, | |
118 map.ISIZE, | |
119 map.SEQ, | |
120 map.QUAL); | |
121 | |
122 | |
123 int i; | |
124 | |
125 for ( i = 0; i < map.optSize; i++) | |
126 { | |
127 switch (map.optFields[i].type) | |
128 { | |
129 case 'A': | |
130 fprintf(fp, "\t%s:%c:%c", map.optFields[i].tag, map.optFields[i].type, map.optFields[i].cVal); | |
131 break; | |
132 case 'i': | |
133 fprintf(fp, "\t%s:%c:%d", map.optFields[i].tag, map.optFields[i].type, map.optFields[i].iVal); | |
134 break; | |
135 case 'f': | |
136 fprintf(fp, "\t%s:%c:%f", map.optFields[i].tag, map.optFields[i].type, map.optFields[i].fVal); | |
137 break; | |
138 case 'Z': | |
139 case 'H': | |
140 fprintf(fp, "\t%s:%c:%s", map.optFields[i].tag, map.optFields[i].type, map.optFields[i].sVal); | |
141 break; | |
142 } | |
143 } | |
144 | |
145 fprintf(fp, "\n"); | |
146 | |
147 } | |
148 | |
149 void outputQ(SAM map) | |
150 { | |
151 | |
152 fprintf(_out_fp, "%s\t%d\t%s\t%d\t%d\t%s\t%s\t%d\t%d\t%s\t%s", | |
153 map.QNAME, | |
154 map.FLAG, | |
155 map.RNAME, | |
156 map.POS, | |
157 map.MAPQ, | |
158 map.CIGAR, | |
159 map.MRNAME, | |
160 map.MPOS, | |
161 map.ISIZE, | |
162 map.SEQ, | |
163 map.QUAL); | |
164 | |
165 | |
166 int i; | |
167 | |
168 for ( i = 0; i < map.optSize; i++) | |
169 { | |
170 switch (map.optFields[i].type) | |
171 { | |
172 case 'A': | |
173 fprintf(_out_fp, "\t%s:%c:%c", map.optFields[i].tag, map.optFields[i].type, map.optFields[i].cVal); | |
174 break; | |
175 case 'i': | |
176 fprintf(_out_fp, "\t%s:%c:%d", map.optFields[i].tag, map.optFields[i].type, map.optFields[i].iVal); | |
177 break; | |
178 case 'f': | |
179 fprintf(_out_fp, "\t%s:%c:%f", map.optFields[i].tag, map.optFields[i].type, map.optFields[i].fVal); | |
180 break; | |
181 case 'Z': | |
182 case 'H': | |
183 fprintf(_out_fp, "\t%s:%c:%s", map.optFields[i].tag, map.optFields[i].type, map.optFields[i].sVal); | |
184 break; | |
185 } | |
186 } | |
187 | |
188 fprintf(_out_fp, "\n"); | |
189 } | |
190 | |
191 int initOutput ( char *fileName, int compressed) | |
192 { | |
193 if (compressed) | |
194 { | |
195 char newFileName[strlen(fileName)+4]; | |
196 sprintf(newFileName, "%s.gz", fileName); | |
197 | |
198 _out_gzfp = fileOpenGZ(newFileName, "w1f"); | |
199 if (_out_gzfp == Z_NULL) | |
200 { | |
201 return 0; | |
202 } | |
203 | |
204 finalizeOutput = &finalizeGZOutput; | |
205 | |
206 output = &gzOutputQ; | |
207 } | |
208 else | |
209 { | |
210 _out_fp = fileOpen(fileName, "w"); | |
211 if (_out_fp == NULL) | |
212 { | |
213 return 0; | |
214 } | |
215 | |
216 finalizeOutput = &finalizeTXOutput; | |
217 output = &outputQ; | |
218 } | |
219 buffer[0] = '\0'; | |
220 return 1; | |
221 } | |
222 | |
223 FILE* getOutputFILE() | |
224 { | |
225 if(_out_fp != NULL) | |
226 return _out_fp; | |
227 else if(_out_gzfp != NULL) | |
228 return _out_gzfp; | |
229 else | |
230 return NULL; | |
231 } |