The outage for Sunday 24th November has been cancelled.
Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
WritePIR.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file WritePIR.c
5 
6  \version V1.0
7  \date 11.06.16
8  \brief Writes a PIR sequence file
9 
10  \copyright (c) UCL / Dr. Andrew C. R. Martin 2015
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 11.06.15
50 
51 *************************************************************************/
52 /* Doxygen
53  -------
54  #GROUP Handling Sequence Data
55  #SUBGROUP File IO
56  PIR and FASTA writer
57 */
58 /************************************************************************/
59 /* Includes
60 */
61 #include <string.h>
62 #include <stdio.h>
63 #include <stdlib.h>
64 #include <ctype.h>
65 
66 #include "SysDefs.h"
67 #include "macros.h"
68 #include "seq.h"
69 
70 /************************************************************************/
71 /* Defines and macros
72 */
73 
74 /************************************************************************/
75 /* Globals
76 */
77 
78 /************************************************************************/
79 /* Prototypes
80 */
81 
82 /************************************************************************/
83 /*>void blWriteOneStringPIR(FILE *out, char *label, char *title,
84  char *sequence, char **chainLabels,
85  BOOL ByChain, BOOL doFasta)
86  --------------------------------------------------------------------
87 *//**
88 
89  \param[in] *out File pointer
90  \param[in] *label Sequence label
91  \param[in] *title Sequence title
92  \param[in] *sequence Sequence (1-letter code) with chains separated
93  by *
94  \param[in] **chainLabels Chain labels (may be set to NULL unless
95  ByChain is set)
96  \param[in] ByChain Print a separate header for each chain
97  \param[in] doFasta Output FASTA format instead of PIR
98 
99  Writes a PIR sequence file from a 1-letter code sequence. Multiple
100  chains are split with '*'. If ByChain is set the the chainLabels array
101  must be non-NULL and contains labels for each chain
102  Adds a terminating * if required.
103 
104 - 10.05.94 Original By: ACRM
105 - 22.08.97 Can now handle chains separately
106 - 26.08.97 If chains are handled separately, don't bother writing out
107  an empty chain
108 - 10.08.98 Basically a total rewrite to fix a bug which caused the
109  header not to be printed with -c -p for a chain after one
110  which was non-protein. Much simplified the code by printing
111  the header at the beginning of a chain rather than end
112  of previous chain.
113 - 18.10.00 Added code to write FASTA as well
114 - 11.06.15 Reset count=0 after a * - tidies up the output!
115 */
116 void blWriteOneStringPIR(FILE *out, char *label, char *title,
117  char *sequence, char **chainLabels,
118  BOOL ByChain, BOOL doFasta)
119 {
120  int i,
121  count,
122  chaincount = 0;
123  BOOL GotStar = FALSE,
124  DoneHeader = FALSE,
125  Printed;
126  char chn[blMAXCHAINLABEL],
127  outlabel[blMAXPIRLABEL];
128 
129  strcpy(outlabel,label);
130 
131  /* If we are not going by chain create a label */
132  if(!ByChain)
133  {
134  strcpy(outlabel, "PDBPIR");
135  if(label[0])
136  strcpy(outlabel, label);
137  }
138 
139  /* If we are not doing it by-chain, then simple display the label
140  and header now otherwise set flag to say we haven't done header
141  */
142  if(ByChain)
143  {
144  DoneHeader = FALSE;
145  }
146  else
147  {
148  if(doFasta)
149  {
150  fprintf(out,">%s\n",outlabel);
151  }
152  else
153  {
154  fprintf(out,">P1;%s\n",outlabel);
155  fprintf(out,"Sequence extracted from PDB file - %s\n",
156  (title[0]?title:"By pdb2pir"));
157  }
158  DoneHeader = TRUE;
159  }
160 
161  /* Start by setting flag to say nothing has been printed */
162  Printed = FALSE;
163 
164  /* Loop through the sequence with i. Use count to count number of
165  residues printed on a line
166 
167  11.06.15 Fixed initialization of count to zero rather than 1
168  */
169  for(i=0,count=0; sequence[i]; i++)
170  {
171  if(ByChain)
172  {
173  /* If we don't have a header, then print one */
174  if((sequence[i] != '*') && (!DoneHeader))
175  {
176  if(label[0])
177  {
178  strcpy(outlabel,label);
179  strcpy(chn, chainLabels[chaincount]);
180  strcat(outlabel,chn);
181  }
182  else
183  {
184  sprintf(outlabel,"Chain%s",chainLabels[chaincount]);
185  }
186  if(doFasta)
187  {
188  fprintf(out,">%s\n",outlabel);
189  }
190  else
191  {
192  fprintf(out,">P1;%s\n",outlabel);
193  fprintf(out,"Sequence extracted from PDB file - %s\n",
194  (title[0]?title:"By pdb2pir"));
195  }
196 
197  DoneHeader = TRUE;
198  count = 0;
199  }
200  }
201 
202  if(count==30)
203  {
204  fputc('\n',out);
205  count = 0;
206  }
207 
208  if(sequence[i] == '*')
209  {
210  chaincount++;
211  if(Printed)
212  {
213  if(doFasta)
214  {
215  fprintf(out,"\n");
216  }
217  else
218  {
219  fprintf(out,"*\n");
220  }
221 
222  GotStar = TRUE;
223  }
224 
225  DoneHeader = FALSE;
226  Printed = FALSE;
227  count = 0; /* 11.06.15 */
228  }
229  else
230  {
231  fputc(sequence[i],out);
232  GotStar = FALSE;
233  Printed = TRUE;
234  }
235 
236  if(Printed)
237  count++;
238  }
239 
240  if(!GotStar)
241  {
242  if(doFasta)
243  {
244  fprintf(out,"\n");
245  }
246  else
247  {
248  fprintf(out,"*\n");
249  }
250  }
251 }
252 
253 
short BOOL
Definition: SysDefs.h:64
#define blMAXPIRLABEL
Definition: seq.h:85
#define FALSE
Definition: macros.h:223
void blWriteOneStringPIR(FILE *out, char *label, char *title, char *sequence, char **chainLabels, BOOL ByChain, BOOL doFasta)
Definition: WritePIR.c:116
Useful macros.
Header file for sequence handling.
#define TRUE
Definition: macros.h:219
#define blMAXCHAINLABEL
Definition: pdb.h:248
System-type variable type definitions.