File: cdna.c

package info (click to toggle)
wise 2.4.1-21
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 27,140 kB
  • sloc: ansic: 276,365; makefile: 1,003; perl: 886; lex: 93; yacc: 81; sh: 24
file content (361 lines) | stat: -rw-r--r-- 8,204 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#ifdef _cplusplus
extern "C" {
#endif
#include "cdna.h"



/* Function:  truncate_cDNA(cdna,start,stop)
 *
 * Descrip:    Truncates a cDNA sequence. Basically uses
 *             the /magic_trunc_Sequence function (of course!)
 *
 *             It does not alter cdna, rather it returns a new
 *             sequence with that truncation
 *
 *
 * Arg:         cdna [READ ] cDNA that is truncated [cDNA *]
 * Arg:        start [UNKN ] Undocumented argument [int]
 * Arg:         stop [UNKN ] Undocumented argument [int]
 *
 * Return [UNKN ]  Undocumented return value [cDNA *]
 *
 */
# line 45 "cdna.dy"
cDNA * truncate_cDNA(cDNA * cdna,int start,int stop)
{
  return cDNA_from_Sequence(magic_trunc_Sequence(cdna->baseseq,start,stop));
}

/* Function:  read_fasta_file_cDNA(filename)
 *
 * Descrip:    Reads a fasta file assumming that it is cDNA. 
 *             Will complain if it is not, and return NULL.
 *
 *
 * Arg:        filename [UNKN ] filename to be opened and read [char *]
 *
 * Return [UNKN ]  Undocumented return value [cDNA *]
 *
 */
# line 56 "cdna.dy"
cDNA * read_fasta_file_cDNA(char * filename)
{
  Sequence * seq;

  seq = read_fasta_file_Sequence(filename);
  if( seq == NULL ) {
    return NULL;
  }

  return cDNA_from_Sequence(seq);
}


/* Function:  read_fasta_cDNA(ifp)
 *
 * Descrip:    Reads a fasta file assumming that it is cDNA. 
 *             Will complain if it is not, and return NULL.
 *
 *
 * Arg:        ifp [UNKN ] file point to be read from [FILE *]
 *
 * Return [UNKN ]  Undocumented return value [cDNA *]
 *
 */
# line 75 "cdna.dy"
cDNA * read_fasta_cDNA(FILE * ifp)
{
  Sequence * seq;

  seq = read_fasta_Sequence(ifp);
  if( seq == NULL ) {
    return NULL;
  }

  return cDNA_from_Sequence(seq);
}

/* Function:  read_efetch_cDNA(estr)
 *
 * Descrip:    Reads a efetch specified query
 *             Uses, of course /read_efetch_Sequence
 *
 *
 * Arg:        estr [READ ] efetch string which is read [char *]
 *
 * Return [UNKN ]  Undocumented return value [cDNA *]
 *
 */
# line 93 "cdna.dy"
cDNA * read_efetch_cDNA(char * estr)
{
  return cDNA_from_Sequence(read_efetch_Sequence(estr));
}

/* Function:  read_SRS_cDNA(srsquery)
 *
 * Descrip:    Reads a SRS sequence using srs4 syntax.
 *             Uses, of course, /read_SRS_Sequence
 *
 *
 *
 * Arg:        srsquery [READ ] string query representing SRS name [char *]
 *
 * Return [UNKN ]  Undocumented return value [cDNA *]
 *
 */
# line 105 "cdna.dy"
cDNA * read_SRS_cDNA(char * srsquery)
{
  return cDNA_from_Sequence(read_SRS_Sequence(srsquery));
}


/* Function:  cDNA_name(cdna)
 *
 * Descrip:    Returns the name of the cDNA
 *
 *
 * Arg:        cdna [UNKN ] Undocumented argument [cDNA *]
 *
 * Return [UNKN ]  Undocumented return value [char *]
 *
 */
# line 115 "cdna.dy"
char * cDNA_name(cDNA * cdna)
{
  return cdna->baseseq->name;
}

/* Function:  cDNA_length(cdna)
 *
 * Descrip:    Returns the length of the cDNA
 *
 *
 * Arg:        cdna [UNKN ] Undocumented argument [cDNA *]
 *
 * Return [UNKN ]  Undocumented return value [int]
 *
 */
# line 124 "cdna.dy"
int cDNA_length(cDNA * cdna)
{
  return cdna->baseseq->len;
}

/* Function:  cDNA_seqchar(cdna,pos)
 *
 * Descrip:    Returns sequence character at this position.
 *
 *
 * Arg:        cdna [UNKN ] cDNA [cDNA *]
 * Arg:         pos [UNKN ] position in cDNA to get char [int]
 *
 * Return [UNKN ]  Undocumented return value [char]
 *
 */
# line 135 "cdna.dy"
char cDNA_seqchar(cDNA * cdna,int pos)
{
  return cdna->baseseq->seq[pos];
}


/* Function:  cDNA_from_Sequence(seq)
 *
 * Descrip:    makes a new cDNA from a Sequence. It 
 *             owns the Sequence memory, ie will attempt a /free_Sequence
 *             on the structure when /free_cDNA is called
 *
 *             If you want to give this cDNA this Sequence and
 *             forget about it, then just hand it this sequence and set
 *             seq to NULL (no need to free it). If you intend to use 
 *             the sequence object elsewhere outside of the cDNA datastructure
 *             then use cDNA_from_Sequence(/hard_link_Sequence(seq))
 *
 *
 *
 * Arg:        seq [OWNER] Sequence to make cDNA from [Sequence *]
 *
 * Return [UNKN ]  Undocumented return value [cDNA *]
 *
 */
# line 155 "cdna.dy"
cDNA * cDNA_from_Sequence(Sequence * seq)
{
  cDNA * out;
  int conv;

  if( seq == NULL ) {
    warn("Trying to make a cdna sequence from a NULL baseseq.");
    return NULL;
  }

  if( is_dna_Sequence(seq) == FALSE ) {
    warn("Trying to make a cDNA sequence from a non cDNA base sequence [%s].",seq->name);
    return NULL;
  }

  uppercase_Sequence(seq);

  force_to_dna_Sequence(seq,1.0,&conv);
 
  if( conv != 0 ) {
    log_full_error(INFO,0,"In making %s a cdna sequence, converted %d bases (%2.1f%%) to N's from non ATGCN",seq->name,conv,(double)conv*100/(double)seq->len);
  }

  out = cDNA_alloc();

  out->baseseq = seq;

  return out;
}




# line 199 "cdna.c"
/* Function:  hard_link_cDNA(obj)
 *
 * Descrip:    Bumps up the reference count of the object
 *             Meaning that multiple pointers can 'own' it
 *
 *
 * Arg:        obj [UNKN ] Object to be hard linked [cDNA *]
 *
 * Return [UNKN ]  Undocumented return value [cDNA *]
 *
 */
cDNA * hard_link_cDNA(cDNA * obj) 
{
    if( obj == NULL )    {  
      warn("Trying to hard link to a cDNA object: passed a NULL object");    
      return NULL;   
      }  
    obj->dynamite_hard_link++;   
    return obj;  
}    


/* Function:  cDNA_alloc(void)
 *
 * Descrip:    Allocates structure: assigns defaults if given 
 *
 *
 *
 * Return [UNKN ]  Undocumented return value [cDNA *]
 *
 */
cDNA * cDNA_alloc(void) 
{
    cDNA * out; /* out is exported at end of function */ 


    /* call ckalloc and see if NULL */ 
    if((out=(cDNA *) ckalloc (sizeof(cDNA))) == NULL)    {  
      warn("cDNA_alloc failed ");    
      return NULL;  /* calling function should respond! */ 
      }  
    out->dynamite_hard_link = 1; 
#ifdef PTHREAD   
    pthread_mutex_init(&(out->dynamite_mutex),NULL);     
#endif   
    out->baseseq = NULL; 


    return out;  
}    


/* Function:  free_cDNA(obj)
 *
 * Descrip:    Free Function: removes the memory held by obj
 *             Will chain up to owned members and clear all lists
 *
 *
 * Arg:        obj [UNKN ] Object that is free'd [cDNA *]
 *
 * Return [UNKN ]  Undocumented return value [cDNA *]
 *
 */
cDNA * free_cDNA(cDNA * obj) 
{
    int return_early = 0;    


    if( obj == NULL) {  
      warn("Attempting to free a NULL pointer to a cDNA obj. Should be trappable");  
      return NULL;   
      }  


#ifdef PTHREAD   
    assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0); 
#endif   
    if( obj->dynamite_hard_link > 1)     {  
      return_early = 1;  
      obj->dynamite_hard_link--; 
      }  
#ifdef PTHREAD   
    assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);   
#endif   
    if( return_early == 1)   
      return NULL;   
    if( obj->baseseq != NULL)    
      free_Sequence(obj->baseseq);   


    ckfree(obj); 
    return NULL; 
}    


/* Function:  replace_baseseq_cDNA(obj,baseseq)
 *
 * Descrip:    Replace member variable baseseq
 *             For use principly by API functions
 *
 *
 * Arg:            obj [UNKN ] Object holding the variable [cDNA *]
 * Arg:        baseseq [OWNER] New value of the variable [Sequence *]
 *
 * Return [SOFT ]  member variable baseseq [boolean]
 *
 */
boolean replace_baseseq_cDNA(cDNA * obj,Sequence * baseseq) 
{
    if( obj == NULL)     {  
      warn("In replacement function baseseq for object cDNA, got a NULL object");    
      return FALSE;  
      }  
    obj->baseseq = baseseq;  
    return TRUE; 
}    


/* Function:  access_baseseq_cDNA(obj)
 *
 * Descrip:    Access member variable baseseq
 *             For use principly by API functions
 *
 *
 * Arg:        obj [UNKN ] Object holding the variable [cDNA *]
 *
 * Return [SOFT ]  member variable baseseq [Sequence *]
 *
 */
Sequence * access_baseseq_cDNA(cDNA * obj) 
{
    if( obj == NULL)     {  
      warn("In accessor function baseseq for object cDNA, got a NULL object");   
      return NULL;   
      }  
    return obj->baseseq;     
}    



#ifdef _cplusplus
}
#endif