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