NCBI C Toolkit Cross Reference

C/biostruc/mkbioseqB.c


  1 /* mkbioseqB.c
  2  *
  3  * ===========================================================================
  4  *
  5  *                            PUBLIC DOMAIN NOTICE
  6  *            National Center for Biotechnology Information (NCBI)
  7  *
  8  *  This software/database is a "United States Government Work" under the
  9  *  terms of the United States Copyright Act.  It was written as part of
 10  *  the author's official duties as a United States Government employee and
 11  *  thus cannot be copyrighted.  This software/database is freely available
 12  *  to the public for use. The National Library of Medicine and the U.S.
 13  *  Government do not place any restriction on its use or reproduction.
 14  *  We would, however, appreciate having the NCBI and the author cited in
 15  *  any work or product based on this material
 16  *
 17  *  Although all reasonable efforts have been taken to ensure the accuracy
 18  *  and reliability of the software and data, the NLM and the U.S.
 19  *  Government do not and cannot warrant the performance or results that
 20  *  may be obtained by using this software or data. The NLM and the U.S.
 21  *  Government disclaim all warranties, express or implied, including
 22  *  warranties of performance, merchantability or fitness for any particular
 23  *  purpose.
 24  *
 25  * ===========================================================================
 26  *
 27  * File Name: mkbioseqB.c
 28  *
 29  * Author: Ken Addess
 30  *
 31  * $Log: mkbioseqB.c,v $
 32  * Revision 6.3  1999/05/07 14:03:21  zimmerma
 33  * Moved LIBCALL isBiopoly() and LIBCALL isHet() into mmdbapi1.c
 34  *
 35  * Revision 6.2  1998/12/01 15:13:36  addess
 36  * cleaned up code to remove memory leaks
 37  *
 38  * Revision 6.1  1998/07/17 18:54:37  madej
 39  * Created by Ken Addess.
 40  *
 41  */
 42 
 43 /************************************************************
 44 /*                                                          */
 45 /*      readBiostruc()                                      */
 46 /*                                                          */
 47 /*      Opens a file, reads data for a PDB entry from it,   */
 48 /*      and closes it.                                      */
 49 /*                                                          */
 50 /************************************************************/ 
 51 
 52 #include "mkbioseq.h"
 53 #include <mmdbapi.h>
 54 
 55 BiostrucPtr LIBCALL readBiostruc(CharPtr filename, Int2 mode, Int4 mdlLvl)
 56 {
 57    BiostrucPtr lbsp;   
 58  
 59    if (filename == NULL) {
 60      return NULL;
 61    }
 62 
 63    /* Read in a Biostruc object. */
 64 
 65    /* lbsp = BiostrucAsnRead(aipr, NULL); */
 66   
 67    lbsp = FetchBS(filename, mode, mdlLvl, 1000, POWER_VIEW);
 68 
 69    return lbsp;
 70 }
 71 
 72 Int4 LIBCALL getHetIdx(Int4 molecule_id, MoleculeGraphPtr currenthet)
 73 {
 74    Int4 i;
 75 
 76    for (i = 0; currenthet; i++, currenthet = currenthet->next)
 77    {
 78       if (currenthet->id == molecule_id)
 79       {
 80          return i;
 81       }
 82    }
 83 
 84    return -1;
 85 }
 86 
 87 /************************************************************/
 88 /*                                                          */
 89 /*      getStdOlcode()                                      */
 90 /*                                                          */
 91 /*      Returns a one-letter iupac code for a standard      */
 92 /*      residue.                                            */
 93 /*                                                          */
 94 /************************************************************/ 
 95 
 96 CharPtr LIBCALL 
 97 getStdOlcode(Int4 standard_graphs_id, Int4 residue_graph_id, BiostrucResidueGraphSetPtr std)
 98 {
 99    ResidueGraphPtr rg;
100 
101    rg = std->residue_graphs;
102 
103    while (rg)
104    {
105       if (rg->id == residue_graph_id)
106       {
107          return(rg->iupac_code->data.ptrvalue);
108       }
109 
110       rg = rg->next;
111    }
112 
113    return NULL; 
114 }
115 
116 /************************************************************/
117 /*                                                          */
118 /*      getNstdOlcode()                                     */
119 /*                                                          */
120 /*      Returns a one-letter iupac code for a non-standard  */
121 /*      residue.                                            */
122 /*                                                          */
123 /************************************************************/ 
124 
125 CharPtr LIBCALL getNstdOlcode(ResidueGraphPtr nrg)
126 {
127    return(nrg->iupac_code->data.ptrvalue);
128 }
129 
130 /************************************************************/
131 /*                                                          */
132 /*      getNstdResGraph()                                   */
133 /*                                                          */
134 /*      Given a graph id, returns a corresponding residue   */
135 /*      graph.                                              */
136 /*                                                          */
137 /************************************************************/ 
138 
139 ResidueGraphPtr LIBCALL getNstdResGraph(Int4 rgid, BiostrucGraphPtr bsgp)
140 {
141    ResidueGraphPtr rgp, new;
142 
143    rgp = bsgp->residue_graphs;
144 
145    while (rgp)
146    {
147       if (rgp->id == rgid)
148       {
149          new = ResidueGraphNew();
150          new->id = rgp->id;
151          new->descr = rgp->descr;
152          new->residue_type = rgp->residue_type;
153          new->iupac_code = rgp->iupac_code;
154          new->atoms = rgp->atoms;
155          new->bonds = rgp->bonds;
156          new->chiral_centers = rgp->chiral_centers;
157 
158          return new;
159       }
160 
161       rgp = rgp->next;
162    }
163 
164    return NULL;
165 }
166 
167 /************************************************************/
168 /*                                                          */
169 /*      rmvSpace()                                          */
170 /*                                                          */
171 /*      Removes white space from a give string.             */
172 /*                                                          */
173 /************************************************************/ 
174 
175 CharPtr LIBCALL rmvSpace(CharPtr str)
176 {
177    CharPtr newstr = NULL;
178    Int4 len, i, j;
179    Boolean allBlank = TRUE;
180 
181    len = strlen(str);
182    for (i=0; i<len; i++)
183    {
184       if (str[i] != ' ')
185       {
186          allBlank = FALSE;
187          break;
188       }
189    }
190 
191    if (!allBlank)
192    {
193       newstr = (CharPtr)MemNew((len+1) * sizeof(CharPtr));
194 
195       for (i=0, j=0; i<len; i++)
196       {
197          if (str[i] != ' ')
198             newstr[j++] = str[i]; 
199       }
200       newstr[j] = '\0';
201 
202       return newstr;
203    }
204    
205    MemFree(newstr);
206    return StringSave(" ");
207 }
208 
209 Boolean LIBCALL isNstd(ResidueGraphPtr rgp)
210 {
211    ValNodePtr vnp;
212    CharPtr rname;
213 
214    vnp = rgp->descr;
215 
216    while (vnp)
217    {
218       if (vnp->choice == BiomolDescr_name)
219       {
220          rname = vnp->data.ptrvalue;
221          break;
222       }
223 
224       vnp = vnp->next; 
225    }
226 
227    if (!StringICmp(rname, "ALA"))
228       return(FALSE);
229    else if (!StringICmp(rname, "ARG"))
230       return(FALSE);
231    else if (!StringICmp(rname, "ASN"))
232       return(FALSE);
233    else if (!StringICmp(rname, "ASP"))
234       return(FALSE);
235    else if (!StringICmp(rname, "CYS"))
236       return(FALSE);
237    else if (!StringICmp(rname, "GLN"))
238       return(FALSE);
239    else if (!StringICmp(rname, "GLU"))
240       return(FALSE);
241    else if (!StringICmp(rname, "GLY"))
242       return(FALSE);
243    else if (!StringICmp(rname, "HIS"))
244       return(FALSE);
245    else if (!StringICmp(rname, "ILE"))
246       return(FALSE);
247    else if (!StringICmp(rname, "LEU"))
248       return(FALSE);
249    else if (!StringICmp(rname, "LYS"))
250       return(FALSE);
251    else if (!StringICmp(rname, "MET"))
252       return(FALSE);
253    else if (!StringICmp(rname, "PHE"))
254       return(FALSE);
255    else if (!StringICmp(rname, "PRO"))
256       return(FALSE);
257    else if (!StringICmp(rname, "SER"))
258       return(FALSE);
259    else if (!StringICmp(rname, "THR"))
260       return(FALSE);
261    else if (!StringICmp(rname, "TRP"))
262       return(FALSE);
263    else if (!StringICmp(rname, "TYR"))
264       return(FALSE);
265    else if (!StringICmp(rname, "VAL"))
266       return(FALSE);
267    else if (!StringICmp(rname, "DNA  A"))
268       return(FALSE);
269    else if (!StringICmp(rname, "DNA  C"))
270       return(FALSE);
271    else if (!StringICmp(rname, "DNA  G"))
272       return(FALSE);
273    else if (!StringICmp(rname, "DNA  T"))
274       return(FALSE);
275    else if (!StringICmp(rname, "RNA  A"))
276       return(FALSE);
277    else if (!StringICmp(rname, "RNA  C"))
278       return(FALSE);
279    else if (!StringICmp(rname, "RNA  G"))
280       return(FALSE);
281    else if (!StringICmp(rname, "RNA  U"))
282       return(FALSE);
283    else
284       return(TRUE);
285 }
286 
287 Int4 LIBCALL findChnidx(Int4 mol_id, Int4 nbp, MoleculeGraphPtr bp)
288 {
289    Int4 i;
290    MoleculeGraphPtr currentbp;
291 
292    currentbp = bp;
293 
294    for (i=1; i<=nbp; i++)
295    {
296       if (currentbp->id == mol_id)
297       {
298          return i;
299       }
300 
301       currentbp = currentbp->next;
302    }
303 
304    return -1;
305 }
306 
307 /************************************************************/
308 /*                                                          */
309 /*      getResNam()                                         */
310 /*                                                          */
311 /*      Given a graph id, returns a name of corresponding   */
312 /*      residue.                                            */
313 /*                                                          */
314 /************************************************************/ 
315 
316 CharPtr LIBCALL getResNam(ResidueGraphPntrPtr rgpp, BiostrucResidueGraphSetPtr stdDictionary, ResidueGraphPtr rg)
317 {
318    BiostrucResidueGraphSetPntrPtr brgsp;
319    ValNodePtr vnp;
320    ResidueGraphPtr rgStd;
321 
322    switch(rgpp->choice)
323    {
324       case ResidueGraphPntr_local:
325          
326          while (rg)
327          {
328             if (rg->id == rgpp->data.intvalue)
329             {
330                vnp = rg->descr;
331 
332                while (vnp)
333                {
334                   if (vnp->choice == BiomolDescr_name)
335                   {
336                      return vnp->data.ptrvalue;
337                   }
338                }
339             }
340 
341             rg = rg->next;
342          }
343          break;
344       case ResidueGraphPntr_standard:
345          rgStd = stdDictionary->residue_graphs;
346          brgsp = (BiostrucResidueGraphSetPntrPtr)rgpp->data.ptrvalue;
347 
348          while (rgStd)
349          {
350             if (rgStd->id == brgsp->residue_graph_id)
351             {
352                vnp = rgStd->descr;
353 
354                while (vnp)
355                {
356                   if (vnp->choice == BiomolDescr_name)
357                   {
358                      return vnp->data.ptrvalue;
359                   }
360                }
361             }
362 
363             rgStd = rgStd->next;
364          }
365          break;
366    }
367 
368    return NULL;
369 }
370 
371 /************************************************************/
372 /*                                                          */
373 /*      getResComm()                                        */
374 /*                                                          */
375 /*      Given a residue graph pointer, returns its comment. */
376 /*                                                          */
377 /************************************************************/ 
378 
379 CharPtr LIBCALL getResComm(ResidueGraphPntrPtr rgpp, BiostrucResidueGraphSetPtr stdDictionary, ResidueGraphPtr rg)
380 {
381 
382    BiostrucResidueGraphSetPntrPtr brgsp;
383    ValNodePtr vnp;
384    ResidueGraphPtr rgStd;
385 
386    switch(rgpp->choice)
387    {
388       case ResidueGraphPntr_local:
389          while (rg)
390          {
391             if (rg->id == rgpp->data.intvalue)
392             {
393                vnp = rg->descr;
394 
395                while (vnp)
396                {
397                   if (vnp->choice == BiomolDescr_pdb_comment)
398                   {
399                      return vnp->data.ptrvalue;
400                   }
401 
402                   vnp = vnp->next;
403                }
404             }
405 
406             rg = rg->next;
407          }
408          break;
409       case ResidueGraphPntr_standard:
410          rgStd = stdDictionary->residue_graphs;
411          brgsp = (BiostrucResidueGraphSetPntrPtr)rgpp->data.ptrvalue;
412 
413          while (rgStd)
414          {
415             if (rgStd->id == brgsp->residue_graph_id)
416             {
417                vnp = rgStd->descr;
418 
419                while (vnp)
420                {
421                   if (vnp->choice == BiomolDescr_name)
422                   {
423                      /* Standard residue graph dictionary doesn't have
424                      pdb comments as for nonstandard cases - return a name. */
425 
426                      return vnp->data.ptrvalue;
427                   }
428 
429                   vnp = vnp->next;
430                }
431             }
432 
433             rgStd = rgStd->next;
434          }
435          break;
436    }
437 
438    return NULL;
439 }
440 
441 Int4 LIBCALL 
442 getAtomElementIdx(Int4 molecule_id, Int4 residue_id, Int4 atom_id, BiostrucGraphPtr bsgp, BiostrucResidueGraphSetPtr stdDictionary)
443 {
444    MoleculeGraphPtr mgp;
445    ResiduePtr rs;
446    ResidueGraphPtr rgp;
447    AtomPtr atmp;
448    BiostrucResidueGraphSetPntrPtr brgsp;
449 
450    mgp = bsgp->molecule_graphs;
451 
452    while (mgp)
453    {
454       if (mgp->id == molecule_id)
455          break;
456 
457       mgp = mgp->next;
458    }
459 
460    rs = mgp->residue_sequence;
461 
462    while (rs)
463    {
464       if (rs->id == residue_id)
465          break;
466 
467       rs = rs->next;
468    }
469 
470    if (rs->residue_graph->choice == ResidueGraphPntr_local)
471    {
472       rgp = bsgp->residue_graphs;
473 
474       while (rgp)
475       {
476          if (rgp->id == rs->residue_graph->data.intvalue)
477          {
478             atmp = rgp->atoms;
479 
480             while (atmp != NULL)
481             {
482                if (atmp->id == atom_id)
483                {
484                   return atmp->element;
485                }
486 
487                atmp = atmp->next;
488             }
489          }
490 
491          rgp = rgp->next;
492       }
493    }
494    else if (rs->residue_graph->choice == ResidueGraphPntr_standard)
495    {
496       rgp = stdDictionary->residue_graphs;
497       brgsp = (BiostrucResidueGraphSetPntrPtr)rs->residue_graph->data.ptrvalue;
498 
499       while (rgp)
500       {
501          if (rgp->id == brgsp->residue_graph_id)
502          {
503             atmp = rgp->atoms;
504 
505             while (atmp != NULL)
506             {
507                if (atmp->id == atom_id) 
508                {
509                   return atmp->element;
510                }
511 
512                atmp = atmp->next;
513             }
514 
515          }
516 
517          rgp = rgp->next;
518       }
519    }
520 
521    return(255);
522 }
523 
524 /************************************************************/
525 /*                                                          */
526 /*      getResGraph()                                       */
527 /*                                                          */
528 /*      Given a graph id, returns corresponding residue     */
529 /*      graph.                                              */
530 /*                                                          */
531 /************************************************************/ 
532 
533 ResidueGraphPtr LIBCALL getResGraph(ResidueGraphPntrPtr rgpp, BiostrucGraphPtr bsgp, BiostrucResidueGraphSetPtr stdDictionary)
534 {
535    ResidueGraphPtr rg;
536    BiostrucResidueGraphSetPntrPtr brgsp;
537 
538    switch(rgpp->choice)
539    {
540       case ResidueGraphPntr_local:
541          rg = bsgp->residue_graphs;
542 
543          while (rg)
544          {
545             if (rg->id == rgpp->data.intvalue)
546             {
547                return rg;
548             }
549 
550             rg = rg->next;
551          }
552          break;
553       case ResidueGraphPntr_standard:
554          rg = stdDictionary->residue_graphs;
555          brgsp = (BiostrucResidueGraphSetPntrPtr)rgpp->data.ptrvalue;
556 
557          while (rg)
558          {
559             if (rg->id == brgsp->residue_graph_id)
560             {
561                return rg;
562             }
563 
564             rg = rg->next;
565          }
566          break;
567    }
568 
569    return NULL;
570 }
571 

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.