0
|
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 <string.h>
|
|
40 #include <ctype.h>
|
|
41 #include "Common.h"
|
|
42 #include "RefGenome.h"
|
|
43
|
|
44 FILE *_rg_fp;
|
|
45 char *_rg_gen;
|
|
46 char *_rg_name;
|
|
47 int _rg_offset;
|
|
48 int _rg_contGen;
|
|
49
|
|
50 /**********************************************/
|
|
51 int initLoadingRefGenome(char *fileName)
|
|
52 {
|
|
53 char ch;
|
|
54 _rg_fp = fileOpen (fileName, "r");
|
|
55 if (fscanf(_rg_fp, "%c", &ch))
|
|
56 {
|
|
57 if (ch == '>')
|
|
58 {
|
|
59 _rg_contGen = 0;
|
|
60 _rg_offset = 0;
|
|
61 _rg_gen = getMem(CONTIG_MAX_SIZE);
|
|
62 _rg_name = getMem(CONTIG_NAME_SIZE);
|
|
63 return 1;
|
|
64 }
|
|
65 }
|
|
66 return 0;
|
|
67 }
|
|
68 /**********************************************/
|
|
69 void finalizeLoadingRefGenome()
|
|
70 {
|
|
71 freeMem(_rg_gen, CONTIG_MAX_SIZE);
|
|
72 freeMem(_rg_name, CONTIG_NAME_SIZE);
|
|
73 fclose(_rg_fp);
|
|
74 }
|
|
75 /**********************************************/
|
|
76 int loadRefGenome(char **refGen, char **refGenName, int *refGenOff)
|
|
77 {
|
|
78 char ch;
|
|
79 int i;
|
|
80 int returnVal = 0;
|
|
81 int actualSize=0;
|
|
82 int size;
|
|
83 char *tmp;
|
|
84
|
|
85 // New Conting
|
|
86 if (!_rg_contGen)
|
|
87 {
|
|
88 size = 0;
|
|
89 tmp = fgets(_rg_name, SEQ_MAX_LENGTH, _rg_fp);
|
|
90 int k;
|
|
91 for (k=0; k<strlen(_rg_name);k++)
|
|
92 {
|
|
93 if (_rg_name[k] == ' ')
|
|
94 {
|
|
95 _rg_name[k]='\0';
|
|
96 break;
|
|
97 }
|
|
98 }
|
|
99
|
|
100 }
|
|
101 else
|
|
102 {
|
|
103 size=strlen(_rg_gen);
|
|
104 for( i = 0 ; i < CONTIG_OVERLAP ; i++ )
|
|
105 {
|
|
106
|
|
107 _rg_gen[i] = _rg_gen[size-CONTIG_OVERLAP+i];
|
|
108 if (_rg_gen[i] != 'N')
|
|
109 actualSize++;
|
|
110 }
|
|
111 size = CONTIG_OVERLAP;
|
|
112 }
|
|
113 while( fscanf(_rg_fp, "%c", &ch) > 0 )
|
|
114 {
|
|
115 if (ch == '>')
|
|
116 {
|
|
117 _rg_contGen = 0;
|
|
118 returnVal = 1;
|
|
119 break;
|
|
120 }
|
|
121 else if (!isspace(ch))
|
|
122 {
|
|
123 ch = toupper(ch);
|
|
124 _rg_gen[size++] = ch;
|
|
125 if (ch != 'N')
|
|
126 {
|
|
127 actualSize++;
|
|
128 }
|
|
129 if (actualSize == CONTIG_SIZE || size == CONTIG_MAX_SIZE)
|
|
130 {
|
|
131 _rg_contGen = 1;
|
|
132 returnVal=1;
|
|
133 break;
|
|
134 }
|
|
135 }
|
|
136
|
|
137 }
|
|
138
|
|
139 _rg_gen[size] = '\0';
|
|
140 for (i=strlen(_rg_name)-1; i >= 0; i--)
|
|
141 if (!isspace(_rg_name[i]))
|
|
142 break;
|
|
143 _rg_name[i+1] = '\0';
|
|
144
|
|
145 *refGenOff = _rg_offset;
|
|
146 *refGenName = _rg_name;
|
|
147 *refGen = _rg_gen;
|
|
148
|
|
149 if (_rg_contGen == 1)
|
|
150 {
|
|
151 _rg_offset += size-CONTIG_OVERLAP;
|
|
152 }
|
|
153 else
|
|
154 {
|
|
155 _rg_offset = 0;
|
|
156 }
|
|
157
|
|
158
|
|
159 return returnVal;
|
|
160 }
|
|
161 /**********************************************/
|