NCBI C Toolkit Cross Reference

C/biostruc/mkbioseqA.c


  1 /* mkbioseqA.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: mkbioseqA.c
 28  *
 29  * Author: Ken Addess
 30  *
 31  * $Log: mkbioseqA.c,v $
 32  * Revision 6.2  1998/12/01 15:13:29  addess
 33  * cleaned up code to remove memory leaks
 34  *
 35  * Revision 6.1  1998/07/17 18:54:26  madej
 36  * Created by Ken Addess.
 37  *
 38  */
 39 
 40 #include "mkbioseq.h"
 41 
 42 /*****************************************************************************
 43 *
 44 *   Begin an entry, adding mol and chain ids, descriptions
 45 *       This makes a Seq-entry of type PDB-entry. 
 46 *
 47 *****************************************************************************/
 48 
 49 
 50 SeqEntryPtr LIBCALL CreateSeqEntry
 51 (BiostrucSourcePtr bssp, BiostrucGraphPtr bsgp, BiostrucModelPtr bsmp, ValNodePtr descr, Int4 nchn)
 52 {
 53         SeqEntryPtr pdb_entry, sephead = NULL, prev, sep;
 54         BioseqPtr biosp;
 55         BioseqSetPtr biossp;
 56         Int4 i;
 57         Int2 month, day, year;
 58         PdbBlockPtr pbp;
 59         ValNodePtr vnp, tmp, pubcat, pubd, pubs;
 60         CharPtr com, compound = NULL, source = NULL;
 61         PubdescPtr pdp;
 62         CitSubPtr citsub;
 63         CitArtPtr citart;
 64         CitBookPtr citbook;
 65         CitGenPtr citgen;
 66 
 67         /*entry_name = StringSave(*pdbid);*/
 68        /* save entry name */
 69 
 70         /*** get the PdbBlock data ***************/
 71 
 72         pbp = PdbBlockNew();
 73         pbp->deposition = bssp->database_entry_date;
 74         
 75         if (vnp = ValNodeFindNext(bsgp->descr, NULL, BiomolDescr_pdb_class))
 76           pbp->pdbclass = StringSave(vnp->data.ptrvalue);
 77      
 78         if (vnp = ValNodeFindNext(bsgp->descr, NULL, BiomolDescr_name))
 79         {
 80           compound = StringSave(vnp->data.ptrvalue);
 81           tmp = ValNodeNew(NULL);
 82           pbp->compound = tmp;
 83           tmp->data.ptrvalue = (Pointer)StringSave(compound);
 84         }
 85 
 86         if (vnp = ValNodeFindNext(bsgp->descr, NULL, BiomolDescr_pdb_source))
 87         {
 88           source = StringSave(vnp->data.ptrvalue);
 89           tmp = ValNodeNew(NULL);
 90           pbp->source = tmp;
 91           tmp->data.ptrvalue = (Pointer)StringSave(source);
 92         }
 93         
 94         MemFree(compound);
 95         MemFree(source);
 96 
 97         if (vnp = ValNodeFindNext(bsmp->descr, NULL, ModelDescr_pdb_method))
 98           pbp->exp_method = StringSave(vnp->data.ptrvalue);
 99         
100         
101         /*** make a seq_set of bioseqs *****************/
102 
103         for (i = 0; i < nchn; i++)
104         {
105           sep = SeqEntryNew();
106           if (sephead == NULL) sephead = sep;
107           else prev->next = sep;
108           prev = sep;
109           sep->choice = 1;    /* Bioseq */
110           biosp = BioseqNew();
111           sep->data.ptrvalue = (Pointer) biosp;
112           biosp->repr = Seq_repr_raw;    /* always raw */
113         }
114 
115         /***** make pbp into a Seq-descr *******/
116 
117         vnp = ValNodeNew(NULL);
118         vnp->choice = Seq_descr_pdb;
119         vnp->data.ptrvalue = (Pointer) pbp;
120 
121         /***** is it a set or a single sequence *********/
122 
123         if (nchn == 1)    /* one sequence */
124         {
125           pdb_entry = sephead;
126           biosp->descr = vnp;   
127         }
128         else                   /* multiple sequences */
129         {
130           pdb_entry = SeqEntryNew();
131           pdb_entry->choice = 2;   /* Bioseq-set */
132           biossp = BioseqSetNew();
133           pdb_entry->data.ptrvalue = (Pointer) biossp;
134           biossp->descr = vnp;
135           biossp->seq_set = sephead;
136           biossp->_class = 12;   /* pdb-entry */
137         }
138 
139         if (tmp = ValNodeFindNext(bsmp->descr, NULL, ModelDescr_pdb_comment))
140         {
141           com = (CharPtr)MemNew(10 * sizeof(Char)); 
142           StringNCpy(com, tmp->data.ptrvalue, 9);
143           com[9] = '\0';
144           if (StringICmp("Alternate", com) && StringICmp("A complet", com)) 
145           {
146             vnp =  ValNodeNew(vnp);
147             vnp->choice = Seq_descr_comment;
148             vnp->data.ptrvalue = MemNew((size_t)(StringLen(tmp->data.ptrvalue) +19));
149             StringCpy(vnp->data.ptrvalue, "Revision History:~");
150             StringCat(vnp->data.ptrvalue, tmp->data.ptrvalue);
151           }
152           MemFree(com);
153         }
154         
155         while (descr)
156         {
157           if (descr->choice == BiostrucDescr_attribution)
158           {
159              pubs = descr->data.ptrvalue;
160 
161             if (nchn == 1)
162               pubd = ValNodeNew(((BioseqPtr)(pdb_entry->data.ptrvalue))->descr);
163             else 
164               pubd = ValNodeNew(((BioseqSetPtr)(pdb_entry->data.ptrvalue))->descr);
165           
166             pubd->choice = Seq_descr_pub;
167             pdp = PubdescNew();
168             pubd->data.ptrvalue = pdp;
169 
170             pdp->pub = ValNodeNew(NULL);
171   
172             switch(pubs->choice)
173             {
174               case PUB_Gen:
175                 citgen = pubs->data.ptrvalue;
176                 pdp->pub->choice = 1;
177                 pdp->pub->data.ptrvalue = citgen;
178 
179                 break;
180               case PUB_Sub:
181                 citsub = pubs->data.ptrvalue;
182                 pdp->pub->choice = 2;
183                 pdp->pub->data.ptrvalue = citsub;
184 
185                 break;
186               case PUB_Article:
187                 citart = pubs->data.ptrvalue;
188                 pdp->pub->choice = 5;
189                 pdp->pub->data.ptrvalue = citart;
190 
191                 break;
192               case PUB_Book:
193                 citbook = pubs->data.ptrvalue;
194                 pdp->pub->choice = 7;
195                 pdp->pub->data.ptrvalue = citbook;
196 
197                 break;
198               case PUB_Equiv:
199                 pdp->pub = ValNodeFree(pdp->pub);
200                 pubcat = pubs->data.ptrvalue;
201 
202                 while (pubcat)
203                 {
204                   vnp = ValNodeNew(pdp->pub);
205                   if (pdp->pub == NULL)
206                     pdp->pub = vnp;
207 
208                   vnp->choice = pubcat->choice;
209                   if (pubcat->choice==4)
210                     vnp->data.intvalue = pubcat->data.intvalue;
211                   else
212                     vnp->data.ptrvalue = pubcat->data.ptrvalue;
213 
214                   pubcat = pubcat->next;
215                 }  
216                 break;
217               } 
218             }
219             descr = descr->next;
220           }  
221       
222       return pdb_entry;
223 }
224 
225 
226 /*****************************************************************************
227 *
228 *   Make SeqIDPtr
229 *
230 *****************************************************************************/
231 SeqIdPtr LIBCALL MakePDBId(BiostrucSourcePtr bssp, MoleculeGraphPtr mgp, DbtagPtr dtp)
232 {
233   ValNodePtr vnp;
234   SeqIdPtr sip;
235   PDBSeqIdPtr psp;
236   CharPtr chnid;
237         
238   if (vnp = ValNodeFindNext(mgp->descr, NULL, BiomolDescr_name))
239     chnid = vnp->data.ptrvalue;
240         
241   sip = ValNodeNew(NULL);
242   sip->choice = SEQID_PDB;
243 
244   psp = PDBSeqIdNew();
245   sip->data.ptrvalue=psp;
246   psp->mol = StringSave(dtp->tag->str);
247   psp->chain = (Uint1) *chnid;
248   psp->rel = DateNew();
249   psp->rel = bssp->database_entry_date;
250   return sip;
251 }
252 
253 SeqIdPtr LIBCALL MakeLocalID(Int4 mid, MoleculeGraphPtr mgp, DbtagPtr dtp)
254 {
255   ValNodePtr vnp;
256   SeqIdPtr sip;
257   ObjectIdPtr oip;
258   CharPtr chnid;
259   Char string_name[9];
260   CharPtr dom_name = {"0"};
261   
262   
263   if (vnp = ValNodeFindNext(mgp->descr, NULL, BiomolDescr_name))
264     chnid = vnp->data.ptrvalue;
265    
266   string_name[0] = '\0';
267   StringCpy(string_name, dtp->tag->str);
268   StringCat(string_name, " ");
269   StringCat(string_name, chnid);
270   StringCat(string_name, " ");
271   StringCat(string_name, dom_name);
272 
273   sip = ValNodeNew(NULL);
274   sip->choice = SEQID_LOCAL;
275         
276   oip = ObjectIdNew();
277   sip->data.ptrvalue = oip;
278   oip->id = mid;
279   oip->str = StringSave(string_name);
280 
281   return sip;
282 }
283 
284 SeqIdPtr LIBCALL MakeGId(Int4 gi)
285 {
286         SeqIdPtr sip;
287 
288         sip = ValNodeNew(NULL);
289         sip->choice = SEQID_GI;
290         sip->data.intvalue=gi;
291 
292         return sip;
293 }
294 /*****************************************************************************
295 *
296 *   Make Bioseq Descriptors
297 *
298 *****************************************************************************/
299 
300 ValNodePtr LIBCALL MakeBioseqDescr(MoleculeGraphPtr mgp, ValNodePtr bioseq_descr)
301 {
302   ValNodePtr descr = NULL, vnp;
303   BioSourcePtr biossp = NULL;
304   ResiduePtr rs;
305   ResidueGraphPntrPtr rgpp;
306   CharPtr *resnam = NULL, rn, tmp;
307   Int4 resnum, index, len;
308   NumEnumPtr nep;
309 
310   /* For taxonomy */
311   if (vnp = ValNodeFindNext(mgp->descr, NULL, BiomolDescr_organism))
312       biossp = (BioSourcePtr) vnp->data.ptrvalue; 
313   
314   if (biossp)
315   {
316     descr = ValNodeNew(bioseq_descr);
317     if (!bioseq_descr) bioseq_descr = descr;
318     descr->choice = Seq_descr_source;
319     descr->data.ptrvalue = (Pointer) biossp;
320   }       
321   /* For comments */
322   vnp = ValNodeFindNext(mgp->descr, NULL, BiomolDescr_pdb_comment);
323   
324   if (!vnp)
325   {
326     descr = ValNodeNew(bioseq_descr);
327     if (!bioseq_descr) bioseq_descr = vnp;
328     descr->choice = Seq_descr_comment;
329     descr->data.ptrvalue = StringSave("Sequence derived from ATOM co-ordinates.");
330   }
331   /* For descr->enum */
332   resnum = CountNumOfResidues(mgp);
333   resnam = (CharPtr PNTR)MemNew((resnum + 1) * sizeof(CharPtr));
334   
335   for (rs = mgp->residue_sequence, index = 0 ; rs, index < resnum ; rs = rs->next, index++)
336   {
337     if (rs->name == NULL)
338       resnam[index] = (CharPtr)StringSave("");
339     else
340     {
341       rn = rmvSpace(rs->name);
342       if (!StringICmp(rn," "))
343       {
344         MemFree(rn);
345         resnam[index] = StringSave("");
346       }
347       else
348         resnam[index] = rn;
349     }
350   }
351   
352   descr = ValNodeNew(bioseq_descr);
353   if (bioseq_descr == NULL) bioseq_descr = descr;
354   descr->choice = Seq_descr_num;
355   descr->data.ptrvalue = ValNodeNew(NULL);
356   descr = descr->data.ptrvalue;
357   descr->choice = Numbering_enum;
358   nep = NumEnumNew();
359   descr->data.ptrvalue = nep;
360   nep->num = resnum;
361   len = 0;
362   for (index = 0; index < nep->num; index++)
363       len += StrLen(resnam[index]) + 1;
364   nep->buf = MemNew((size_t)len);
365   nep->names = MemNew((size_t)(sizeof(CharPtr) * nep->num));
366   tmp = nep->buf;
367   for (index = 0; index < nep->num; index++)
368   {
369     nep->names[index] = tmp;
370     StringMove(tmp, resnam[index]);
371     tmp += StrLen(resnam[index]) + 1;
372   }
373   
374   MemFree(resnam);
375   return bioseq_descr;
376 }
377 
378 Uint1 LIBCALL MakeBioseqMol(MoleculeGraphPtr mgp)
379 {
380   ValNodePtr vnp; 
381   Int4 mtype;  
382   Uint1 mol;
383  
384   if (vnp = ValNodeFindNext(mgp->descr, NULL, BiomolDescr_molecule_type))
385      mtype = vnp->data.intvalue;
386   
387   switch(mtype)
388   {
389     case 1:
390       mol = Seq_mol_dna;
391       break;
392     case 2:
393       mol = Seq_mol_rna;
394       break;
395     case 3:
396       mol = Seq_mol_aa;
397       break;
398   }
399   
400   return mol;
401 }
402 
403 Int4 LIBCALL CountNumOfResidues(MoleculeGraphPtr mgp)
404 {
405   Int4 resnum = 0;
406   ResiduePtr rs;
407   
408   rs = mgp->residue_sequence;
409   
410   while (rs)
411   {
412     rs = rs->next;
413     resnum++;
414   }
415   
416   return resnum;
417 }
418 
419 ByteStorePtr LIBCALL 
420 AddSeqData(MoleculeGraphPtr mgp, Uint1 mol, Int4 length, BiostrucGraphPtr bsgp, BiostrucResidueGraphSetPtr stdDictionary)
421 {
422   ByteStorePtr seq_data;
423   CharPtr olcode;
424   BiostrucResidueGraphSetPntrPtr brgsp;
425   DbtagPtr dtp;
426   AsnIoPtr aipr=NULL;
427   ResidueGraphPtr newrg;
428   ResidueGraphPntrPtr rgpp;
429   ResiduePtr rs;
430   Int2 residue;
431   Int4 i = 0;
432   
433   seq_data = BSNew(length);
434  
435   for (i = 0, rs = mgp->residue_sequence; i < length, rs; i++, rs = rs->next)
436   {
437     rgpp = rs->residue_graph;
438 
439     switch(rgpp->choice)
440     {
441       case ResidueGraphPntr_local:
442         newrg = getNstdResGraph(rgpp->data.intvalue, bsgp);
443         olcode = getNstdOlcode(newrg);
444         break;
445       case ResidueGraphPntr_biostruc:
446         break;
447       case ResidueGraphPntr_standard:
448         brgsp = (BiostrucResidueGraphSetPntrPtr)rgpp->data.ptrvalue;
449         dtp = (DbtagPtr) brgsp->biostruc_residue_graph_set_id->data.ptrvalue;
450         olcode = getStdOlcode(dtp->tag->id, brgsp->residue_graph_id, stdDictionary);
451         break;
452     }
453     residue = (Int2)(*olcode);
454     if ((mol != Seq_mol_aa) && (residue == 'U')) residue = 'T';
455     BSPutByte(seq_data, residue); 
456   }
457   
458   return seq_data;
459 }
460 
461 SeqAnnotPtr LIBCALL AddNstdSeqAnnot(MoleculeGraphPtr mgp, SeqIdPtr id, BiostrucGraphPtr bsgp)
462 {
463   ValNodePtr head = NULL, current, prev = NULL, vnp;
464   ResiduePtr rs;
465   ResidueGraphPtr newrg, currentrg, nstdrg = NULL;
466   ResidueGraphPntrPtr rgpp;
467   SeqAnnotPtr sap = NULL;
468   SeqFeatPtr sfp, prev_seqfeat;
469   SeqLocPtr slp;
470   SeqPntPtr spp;
471   Int4 nstdnum = 0, i, len, k, resnum;
472   CharPtr rname, pdbcomm, resnam, chp;
473   Boolean nucacid;
474  
475   resnum = 0;
476   for (rs = mgp->residue_sequence; rs; rs = rs->next)
477   {
478     rgpp = rs->residue_graph;
479     
480     if (rgpp->choice == ResidueGraphPntr_local)
481     {
482       newrg = getNstdResGraph(rgpp->data.intvalue, bsgp);
483       
484       if (isNstd(newrg))
485       {
486         if (nstdrg == NULL)
487           nstdrg = newrg;
488         else
489           currentrg->next = newrg;
490         currentrg = newrg;
491 
492         current = ValNodeNew(prev);
493         current->data.intvalue = resnum;
494 
495         if (head == NULL)
496           head = current;
497         else
498           prev->next = current;
499         prev = current;
500         nstdnum++;
501       } 
502       else
503         MemFree(newrg);
504     }
505     resnum++;
506   }
507   
508   if (nstdnum > 0)
509   {
510     if (sap == NULL)
511     {
512       sap = SeqAnnotNew();
513       sap->type = 1;
514     }
515     
516     prev_seqfeat = (SeqFeatPtr)sap->data;
517     if (prev_seqfeat != NULL)
518     {
519       while (prev_seqfeat->next != NULL)
520         prev_seqfeat = prev_seqfeat->next;
521     }
522     
523     for (currentrg = nstdrg, current = head, i = 0; currentrg, current, i < nstdnum; 
524          currentrg = currentrg->next, current = current->next, i++)
525     {
526       if (vnp = ValNodeFindNext(currentrg->descr, NULL, BiomolDescr_name))
527         rname = vnp->data.ptrvalue;
528       
529       if (vnp = ValNodeFindNext(currentrg->descr, NULL, BiomolDescr_pdb_comment))
530         pdbcomm = vnp->data.ptrvalue;
531       
532       nucacid = FALSE;
533       chp = rname; 
534       if ((*chp++=='D')&&(*chp++=='N')&&(*chp++=='A'))
535         nucacid = TRUE;
536       chp = rname;
537       if ((*chp++=='R')&&(*chp++=='N')&&(*chp++=='A'))
538         nucacid = TRUE;
539       
540       if (nucacid)
541       {
542         chp = rname;
543         chp+=3;
544         len = strlen(rname);
545         resnam = (CharPtr)MemNew((len-2) * sizeof(char));
546         k = 0;
547         while (*chp != '\0')
548         {
549           resnam[k++] = *chp++;
550         }
551         resnam[k] = '\0';
552       }
553       else resnam = StringSave(rname);
554         
555       sfp = SeqFeatNew();
556       if (prev_seqfeat == NULL)
557         sap->data = sfp;
558       else
559         prev_seqfeat->next = sfp;
560       prev_seqfeat = sfp;
561       sfp->data.choice = 18;   /* non-std residue */
562       sfp->data.value.ptrvalue = StringSave(resnam);
563                         
564       if (*pdbcomm != '\0') 
565         sfp->comment = StringSave(pdbcomm);
566       slp = ValNodeNew(NULL);
567       sfp->location = slp;
568       slp->choice = SEQLOC_PNT;
569       spp = SeqPntNew();
570       slp->data.ptrvalue = spp;
571       spp->point = current->data.intvalue;
572       spp->id = SeqIdDup(id);
573     }
574   
575   return sap;
576   }
577   else return NULL;
578 
579 } 
580 
581 SeqAnnotPtr LIBCALL AddSecDomToSeqAnnot(BiostrucFeaturePtr bsfp, CharPtr name, SeqAnnotPtr seq_annot, SeqIdPtr id, Int4 num)
582 {
583   SeqAnnotPtr sap;
584   SeqFeatPtr sfp, prev;
585   SeqLocPtr slp, prevloc;
586   SeqIntPtr sip;
587   CharPtr tmp;
588   Char domnum[3];
589   PDBSeqIdPtr psp;
590   ChemGraphPntrsPtr cgpp;
591   ResiduePntrsPtr rpp;
592   ResidueIntervalPntrPtr ripp = NULL;
593   Int4 rippcount = 0;
594   
595   if (bsfp == NULL) return seq_annot;
596   
597   sap = seq_annot;
598   if (sap == NULL)
599   {
600     sap = SeqAnnotNew();
601     seq_annot = sap;
602     sap->type = 1;
603   }
604   prev = (SeqFeatPtr)sap->data;
605   if (prev != NULL)
606   {
607     while (prev->next != NULL)
608      prev = prev->next;
609   }
610   
611   cgpp = (ChemGraphPntrsPtr)bsfp->Location_location->data.ptrvalue;
612   rpp = (ResiduePntrsPtr)cgpp->data.ptrvalue;
613   ripp = (ResidueIntervalPntrPtr)rpp->data.ptrvalue;
614   
615   while (ripp)
616   {
617     rippcount++;
618     ripp = ripp->next;
619   }
620    
621   sfp = SeqFeatNew();
622   if (prev == NULL)
623     sap->data = sfp;
624   else
625     prev->next = sfp;
626   prev = sfp;
627 
628   if (!StringICmp("NCBI assigned secondary structure", name))
629   {
630     sfp->data.choice = 17;   /* protein secondary structure */
631     sfp->data.value.intvalue = bsfp->type;
632     sfp->comment = StringSave(bsfp->name);
633   }
634   else
635   {
636     sfp->data.choice = 9;
637     tmp = MemNew(StringLen(bsfp->name) + sizeof(domnum));
638     *tmp = '\0';
639     StringCpy(tmp, bsfp->name);
640     sprintf(domnum, " %d", num);
641     StringCat(tmp, domnum);  
642     sfp->data.value.ptrvalue = StringSave(tmp);
643     sfp->comment = StringSave(name);
644   } 
645   slp = ValNodeNew(NULL);
646   sfp->location = slp;
647   
648   if (rippcount <= 1)
649   {
650     ripp = (ResidueIntervalPntrPtr)rpp->data.ptrvalue;
651     slp->choice = SEQLOC_INT;
652     sip = SeqIntNew();
653     slp->data.ptrvalue = sip;
654     sip->from = ripp->from - 1;
655     sip->to = ripp->to - 1;
656     sip->id = SeqIdDup(id);
657   }
658   else
659   {
660     prevloc = NULL;
661     slp->choice = SEQLOC_MIX;
662     for (ripp = (ResidueIntervalPntrPtr)rpp->data.ptrvalue; ripp; ripp = ripp->next) 
663     {
664       slp = ValNodeNew(prevloc);
665       if (prevloc == NULL)
666         sfp->location->data.ptrvalue = slp;
667       prevloc = slp;
668       slp->choice = SEQLOC_INT;
669       sip = SeqIntNew();
670       slp->data.ptrvalue = sip;
671       sip->from = ripp->from - 1;
672       sip->to = ripp->to - 1;
673       sip->id = SeqIdDup(id);
674     }
675   }
676   
677   return sap;
678 }
679 
680 ValNodePtr LIBCALL 
681 MakeHetValNode(MoleculeGraphPtr nhet, BiostrucResidueGraphSetPtr stdDictionary, ResidueGraphPtr rg)
682 {
683   ValNodePtr hetval = NULL;
684   CharPtr hettype, hetnum, hetdesc, tmp;
685   Int4 len;
686   
687   hettype = StringSave(getResNam(nhet->residue_sequence->residue_graph, stdDictionary, rg));
688   hetnum = StringSave(nhet->residue_sequence->name);
689   hetdesc = StringSave(getResComm(nhet->residue_sequence->residue_graph, stdDictionary, rg));
690   
691   hetval = ValNodeNew(NULL);
692   hetval->choice = Seq_descr_het;
693   tmp = MemNew(StringLen(hettype) + StringLen(hetnum) + StringLen(hetdesc) + 5);
694   hetval->data.ptrvalue = tmp;
695   tmp = StringMove(tmp, "(");
696   tmp = StringMove(tmp, hettype);
697   tmp = StringMove(tmp, ",");
698   tmp = StringMove(tmp, hetnum);
699   tmp = StringMove(tmp, ")");
700 
701   if (*hetdesc != '\0')
702   {
703     tmp = StringMove(tmp, " ");
704     tmp = StringMove(tmp, hetdesc);
705   }
706  
707   return hetval;
708 }
709 
710 SeqAnnotPtr LIBCALL AddHetToSeqAnnot
711 (SeqAnnotPtr seq_annot, SeqIdPtr id, ValNodePtr hetval, ValNodePtr pvnThePoints, Int4 rescount)
712 {
713   SeqAnnotPtr sap;
714   SeqFeatPtr sfp, prev;
715   SeqLocPtr slp, prevloc;
716   SeqBondPtr sbp;
717   SeqPntPtr spp;
718   ValNodePtr pvnPoint;
719   
720   
721   sap = seq_annot;
722   
723   if (sap == NULL)
724   {
725     sap = SeqAnnotNew();
726     seq_annot = sap;
727     sap->type = 1;
728   }
729  
730   prev = (SeqFeatPtr)sap->data;
731   if (prev != NULL)
732   {
733     while (prev->next != NULL)
734      prev = prev->next;
735   }
736                 
737   sfp = SeqFeatNew();
738   if (prev == NULL)
739     sap->data = sfp;
740   else
741     prev->next = sfp;
742 
743   sfp->data.choice = 19;   /* heterogen */
744   sfp->data.value.ptrvalue = hetval->data.ptrvalue;
745   slp = ValNodeNew(NULL);
746   sfp->location = slp;
747   
748   if (rescount == 1)
749   {
750     slp->choice = SEQLOC_BOND;
751     sbp = SeqBondNew();
752     slp->data.ptrvalue = sbp;
753     spp = SeqPntNew();
754     sbp->a = spp;
755     spp->id = SeqIdDup(id);
756     spp->point = (Int4) pvnThePoints->data.intvalue;
757   }
758   else
759   {
760     prevloc = NULL;
761     slp->choice = SEQLOC_MIX;
762     for (pvnPoint = pvnThePoints; pvnPoint; pvnPoint = pvnPoint->next) 
763     {
764       slp = ValNodeNew(prevloc);
765       if (prevloc == NULL)
766         sfp->location->data.ptrvalue = slp;
767       prevloc = slp;
768       slp->choice = SEQLOC_BOND;
769       sbp = SeqBondNew();
770       slp->data.ptrvalue = sbp;
771       spp = SeqPntNew();
772       sbp->a = spp;
773       spp->id = SeqIdDup(id);
774       spp->point = (Int4) pvnPoint->data.intvalue;
775     }
776   }
777                           
778   return sap;
779 }
780                         
781 SeqAnnotPtr LIBCALL AddDisulToSeqAnnot(SeqAnnotPtr seq_annot, Int4 residx1, Int4 residx2, SeqIdPtr id1, SeqIdPtr id2)
782 {
783   SeqAnnotPtr sap;
784   SeqFeatPtr sfp, prev;
785   SeqLocPtr slp;
786   SeqBondPtr sbp;
787   SeqPntPtr spp;
788   
789   sap = seq_annot;
790   
791   if (sap == NULL)
792   {
793     sap = SeqAnnotNew();
794     seq_annot = sap;
795     sap->type = 1;
796   }
797  
798   prev = (SeqFeatPtr)sap->data;
799   if (prev != NULL)
800   {
801     while (prev->next != NULL)
802      prev = prev->next;
803   }
804                 
805   sfp = SeqFeatNew();
806   if (prev == NULL)
807     sap->data = sfp;
808   else
809     prev->next = sfp;
810 
811   sfp->data.choice = 11;   /* bond */
812   sfp->data.value.intvalue = 1;   /* disulfide */
813   slp = ValNodeNew(NULL);
814   sfp->location = slp;
815   slp->choice = SEQLOC_BOND;
816   sbp = SeqBondNew();
817   slp->data.ptrvalue = sbp;
818   spp = SeqPntNew();
819   sbp->a = spp;
820   spp->id = SeqIdDup(id1);
821   spp->point = residx1;
822   spp = SeqPntNew();
823   sbp->b = spp;
824   spp->id = SeqIdDup(id2);
825   spp->point = residx2;
826   
827   return sap;
828 
829 }
830 

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.