forked from yhlink/kssdtree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsequence.c
142 lines (119 loc) · 4.32 KB
/
sequence.c
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
/**********************************************************************
* File: sequence.c
* Author: Kevin Howe
* Copyright (C) Genome Research Limited, 2002-
*-------------------------------------------------------------------
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------
* NOTES:
* Functions and structures for the manipulation of protein
* sequences. Only minimal functionality is needed
**********************************************************************/
#include "njheaders/sequence.h"
/**********************************************************************
FUNCTION: clone_Sequence
DESCRIPTION:
Performs a deep copy of the given Sequence and returns it
ARGS:
A Sequenced pointer (sequence.h)
RETURNS:
A pointer to a Sequence structure
NOTES:
**********************************************************************/
struct Sequence *clone_Sequence( struct Sequence *source) {
unsigned int i;
struct Sequence *dest = NULL;
if (source != NULL) {
dest = empty_Sequence();
dest->name = (char *) malloc_util( (strlen(source->name)+1) * sizeof(char));
strcpy( dest->name, source->name );
dest->length = source->length;
if (source->length)
dest->seq = (char *) malloc_util( dest->length * sizeof( char ));
for( i=0; i < dest->length; i++) {
dest->seq[i] = source->seq[i];
}
if (source->sec_struct != NULL) {
dest->sec_struct = (char *) malloc_util( dest->length * sizeof( char ));
for (i=0; i < dest->length; i++) {
dest->sec_struct[i] = source->sec_struct[i];
}
}
if (source->surf_acc != NULL) {
dest->surf_acc = (char *) malloc_util( dest->length * sizeof( char ));
for (i=0; i < dest->length; i++) {
dest->surf_acc[i] = source->surf_acc[i];
}
}
if (source->post_prob != NULL) {
dest->post_prob = (char *) malloc_util( dest->length * sizeof( char ));
for (i=0; i < dest->length; i++) {
dest->post_prob[i] = source->post_prob[i];
}
}
if (source->lig_bind != NULL) {
dest->lig_bind = (char *) malloc_util( dest->length * sizeof( char ));
for (i=0; i < dest->length; i++) {
dest->lig_bind[i] = source->lig_bind[i];
}
}
}
return dest;
}
/**********************************************************************
FUNCTION: empty_Sequence
DESCRIPTION:
Creates and returns an new, empty Sequence object
ARGS:
RETURNS:
A pointer to a Sequence structure
NOTES:
**********************************************************************/
struct Sequence *empty_Sequence( void ) {
struct Sequence *theseq;
theseq = (struct Sequence *) malloc_util( sizeof(struct Sequence));
theseq->length = 0;
theseq->name = NULL;
theseq->seq = NULL;
theseq->sec_struct = NULL;
theseq->surf_acc = NULL;
theseq->post_prob = NULL;
theseq->lig_bind = NULL;
return theseq;
}
/**********************************************************************
FUNCTION: free_Sequence
DESCRIPTION:
frees the memory occupied by the given Sequence reference
ARGS:
A pointer to a struct Sequence
RETURNS:
The NULL pointer
NOTES:
**********************************************************************/
void *free_Sequence( struct Sequence *theseq ) {
if (theseq != NULL) {
if (theseq->name != NULL)
theseq->name = free_util( theseq->name);
if (theseq->seq != NULL)
theseq->seq = free_util( theseq->seq);
if (theseq->sec_struct != NULL)
theseq->sec_struct = free_util( theseq->sec_struct);
if (theseq->surf_acc != NULL)
theseq->surf_acc = free_util( theseq->surf_acc);
if (theseq->post_prob != NULL)
theseq->post_prob = free_util( theseq->post_prob);
if (theseq->lig_bind != NULL)
theseq->lig_bind = free_util( theseq->lig_bind);
theseq = free_util( theseq );
}
return theseq;
}