The outage for Sunday 24th November has been cancelled.
Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
SplitSeq.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file SplitSeq.c
5 
6  \version V1.11
7  \date 07.07.14
8  \brief
9 
10  \copyright (c) UCL / Dr. Andrew C. R. Martin 1993-2000
11  \author Dr. Andrew C. R. Martin
12  \par
13  Institute of Structural & Molecular Biology,
14  University College London,
15  Gower Street,
16  London.
17  WC1E 6BT.
18  \par
19  andrew@bioinf.org.uk
20  andrew.martin@ucl.ac.uk
21 
22 **************************************************************************
23 
24  This code is NOT IN THE PUBLIC DOMAIN, but it may be copied
25  according to the conditions laid out in the accompanying file
26  COPYING.DOC.
27 
28  The code may be modified as required, but any modifications must be
29  documented so that the person responsible can be identified.
30 
31  The code may not be sold commercially or included as part of a
32  commercial product except as described in the file COPYING.DOC.
33 
34 **************************************************************************
35 
36  Description:
37  ============
38 
39 
40 **************************************************************************
41 
42  Usage:
43  ======
44 
45 **************************************************************************
46 
47  Revision History:
48  =================
49 - V1.0 29.09.92 Original
50 - V1.1 07.06.93 Corrected allocation
51 - V1.2 18.06.93 Handles multi-chains and skips NTER and CTER residues.
52  Added SplitSeq()
53 - V1.3 09.07.93 SplitSeq() cleans up properly if allocation failed
54 - V1.4 11.05.94 Added TrueSeqLen()
55 - V1.5 13.05.94 Fixed bug in PDB2Seq().
56  Added KnownSeqLen().
57 - V1.6 07.09.94 Fixed allocation bug in SplitSeq()
58 - V1.7 19.07.95 Added check for ATOM records
59 - V1.8 24.01.96 Fixed bug when no ATOM records in linked list
60  Returns a blank string
61 - V1.9 26.08.97 Renamed DoPDB2Seq() with handling of Asx/Glx and
62  protein-only. Added macros to recreate the
63  old PDB2Seq() interface and similar new calls
64 - V1.10 02.10.00 Added NoX option
65 - V1.11 07.07.14 Use bl prefix for functions By: CTP
66 
67 *************************************************************************/
68 /* Doxygen
69  -------
70  #GROUP Handling Sequence Data
71  #SUBGROUP blSplitSeq()
72  Splits a sequence stored as a linear array with each chain separated
73  by a * into an array of sequences. Returns the number of chains
74  found.
75 */
76 /************************************************************************/
77 /* Includes
78 */
79 #include <stdlib.h>
80 #include <string.h>
81 
82 /************************************************************************/
83 /* Defines and macros
84 */
85 
86 /************************************************************************/
87 /* Globals
88 */
89 
90 /************************************************************************/
91 /* Prototypes
92 */
93 
94 
95 /************************************************************************/
96 /*>int blSplitSeq(char *LinearSeq, char **seqs)
97  --------------------------------------------
98 *//**
99 
100  \param[in] *LinearSeq Array containing sequence with chains
101  terminated by *'s
102  \param[out] **seqs Allocated set of character arrays
103  containing one chain per array
104  \return Number of chains found
105 
106  Splits a sequence stored as a linear array with each chain separated
107  by a * into an array of sequences. Returns the number of chains
108  found.
109 
110 - 18.06.93 Original By: ACRM
111 - 09.07.93 Cleans up properly of allocation failed
112 - 07.09.94 Sequence space was being allocated one too small
113 - 07.07.14 Use bl prefix for functions By: CTP
114 */
115 int blSplitSeq(char *LinearSeq, char **seqs)
116 {
117  char *ptr,
118  *star;
119  int seqlen = strlen(LinearSeq),
120  NSeq = 0;
121 
122  ptr = LinearSeq;
123 
124  while(ptr-LinearSeq < seqlen)
125  {
126  star = strchr(ptr,'*');
127  if(star != NULL)
128  {
129  *star = '\0';
130  seqs[NSeq] = (char *)malloc((1+strlen(ptr)) * sizeof(char));
131  if(seqs[NSeq] == NULL)
132  {
133  int i;
134  for(i=0; i<=NSeq; i++) if(seqs[i] != NULL) free(seqs[i]);
135  return(0);
136  }
137  strcpy(seqs[NSeq],ptr);
138  NSeq++;
139  ptr = star+1;
140  }
141  else
142  {
143  if(ptr < LinearSeq+seqlen)
144  {
145  seqs[NSeq] = (char *)malloc((1+strlen(ptr)) * sizeof(char));
146  if(seqs[NSeq] == NULL)
147  {
148  int i;
149  for(i=0; i<=NSeq; i++) if(seqs[i] != NULL) free(seqs[i]);
150  return(0);
151  }
152  strcpy(seqs[NSeq],ptr);
153  NSeq++;
154  }
155  break;
156  }
157  }
158 
159  return(NSeq);
160 }
161 
#define NULL
Definition: array2.c:99
int blSplitSeq(char *LinearSeq, char **seqs)
Definition: SplitSeq.c:115