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