annotate mrfast-2.1.0.5/RefGenome.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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
1 /*
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
2 * Copyright (c) <2008 - 2012>, University of Washington, Simon Fraser University
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
3 * All rights reserved.
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
4 *
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
5 * Redistribution and use in source and binary forms, with or without modification,
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
6 * are permitted provided that the following conditions are met:
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
7 *
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
8 * Redistributions of source code must retain the above copyright notice, this list
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
9 * of conditions and the following disclaimer.
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
10 * - Redistributions in binary form must reproduce the above copyright notice, this
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
11 * list of conditions and the following disclaimer in the documentation and/or other
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
12 * materials provided with the distribution.
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
13 * - Neither the names of the University of Washington, Simon Fraser University,
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
14 * nor the names of its contributors may be
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
15 * used to endorse or promote products derived from this software without specific
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
16 * prior written permission.
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
17 *
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
26 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
29 */
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
30
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
31 /*
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
32 Authors:
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
33 Farhad Hormozdiari
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
34 Faraz Hach
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
35 Can Alkan
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
36 Emails:
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
37 farhadh AT uw DOT edu
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
38 fhach AT cs DOT sfu DOT ca
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
39 calkan AT uw DOT edu
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
40 */
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
41
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
42
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
43 #include <stdio.h>
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
44 #include <stdlib.h>
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
45 #include <string.h>
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
46 #include <ctype.h>
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
47 #include "Common.h"
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
48 #include "RefGenome.h"
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
49
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
50 FILE *_rg_fp;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
51 char *_rg_gen;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
52 char *_rg_name;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
53 int _rg_offset;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
54 int _rg_contGen;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
55
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
56 /**********************************************/
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
57 int initLoadingRefGenome(char *fileName)
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
58 {
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
59 char ch;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
60 _rg_fp = fileOpen (fileName, "r");
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
61 if (fscanf(_rg_fp, "%c", &ch))
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
62 {
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
63 if (ch == '>')
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
64 {
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
65 _rg_contGen = 0;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
66 _rg_offset = 0;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
67 _rg_gen = getMem(CONTIG_MAX_SIZE);
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
68 _rg_name = getMem(CONTIG_NAME_SIZE);
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
69 return 1;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
70 }
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
71 }
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
72 return 0;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
73 }
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
74 /**********************************************/
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
75 void finalizeLoadingRefGenome()
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
76 {
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
77 freeMem(_rg_gen, CONTIG_MAX_SIZE);
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
78 freeMem(_rg_name, CONTIG_NAME_SIZE);
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
79 fclose(_rg_fp);
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
80 }
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
81 /**********************************************/
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
82 int loadRefGenome(char **refGen, char **refGenName, int *refGenOff)
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
83 {
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
84 char ch;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
85 int i;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
86 int returnVal = 0;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
87 int actualSize=0;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
88 int size;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
89 char *tmp;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
90
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
91 // New Conting
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
92 if (!_rg_contGen)
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
93 {
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
94 size = 0;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
95 tmp = fgets(_rg_name, SEQ_MAX_LENGTH, _rg_fp);
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
96 }
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
97 else
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
98 {
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
99 size=strlen(_rg_gen);
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
100 for( i = 0 ; i < CONTIG_OVERLAP ; i++ )
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
101 {
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
102
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
103 _rg_gen[i] = _rg_gen[size-CONTIG_OVERLAP+i];
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
104 if (_rg_gen[i] != 'N')
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
105 actualSize++;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
106 }
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
107 size = CONTIG_OVERLAP;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
108 }
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
109 while( fscanf(_rg_fp, "%c", &ch) > 0 )
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
110 {
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
111 if (ch == '>')
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
112 {
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
113 _rg_contGen = 0;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
114 returnVal = 1;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
115 break;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
116 }
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
117 else if (!isspace(ch))
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
118 {
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
119 ch = toupper(ch);
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
120 _rg_gen[size++] = ch;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
121 if (ch != 'N')
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
122 {
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
123 actualSize++;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
124 }
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
125 if (actualSize == CONTIG_SIZE || size == CONTIG_MAX_SIZE)
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
126 {
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
127 _rg_contGen = 1;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
128 returnVal=1;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
129 break;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
130 }
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
131 }
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
132
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
133 }
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
134
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
135 _rg_gen[size] = '\0';
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
136 for (i=strlen(_rg_name)-1; i >= 0; i--)
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
137 if (!isspace(_rg_name[i]))
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
138 break;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
139 _rg_name[i+1] = '\0';
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
140
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
141 *refGenOff = _rg_offset;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
142 *refGenName = _rg_name;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
143 *refGen = _rg_gen;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
144
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
145 if (_rg_contGen == 1)
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
146 {
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
147 _rg_offset += size-CONTIG_OVERLAP;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
148 }
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
149 else
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
150 {
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
151 _rg_offset = 0;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
152 }
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
153
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
154
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
155 return returnVal;
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
156 }
d4054b05b015 Version update to 2.1.0.5
calkan
parents:
diff changeset
157 /**********************************************/