Mercurial > repos > calkan > mrsfast
comparison mrsfast-2.3.0.2/Output.c @ 0:ec628ba33878 default tip
Uploaded source code for mrsFAST
author | calkan |
---|---|
date | Tue, 21 Feb 2012 10:39:28 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ec628ba33878 |
---|---|
1 /* | |
2 * Copyright (c) <2008 - 2009>, 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 name of the <ORGANIZATION> nor the names of its contributors may be | |
14 * used to endorse or promote products derived from this software without specific | |
15 * prior written permission. | |
16 * | |
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 */ | |
29 | |
30 /* | |
31 * Author : Faraz Hach | |
32 * Email : fhach AT cs DOT sfu | |
33 * Last Update : 2009-12-08 | |
34 */ | |
35 | |
36 | |
37 #include <stdio.h> | |
38 #include <stdlib.h> | |
39 #include <zlib.h> | |
40 #include <string.h> | |
41 #include "Common.h" | |
42 #include "Output.h" | |
43 | |
44 FILE *_out_fp; | |
45 gzFile _out_gzfp; | |
46 | |
47 | |
48 | |
49 void finalizeGZOutput() | |
50 { | |
51 gzclose(_out_gzfp); | |
52 } | |
53 | |
54 void finalizeTXOutput() | |
55 { | |
56 fclose(_out_fp); | |
57 } | |
58 | |
59 | |
60 void gzOutputQ(SAM map) | |
61 { | |
62 gzprintf(_out_gzfp, "%s\t%d\t%s\t%d\t%d\t%s\t%s\t%d\t%d\t%s\t%s", | |
63 map.QNAME, | |
64 map.FLAG, | |
65 map.RNAME, | |
66 map.POS, | |
67 map.MAPQ, | |
68 map.CIGAR, | |
69 map.MRNAME, | |
70 map.MPOS, | |
71 map.ISIZE, | |
72 map.SEQ, | |
73 map.QUAL); | |
74 | |
75 int i; | |
76 | |
77 for ( i = 0; i < map.optSize; i++) | |
78 { | |
79 switch (map.optFields[i].type) | |
80 { | |
81 case 'A': | |
82 gzprintf(_out_gzfp, "\t%s:%c:%c", map.optFields[i].tag, map.optFields[i].type, map.optFields[i].cVal); | |
83 break; | |
84 case 'i': | |
85 gzprintf(_out_gzfp, "\t%s:%c:%d", map.optFields[i].tag, map.optFields[i].type, map.optFields[i].iVal); | |
86 break; | |
87 case 'f': | |
88 gzprintf(_out_gzfp, "\t%s:%c:%f", map.optFields[i].tag, map.optFields[i].type, map.optFields[i].fVal); | |
89 break; | |
90 case 'Z': | |
91 case 'H': | |
92 gzprintf(_out_gzfp, "\t%s:%c:%s", map.optFields[i].tag, map.optFields[i].type, map.optFields[i].sVal); | |
93 break; | |
94 } | |
95 } | |
96 gzprintf(_out_gzfp, "\n"); | |
97 } | |
98 | |
99 void outputQ(SAM map) | |
100 { | |
101 | |
102 fprintf(_out_fp, "%s\t%d\t%s\t%d\t%d\t%s\t%s\t%d\t%d\t%s\t%s", | |
103 map.QNAME, | |
104 map.FLAG, | |
105 map.RNAME, | |
106 map.POS, | |
107 map.MAPQ, | |
108 map.CIGAR, | |
109 map.MRNAME, | |
110 map.MPOS, | |
111 map.ISIZE, | |
112 map.SEQ, | |
113 map.QUAL); | |
114 | |
115 | |
116 int i; | |
117 | |
118 for ( i = 0; i < map.optSize; i++) | |
119 { | |
120 switch (map.optFields[i].type) | |
121 { | |
122 case 'A': | |
123 fprintf(_out_fp, "\t%s:%c:%c", map.optFields[i].tag, map.optFields[i].type, map.optFields[i].cVal); | |
124 break; | |
125 case 'i': | |
126 fprintf(_out_fp, "\t%s:%c:%d", map.optFields[i].tag, map.optFields[i].type, map.optFields[i].iVal); | |
127 break; | |
128 case 'f': | |
129 fprintf(_out_fp, "\t%s:%c:%f", map.optFields[i].tag, map.optFields[i].type, map.optFields[i].fVal); | |
130 break; | |
131 case 'Z': | |
132 case 'H': | |
133 fprintf(_out_fp, "\t%s:%c:%s", map.optFields[i].tag, map.optFields[i].type, map.optFields[i].sVal); | |
134 break; | |
135 } | |
136 } | |
137 | |
138 fprintf(_out_fp, "\n"); | |
139 } | |
140 | |
141 int initOutput ( char *fileName, int compressed) | |
142 { | |
143 if (compressed) | |
144 { | |
145 char newFileName[strlen(mappingOutputPath)+strlen(fileName)+4]; | |
146 sprintf(newFileName, "%s%s.gz", mappingOutputPath, fileName); | |
147 _out_gzfp = fileOpenGZ(newFileName, "w1f"); | |
148 if (_out_gzfp == Z_NULL) | |
149 { | |
150 return 0; | |
151 } | |
152 | |
153 finalizeOutput = &finalizeGZOutput; | |
154 | |
155 output = &gzOutputQ; | |
156 } | |
157 else | |
158 { | |
159 | |
160 char newFileName[strlen(mappingOutputPath)+strlen(fileName)]; | |
161 sprintf(newFileName, "%s%s", mappingOutputPath, fileName); | |
162 | |
163 _out_fp = fileOpen(newFileName, "w"); | |
164 if (_out_fp == NULL) | |
165 { | |
166 return 0; | |
167 } | |
168 | |
169 finalizeOutput = &finalizeTXOutput; | |
170 output = &outputQ; | |
171 } | |
172 return 1; | |
173 } | |
174 | |
175 |