|
NCBI Home IEB Home C Toolkit docs C++ Toolkit source browser C Toolkit source browser (2) |
NCBI C Toolkit Cross ReferenceC/cn3d/cn3dopen.c |
source navigation diff markup identifier search freetext search file search |
1 /* cn3dopen.c
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information (NCBI)
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government do not place any restriction on its use or reproduction.
13 * We would, however, appreciate having the NCBI and the author cited in
14 * any work or product based on this material
15 *
16 * Although all reasonable efforts have been taken to ensure the accuracy
17 * and reliability of the software and data, the NLM and the U.S.
18 * Government do not and cannot warrant the performance or results that
19 * may be obtained by using this software or data. The NLM and the U.S.
20 * Government disclaim all warranties, express or implied, including
21 * warranties of performance, merchantability or fitness for any particular
22 * purpose.
23 *
24 * ===========================================================================
25 *
26 * File Name: cn3dopen.c
27 *
28 * Author: Christopher Hogue, Yanli Wang, Lewis Geer
29 *
30 * First Version Creation Date: 1/31/96
31 *
32 * $Revision: 6.112 $
33 *
34 * File Description: Cn3d file opening routines
35 *
36 *
37 * Modifications:
38 * --------------------------------------------------------------------------
39 * Date Name Description of modification
40 * ------- ---------- -----------------------------------------------------
41 * $Log: cn3dopen.c,v $
42 * Revision 6.112 2000/07/24 22:30:20 thiessen
43 * fix header conflict
44 *
45 * Revision 6.111 2000/07/21 18:55:14 thiessen
46 * allow dynamic slave->master transformation
47 *
48 * Revision 6.110 2000/06/16 14:57:03 lewisg
49 * move entrez calls out of desktop
50 *
51 * Revision 6.109 2000/05/16 20:24:23 thiessen
52 * don't display alignseq
53 *
54 * Revision 6.108 2000/05/16 18:13:32 lewisg
55 * fix cdd load bug
56 *
57 * Revision 6.107 2000/05/16 12:44:55 lewisg
58 * fix coloring bug for strucseqs
59 *
60 * Revision 6.106 2000/05/16 11:08:44 wheelan
61 * changed sap to salp in SAM_ReplaceGI call at line 505
62 *
63 * Revision 6.105 2000/05/15 23:39:34 lewisg
64 * shred cblast, add menu items for gapped/ungapped, fix pdbheaders
65 *
66 * Revision 6.104 2000/04/20 23:27:45 lewisg
67 * misc bug fixes
68 *
69 * Revision 6.103 2000/04/11 20:05:39 lewisg
70 * fix freeing bug on bioseq import, misc. tweaks
71 *
72 * Revision 6.102 2000/04/10 20:33:40 lewisg
73 * fix show/hide for blast multiple, make blast multiple API generic
74 *
75 * Revision 6.101 2000/04/08 00:37:30 lewisg
76 * multiple seqentries, NEWSEQ message, etc.
77 *
78 * Revision 6.100 2000/04/07 17:48:39 thiessen
79 * make 'identity' color default for strucseqs
80 *
81 * Revision 6.99 2000/04/04 22:18:42 lewisg
82 * add defline to ddv, fix seq import bugs, set boundbox
83 *
84 * Revision 6.98 2000/04/04 17:51:54 lewisg
85 * fix various seq import bugs
86 *
87 * Revision 6.97 2000/04/03 21:05:53 lewisg
88 * fix launch of cn3d from sequin
89 *
90 * Revision 6.96 2000/04/03 14:56:22 lewisg
91 * fix sequence import hang
92 *
93 * Revision 6.95 2000/03/28 21:18:54 lewisg
94 * more bug fixes for strucseqs
95 *
96 * Revision 6.94 2000/03/28 19:28:13 lewisg
97 * prep new imported sa
98 *
99 * Revision 6.93 2000/03/28 16:23:04 thiessen
100 * store row number in MMD after BLAST import
101 *
102 * Revision 6.92 2000/03/27 22:15:04 lewisg
103 * add show/hide row dialog
104 *
105 * Revision 6.91 2000/03/27 17:15:42 thiessen
106 * fix layer display bug
107 *
108 * Revision 6.90 2000/03/24 20:34:56 lewisg
109 * add blast from file, bug fixes, get rid of redundant code, etc.
110 *
111 * Revision 6.89 2000/03/23 21:01:07 thiessen
112 * add row number (1) to structure of strucseqs mime type
113 *
114 * Revision 6.88 2000/03/22 23:17:49 thiessen
115 * added ability to save ARS in ASN1
116 *
117 * Revision 6.87 2000/03/20 18:18:33 thiessen
118 * fixed header problem causing network unavailability
119 *
120 * Revision 6.86 2000/03/18 22:39:50 lewisg
121 * copy blast3 headers in makeall.unx, add blast3 to entrez link
122 *
123 * Revision 6.84 2000/03/18 00:06:00 lewisg
124 * add blast, new help, new menus
125 *
126 * Revision 6.83 2000/03/15 04:43:55 thiessen
127 * various minor fixes
128 *
129 * Revision 6.82 2000/03/14 18:03:13 thiessen
130 * add target row to MMD; remove rowmgr
131 *
132 * Revision 6.81 2000/03/13 22:03:21 lewisg
133 * add globalpars to network biostruc open
134 *
135 * Revision 6.80 2000/03/09 20:32:26 lewisg
136 * fix saving strucseq
137 *
138 * Revision 6.79 2000/03/09 17:56:58 thiessen
139 * changes to palette handling, feature implementation, PARS storage
140 *
141 * Revision 6.78 2000/03/08 21:46:14 lewisg
142 * cn3d saves viewport, misc bugs
143 *
144 * Revision 6.77 2000/03/02 21:11:06 lewisg
145 * use bandalign for import sequence, make standalone ddv use viewmgr, make dialogs modal, send color update
146 *
147 * Revision 6.76 2000/03/01 22:49:41 lewisg
148 * import bioseq, neatlyindex, get rid of dead code
149 *
150 * Revision 6.75 2000/03/01 16:17:55 thiessen
151 * improved handling of colors; many small fixes
152 *
153 * Revision 6.74 2000/02/19 21:25:57 thiessen
154 * split of cn3dmodl into cn3dmodl and cn3dstyl
155 *
156 * Revision 6.73 2000/02/15 22:40:57 lewisg
157 * add ability to launch udv so that it colors by row, fixes to colormgr, track rows from viewmgr, fix visual c projects
158 *
159 * Revision 6.72 2000/02/10 17:47:02 thiessen
160 * added: color-by-sequence-conservation menu item, zoom-out to OpenGL, misc fixes
161 *
162 * Revision 6.71 2000/02/05 01:32:21 lewisg
163 * add viewmgr, move place freeing is done in ddv, modify visual c++ projects
164 *
165 * Revision 6.70 2000/01/21 15:59:05 lewisg
166 * add check for binary/ascii files
167 *
168 * Revision 6.69 2000/01/14 21:40:41 lewisg
169 * add translucent spheres, ion labels, new cpk, fix misc bugs
170 *
171 * Revision 6.68 2000/01/04 15:55:51 lewisg
172 * don't hang on disconnected network and fix memory leak/hang at exit
173 *
174 * Revision 6.67 1999/12/28 23:06:35 lewisg
175 * udv/cn3d communication
176 *
177 * Revision 6.66 1999/12/28 15:55:21 lewisg
178 * remove remaining mediainfo code
179 *
180 * Revision 6.65 1999/12/15 23:17:47 lewisg
181 * make cn3d launch udv, fix launching of non-autonomous udv, add mouseup message
182 *
183 * Revision 6.64 1999/12/13 23:20:44 lewisg
184 * bug fixes: duplicate color structures eliminated, clear color doesn't clear case
185 *
186 * Revision 6.63 1999/12/11 01:30:35 lewisg
187 * fix bugs with sharing colors between ddv and cn3d
188 *
189 * Revision 6.62 1999/12/01 16:15:54 lewisg
190 * interim checkin to fix blocking memory leak
191 *
192 * Revision 6.61 1999/11/24 15:23:19 lewisg
193 * added color selection dialogs for SS
194 *
195 * Revision 6.60 1999/11/15 18:30:08 lewisg
196 * get rid of extra redraws when selecting
197 *
198 * Revision 6.59 1999/11/10 23:19:41 lewisg
199 * rewrite of selection code for ddv
200 *
201 * Revision 6.58 1999/11/02 23:06:07 lewisg
202 * fix cn3d to launch correctly if there is no seqentry associated with bioseq
203 *
204 * Revision 6.57 1999/10/29 14:15:30 thiessen
205 * ran all Cn3D source through GNU Indent to prettify
206 *
207 * Revision 6.56 1999/10/18 16:01:09 lewisg
208 * fix bssp to bsssp
209 *
210 * Revision 6.55 1999/10/18 15:32:50 lewisg
211 * move ClearSequences() to cn3dshim.c
212 *
213 * Revision 6.54 1999/10/15 20:56:39 lewisg
214 * append DDV_ColorGlobal as userdata. free memory when cn3d terminates.
215 *
216 * Revision 6.53 1999/10/05 23:18:24 lewisg
217 * add ddv and udv to cn3d with memory management
218 *
219 * Revision 6.52 1999/09/16 17:16:21 ywang
220 * open multiple salsa window for data with multiple seq-annot data
221 *
222 * Revision 6.51 1999/08/04 21:18:01 lewisg
223 * modularized open operations to allow sequin to launch cn3d
224 *
225 * Revision 6.50 1999/07/12 19:37:44 ywang
226 * fix bug
227 *
228 * Revision 6.49 1999/07/07 20:45:37 ywang
229 * clear domaindata, mediadata, special feature before reading in new data in cn3d
230 *
231 * Revision 6.48 1999/07/07 16:41:30 ywang
232 * reset Num_Bioseq as 0 when sequences are freed
233 *
234 * Revision 6.47 1999/07/06 18:30:45 chappey
235 * Send FLUSH message on each Bioseq to close windows
236 *
237 * Revision 6.46 1999/07/06 17:18:38 ywang
238 * send OM_MSG_FLUSH message to salsa to close all its windows before new sequence window launched
239 *
240 * Revision 6.45 1999/07/02 20:58:37 ywang
241 * return NULL sep upon NULL pmsdThis in Cn3DFetchSeqEntry
242 *
243 * Revision 6.44 1999/07/02 19:57:43 ywang
244 * go through every node of SeqEntryPtr for free
245 *
246 * Revision 6.43 1999/07/02 14:39:14 ywang
247 * clean seq-entry fetching and OM register for netopen and local read(non mimetype) functioning
248 *
249 * Revision 6.42 1999/07/01 22:14:58 ywang
250 * back to previous version to use EntrezSeqEntryGet to get sequences for additional loading, before this free existant sequences
251 *
252 * Revision 6.41 1999/07/01 22:08:08 lewisg
253 * add resize before all redraws
254 *
255 * Revision 6.40 1999/07/01 21:44:30 ywang
256 * work around EntrezSeqEntryGet core dump on redunant sequence loading and free existant sequences before additional loading
257 *
258 * Revision 6.39 1999/07/01 14:07:25 ywang
259 * cn3dwin.c
260 *
261 * Revision 6.38 1999/06/15 19:08:17 kans
262 * instantiate Cn3D_useEntrez in library
263 *
264 * Revision 6.37 1999/06/15 17:57:54 ywang
265 * rename useEntrez as Cn3D_useEntrez
266 *
267 * Revision 6.36 1999/06/14 17:40:26 ywang
268 * assign mimetype to structure data read in locally or via network with respect to availability of sequences
269 *
270 * Revision 6.35 1999/04/06 20:14:09 lewisg
271 * more opengl
272 *
273 * Revision 6.34 1999/03/30 22:36:19 ywang
274 * add functions to color salsa for NcbiMimeAsn1_strucseqs & code reorganization
275 *
276 * Revision 6.33 1999/03/18 22:28:58 ywang
277 * add functions for saveout+readin+index user defined features
278 *
279 * Revision 6.32 1999/03/03 23:17:22 lewisg
280 * one master struct at a time, list slaves in structure info, bug fixes
281 *
282 * Revision 6.31 1999/02/25 23:14:31 ywang
283 * move around menu item and callback function, change menu item names
284 *
285 * Revision 6.30 1999/02/24 23:00:49 ywang
286 * record mime type at MSD node
287 *
288 * Revision 6.29 1999/01/20 18:21:20 ywang
289 * include salmedia.h due to the move around of MediaInfo from cn3dmsg.h to the new created salmedia.h
290 *
291 * Revision 6.28 1999/01/19 23:42:48 ywang
292 * fix bugs over improving color msg
293 *
294 * Revision 6.27 1999/01/14 19:07:17 kans
295 * network availability is configurable
296 *
297 * Revision 6.26 1998/12/22 15:40:32 ywang
298 * restore sequences pointer for strucseq
299 *
300 * Revision 6.25 1998/12/21 18:47:37 addess
301 * fixed strucseq bug found by Aron
302 *
303 * Revision 6.24 1998/12/16 17:02:57 ywang
304 * pick up strucseqs mime type
305 *
306 * Revision 6.23 1998/10/21 15:49:21 ywang
307 * attach the whole vast alignment data to master structure
308 *
309 * Revision 6.22 1998/09/23 18:38:50 ywang
310 * add functions to control display on domain level
311 *
312 * Revision 6.21 1998/06/30 23:29:22 ywang
313 * fix bugs regarding to read in more structures
314 *
315 * Revision 6.20 1998/06/30 14:48:04 ywang
316 * launch salsa automatically and accordingly when more structures are readin
317 *
318 * Revision 6.19 1998/06/29 19:28:00 lewisg
319 * on the fly update of conservation color
320 *
321 * Revision 6.17 1998/06/15 14:26:06 ywang
322 * automatic launch salsa when mime data got in either through command line or via local reading in
323 *
324 * Revision 6.16 1998/06/12 21:21:56 ywang
325 * change sCompare to make cn3d accept mime strucseq from local readin
326 *
327 * Revision 6.15 1998/06/04 16:48:36 ywang
328 * fix bug triggered by automatic salsa launch
329 *
330 * Revision 6.14 1998/05/27 22:15:16 ywang
331 * add Cn3dObjRegister() to several places
332 *
333 * Revision 6.13 1998/05/18 22:09:14 ywang
334 * move codes around
335 *
336 * Revision 6.12 1998/05/12 21:47:05 lewisg
337 * stricter conservation coloring
338 *
339 * Revision 6.11 1998/05/12 16:34:01 ywang
340 * take strucseq mime data
341 *
342 * Revision 6.10 1998/05/06 23:50:24 lewisg
343 * fixed launching problem with sequin
344 *
345 * Revision 6.9 1998/05/06 14:20:09 lewisg
346 * get rid of NULL structure bugs
347 *
348 * Revision 6.8 1998/04/28 22:47:21 lewisg
349 * master/slave color in sync
350 *
351 * Revision 6.7 1998/04/28 19:40:01 lewisg
352 * codewarrior fixes
353 *
354 * Revision 6.6 1998/04/28 19:38:39 lewisg
355 * codewarrior fixes
356 *
357 * Revision 6.5 1998/04/28 18:53:25 ywang
358 * take NcbiMimeAsn1_alignseq to view alignment only
359 *
360 * Revision 6.4 1998/04/28 15:20:37 kans
361 * cast needed on FileGets for CodeWarrior
362 *
363 * Revision 6.3 1998/04/28 15:14:29 lewisg
364 * moved OpenMimeFileWithDeletion to cn3dopen
365 *
366 * Revision 6.2 1998/04/27 23:23:06 lewisg
367 * added ability to open mime files
368 *
369 * Revision 6.1 1998/04/16 00:32:25 lewisg
370 * corrected neighbor mode bugs
371 *
372 * Revision 6.0 1997/08/25 18:13:38 madden
373 * Revision changed to 6.0
374 *
375 * Revision 5.0 1996/05/28 14:05:44 ostell
376 * Set to revision 5.0
377 *
378 * Revision 1.5 1996/04/18 17:01:10 hogue
379 * Fixed calls to FetchBS for later integration into Entrez, added feature to turn off redundant backbone model for faster spinning...
380 *
381 * Revision 1.4 1996/03/30 23:41:01 hogue
382 * Redraw now saves camera
383 *
384 * Revision 1.3 1996/03/29 20:01:24 hogue
385 * Added call to reset active structure upon opening.
386 *
387 * Revision 1.2 1996/02/02 19:40:19 hogue
388 * Initial Revision
389 *
390 *
391 * ==========================================================================
392 */
393
394 #include <vibrant.h>
395 #include <math.h>
396 #include <mmdbapi.h>
397 #include <accentr.h>
398 #include <objalign.h>
399 #include <objseq.h>
400 #include <objmgr.h>
401 #include <sequtil.h>
402 #include <saledit.h>
403 #include <lsqfetch.h>
404 #include <cn3dopen.h>
405 #include <cn3dmain.h>
406 #include <algorend.h>
407 #include <cn3dmsg.h>
408 #include <salmedia.h>
409 #include <cn3dshim.h>
410 #include <cn3dmodl.h>
411 #include <cn3dstyl.h>
412 #include <alignmgr.h>
413 #include <sqnutils.h>
414 #include <cn3dsave.h>
415 #include <ddvopen.h>
416 #include <seqcons.h>
417 #include <udviewer.h>
418 #include <tofasta.h>
419 #include <accutils.h>
420
421
422 static Boolean Cn3D_Open_InUse = FALSE;
423 static WindoW Cn3D_wNetOpen;
424 static TexT Cn3D_tOpen;
425 static GrouP Cn3D_gAccType;
426 static ButtoN Cn3D_bOpenAccept;
427 static GrouP Cn3D_gMdlLvl;
428 static GrouP Cn3D_gMdlNo;
429
430 static WindoW Cn3D_wOpen;
431 static ButtoN Cn3D_bOpenBrowse;
432
433 Boolean Mime_ReadIn = FALSE;
434
435 Int2 Cn3DMime = 0;
436
437
438 /*****************************************************************************
439
440 Function: Cn3D_UseNetwork()
441
442 Purpose: Sets Cn3D_ColorData.UseEntrez, if Cn3D should use the network
443
444 Returns: TRUE if yes
445
446 *****************************************************************************/
447
448 NLM_EXTERN Boolean Cn3D_CheckNetworkUse()
449 {
450 Char str[64];
451 Boolean useNetwork = FALSE;
452
453 if (GetAppParam
454 ("CN3D", "SETTINGS", "NETWORKAVAILABLE", NULL, str, sizeof(str))) {
455 if (StringICmp(str, "TRUE") == 0) useNetwork = TRUE;
456 }
457 Cn3D_ColorData.UseEntrez = useNetwork;
458 Cn3D_ColorData.EntrezOn = FALSE;
459 return useNetwork;
460 }
461
462 /*------------------------------------------------------*/
463 Boolean Cn3D_UsingEntrez(void)
464 {
465 return Cn3D_ColorData.UseEntrez;
466 }
467
468 /*------------------------------------------------------*/
469 Boolean Cn3D_EntrezOn(void)
470 {
471 return Cn3D_ColorData.EntrezOn;
472 }
473
474 /*------------------------------------------------------*/
475 SeqEntryPtr Cn3DFetchSeqEntry(PMSD pmsdThis)
476 {
477 PDNMM pdnmmHead = NULL;
478 PMMD pmmdThis = NULL;
479 SeqId si;
480 Bioseq *bsp;
481
482 if (pmsdThis == NULL)
483 return NULL;
484
485 pdnmmHead = pmsdThis->pdnmmHead;
486 while (pdnmmHead) {
487 pmmdThis = pdnmmHead->data.ptrvalue;
488 if (pmmdThis == NULL)
489 goto errot;
490 if (pmmdThis->bWhat != (Byte) AM_PROT
491 && pmmdThis->bWhat != (Byte) AM_RNA
492 && pmmdThis->bWhat != (Byte) AM_DNA)
493 goto errot;
494 if (pmmdThis->iGi != 0) {
495 si.choice = SEQID_GI;
496 si.data.intvalue = pmmdThis->iGi;
497 bsp = BioseqLockById(&si);
498 BioseqUnlock(bsp);
499
500 if (bsp != NULL)
501 return SeqEntryFind(&si);
502 }
503
504 errot:
505 pdnmmHead = pdnmmHead->next;
506 }
507
508 return NULL;
509 }
510
511 static SeqAnnot * Cn3D_ShredCBlast(SeqAnnot *sap)
512 {
513 SeqAlign *salp;
514 SeqAnnot *sapout, *saptmp;
515
516 if (sap == NULL) return NULL;
517
518 saptmp = sap;
519 while (saptmp) {
520 if (saptmp->type == 2) {
521 salp = saptmp->data;
522 break;
523 }
524 saptmp = saptmp->next;
525 }
526
527 if (salp) {
528 if(am_guess_numrows(salp) > 2) return sap;
529 SAM_ReplaceGI(salp);
530 AlnMgrIndexSeqAlign(salp);
531 AlnMgrMakeMultipleByScore(salp);
532 AlnMgrDeleteHidden(salp, FALSE);
533 sapout = SeqAnnotNew();
534 sapout->data = DDV_ShredAln(salp);
535 if(sapout->data == NULL) return sap;
536 sapout->type = 2;
537 return sapout;
538 } else return NULL;
539 }
540
541
542 /*
543 sets alignment bits in master structure given pairwise seqaligns
544 */
545 static void Cn3D_MarkStrucSeqs(PDNMS pdnmsThis, SeqAnnot *sap)
546 {
547 PMSD pmsdThis = NULL;
548 PMMD pmmdThis = NULL;
549 PMGD pmgdThis = NULL;
550 SeqIdPtr sip = NULL;
551 SeqAlignPtr salp = NULL;
552 DenseSegPtr dssp = NULL;
553 DenseDiagPtr ddp = NULL;
554 Int4 nres, numseg;
555
556 if (sap == NULL || pdnmsThis == NULL) return;
557 pmsdThis = pdnmsThis->data.ptrvalue;
558 if (pmsdThis == NULL) return;
559
560 while (sap) {
561 if (sap->type == 2) {
562 salp = sap->data;
563 break;
564 }
565 sap = sap->next;
566 }
567
568 if (salp) {
569 if(salp->segtype == SAS_DENDIAG) {
570 ddp = salp->segs;
571 sip = ddp->id;
572 }
573 else if(salp->segtype == SAS_DENSEG) {
574 dssp = salp->segs;
575 sip = dssp->ids;
576 }
577 else return;
578 pmmdThis = GetMMFromMSDBySeqId(pmsdThis, sip);
579 /* assume the first sip is for the sequence with known structure */
580 } else return;
581
582 if (pmmdThis == NULL) return;
583
584 while (salp) {
585 pmsdThis->bAligned++;
586 if(salp->segtype == SAS_DENSEG) {
587 dssp = salp->segs;
588 if(dssp->dim != 2) continue;
589
590 for (numseg = 0; numseg < dssp->numseg; numseg++) {
591 if (dssp->starts[numseg*2] == -1
592 || dssp->starts[numseg*2+1] == -1 ) continue;
593 for (nres = dssp->starts[numseg*2];
594 nres < dssp->starts[numseg*2] + dssp->lens[numseg];
595 nres++) {
596 pmgdThis = GetMGFromMM(pmmdThis, nres + 1);
597 if (pmgdThis) pmgdThis->bReserved++;
598 }
599 }
600 }
601 else /* densediag */ {
602 ddp = salp->segs;
603 if(ddp->dim != 2) continue;
604 if (ddp->starts[0] != -1 && ddp->starts[1] != -1) {
605 for (nres = ddp->starts[0]; nres < ddp->starts[0] + ddp->len;
606 nres++) {
607 pmgdThis = GetMGFromMM(pmmdThis, nres + 1);
608 if (pmgdThis) pmgdThis->bReserved++;
609 }
610 }
611 }
612 salp = salp->next;
613 }
614 }
615
616
617 /**********
618 fnMarkAlignedResidue()
619 Given a master and model, mark all of the residues in the slave and master that are aligned.
620 **********/
621
622 ValNodePtr fnMarkAlignedResidues(PDNMS pdnmsMaster, PDNMS pdnmsSlave,
623 BiostrucFeaturePtr pbsfThis)
624 {
625
626 ValNodePtr pvnAlignment;
627 ValNodePtr pvnThis = NULL;
628 ChemGraphPntrsPtr pcgpThis;
629 ValNodePtr pvnListMaster = NULL, pvnListSlave = NULL,
630 pvnListMasterHead, pvnListSlaveHead;
631 PFB pfbMaster = NULL, pfbSlave = NULL;
632 ChemGraphAlignmentPtr pcgaSlave;
633
634
635 /* find the corresponding alignment */
636 pvnAlignment =
637 ValNodeFindNext(pbsfThis->Location_location, NULL,
638 Location_location_alignment);
639 if (pvnAlignment == NULL)
640 return NULL;
641
642
643 pcgaSlave = pvnAlignment->data.ptrvalue;
644 pvnThis = pcgaSlave->alignment;
645 if (pvnThis) {
646 pcgpThis = (ChemGraphPntrsPtr) pvnThis;
647 pvnListMasterHead = pvnListMaster =
648 MakeChemGraphNodeList(pdnmsMaster, pcgpThis);
649 pcgpThis = (ChemGraphPntrsPtr) pvnThis->next;
650 pvnListSlaveHead = pvnListSlave =
651 MakeChemGraphNodeList(pdnmsSlave, pcgpThis);
652 if (!pvnListMaster || !pvnListSlave)
653 return NULL;
654 while (pvnListMaster && pvnListSlave) {
655 pfbMaster = (PFB) pvnListMaster->data.ptrvalue;
656 pfbMaster->bReserved++;
657 pfbSlave = (PFB) pvnListSlave->data.ptrvalue;
658 pfbSlave->bReserved++;
659 ((PMGD) pfbSlave)->pbMasterReserved = &(pfbMaster->bReserved); /* use unused feature pointer to point slave back at master */
660 pvnListSlave = pvnListSlave->next;
661 pvnListMaster = pvnListMaster->next;
662 } /* while pvnListMaster */
663 ValNodeFree(pvnListMasterHead);
664 ValNodeFree(pvnListSlaveHead);
665 } /* while pvnThis */
666 return pvnAlignment;
667 }
668
669 /************
670 fnClearMarkedResidues
671 callback function used to clear all of the alignment pointers and counters used for protein conservation calculations
672 ************/
673
674 void LIBCALLBACK fnClearMarkedResidues(PFB pfbThis, Int4 iModel,
675 Int4 iIndex, Pointer ptr)
676 {
677 PMGD pmgdThis;
678
679 pfbThis->bReserved = 0;
680 pmgdThis = (PMGD) pfbThis;
681 pmgdThis->pbMasterReserved = NULL;
682 }
683
684 /******************************************************************************
685 *
686 * Traverses the given MSD and sets it up for displaying one model or animation
687 * Turns off backbone model if all atoms is loaded in?
688 *
689 ******************************************************************************/
690
691 NLM_EXTERN void MMDB_OpenTraverse(PMSD pmsd)
692 {
693 PDNML pdnmlThis = NULL;
694 PMLD pmldThis = NULL;
695 PMLD pmldOne = NULL;
696 PMLD pmldAll = NULL;
697
698 pdnmlThis = pmsd->pdnmlModels;
699 /* set up for doing one model or animation */
700 while (pdnmlThis) {
701 pmldThis = (PMLD) pdnmlThis->data.ptrvalue;
702 if (pmldThis->iType == Model_type_ncbi_backbone)
703 pmldOne = pmldThis;
704 if (pmldThis->iType == Model_type_ncbi_all_atom)
705 pmldAll = pmldThis;
706 pdnmlThis = pdnmlThis->next;
707 }
708
709 if (pmldOne && pmldAll)
710 pmldOne->bSelected &= (Byte) 0xFE;
711 }
712
713 /******************************************************************************
714 *
715 * Sets up Cn3D for reading in a new structure and any potential alignments
716 * and bioseqs.
717 *
718 ******************************************************************************/
719
720 NLM_EXTERN void Cn3D_OpenStart()
721 {
722 Int4 iBioseq = 0;
723
724 #ifndef _OPENGL
725 Cn3D_SaveActiveCam();
726 #endif
727
728 ObjMgrDeSelectAll();
729 Mime_ReadIn = FALSE;
730
731 ClearSequences();
732 ClearStructures();
733 ClearRest();
734 }
735
736 NLM_EXTERN Boolean Cn3D_StartNet(Boolean UseNetwork)
737 {
738 if (Cn3D_ColorData.EntrezOn) return TRUE;
739 if (Cn3D_ColorData.UseEntrez) {
740 if(EntrezInit("Cn3D", TRUE, NULL)) {
741 if(EntrezBioseqFetchEnable("Cn3D", FALSE)) {
742 Cn3D_ColorData.EntrezOn = TRUE;
743 return TRUE;
744 }
745 }
746 }
747 return FALSE;
748 }
749
750 /******************************************************************************
751 *
752 * Finishes setting up Cn3D. Called after reading in a new structure and any
753 * alignments and bioseqs. If necessary, will load in a sequence via
754 * netentrez if a network connection is open.
755 *
756 ******************************************************************************/
757
758 /* call back to replace gi's with full seqid's */
759 static void LIBCALLBACK fnRewireSips(PFB pfbThis, Int4 iModel,
760 Int4 iIndex, Pointer ptr)
761 {
762 PMMD pmmdThis;
763 Bioseq *bsp;
764 SeqId *sip;
765
766 pmmdThis = (PMMD) pfbThis;
767 if(pmmdThis->pSeqId == NULL) return;
768 bsp = BioseqLockById(pmmdThis->pSeqId);
769 if(bsp == NULL) return;
770 sip = SeqIdDupList(bsp->id);
771 BioseqUnlock(bsp);
772 if(sip == NULL) {
773 return;
774 }
775 SeqIdFree(pmmdThis->pSeqId);
776 pmmdThis->pSeqId = sip;
777 return;
778 }
779
780
781 NLM_EXTERN void Cn3D_OpenEnd()
782 {
783 PMSD pmsdMaster = NULL;
784 PDNMS pdnmsMaster = NULL, pdnmsSlave = NULL;
785 SeqEntryPtr sep = NULL;
786 #ifdef _OPENGL
787 BiostrucFeaturePtr bsfp;
788 Camera *camera;
789 #endif
790
791 Cn3DIndexUserDefinedFeature();
792
793 #ifdef _OPENGL
794 OGL_Reset(Cn3D_ColorData.OGL_Data);
795 #else
796 ZoomAll3D(Cn3D_v3d);
797 #endif
798
799 pdnmsMaster = GetSelectedModelstruc();
800 if(pdnmsMaster == NULL) return;
801 pmsdMaster = pdnmsMaster->data.ptrvalue;
802 if(pmsdMaster == NULL) return;
803
804 Cn3D_GetRenderSettingsFromBiostruc(pdnmsMaster);
805
806 if (!Mime_ReadIn || pmsdMaster->iMimeType == NcbiMimeAsn1_entrez) {
807 Cn3D_StartNet(TRUE);
808 if (Cn3D_ColorData.EntrezOn) {
809 sep = Cn3DFetchSeqEntry(pmsdMaster);
810 if (sep != NULL) {
811 pmsdMaster->iMimeType = NcbiMimeAsn1_strucseq;
812 Cn3D_RegisterSeqEntry(sep);
813 }
814 else pmsdMaster->iMimeType = NcbiMimeAsn1_entrez;
815 }
816 else pmsdMaster->iMimeType = NcbiMimeAsn1_entrez;
817 }
818
819 Cn3D_ColorData.IsUserData = TRUE;
820 if(Cn3D_ColorData.pDDVColorGlobal == NULL) {
821 Cn3D_ColorData.pDDVColorGlobal = DDV_CreateColorGlobal(FALSE,
822 NULL);
823 DDV_LoadSSColor(Cn3D_ColorData.pDDVColorGlobal, "CN3D");
824 Cn3D_ColorData.IsUserData = FALSE;
825 Cn3D_RegisterColor();
826 }
827
828 if (pmsdMaster->iMimeType != NcbiMimeAsn1_entrez) {
829 TraverseMolecules(pdnmsMaster, 0, 0, NULL,
830 (pNodeFunc) fnRewireSips);
831 for(pdnmsSlave = pmsdMaster->pdnmsSlaves; pdnmsSlave != NULL;
832 pdnmsSlave = pdnmsSlave->next)
833 TraverseMolecules(pdnmsSlave, 0, 0, NULL,
834 (pNodeFunc) fnRewireSips);
835 }
836
837 Cn3D_ResetActiveStrucProc();
838 Cn3D_RedrawEx(TRUE); /* always a new structure */
839
840 #ifdef _OPENGL
841 bsfp = Cn3D_FindFeature(pmsdMaster->pbsBS->features,
842 Feature_type_camera, 1);
843
844 if(bsfp != NULL) {
845 camera = (Camera *)bsfp->Property_property->data.ptrvalue;
846 if(camera->scale != 0) {
847 Cn3D_Asn2Matrix(Cn3D_ColorData.OGL_Data->ModelMatrix, camera->modelview);
848 Cn3D_ColorData.OGL_Data->CameraDistance = ((FloatLo)camera->distance)
849 /camera->scale;
850 Cn3D_ColorData.OGL_Data->CameraAngle = ((FloatLo)camera->angle)
851 /camera->scale;
852 Cn3D_ColorData.OGL_Data->CameraDirection[0] = ((FloatLo)camera->x)
853 /camera->scale;
854 Cn3D_ColorData.OGL_Data->CameraDirection[1] = ((FloatLo)camera->y)
855 /camera->scale;
856 Cn3D_ColorData.OGL_Data->NeedCameraSetup = TRUE;
857 }
858 }
859 OGL_AllLayerOnProc(Cn3D_ColorData.OGL_Data);
860 #endif
861
862 Cn3D_RedrawNUpdate(FALSE);
863 if (pmsdMaster->iMimeType != NcbiMimeAsn1_entrez) LaunchSequenceWindow();
864
865 }
866
867 static void Cn3D_StoreAlignRowNumsInMMDs(SeqAnnot * sanp)
868 {
869 PDNMS pdnmsMaster, pdnmsSlave;
870 PMMD pmmdThis;
871 Int4 row = 1;
872 SeqAlignPtr salp = NULL;
873 SeqIdPtr sip;
874
875 for (; sanp != NULL; sanp = sanp->next) {
876 if (sanp->data == NULL) continue;
877 salp = sanp->data;
878 break;
879 }
880 if (!salp) return;
881
882 pdnmsMaster = GetSelectedModelstruc();
883 if (pdnmsMaster == NULL) return;
884
885 /* assume master is row #1 */
886 sip = AlnMgrGetNthSeqIdPtr(salp, row);
887 pmmdThis = GetMMFromMSDBySeqId((PMSD) pdnmsMaster->data.ptrvalue, sip);
888 if (!pmmdThis) {
889 Message(MSG_ERROR, "error matching master MMD to target row 0");
890 return;
891 }
892 pmmdThis->iTargetRow = row;
893 row++;
894
895 /* assume slaves are rows 2..N in order */
896 for(pdnmsSlave = ((PMSD) pdnmsMaster->data.ptrvalue)->pdnmsSlaves;
897 pdnmsSlave;
898 pdnmsSlave = pdnmsSlave->next, row++) {
899
900 sip = AlnMgrGetNthSeqIdPtr(salp, row);
901 pmmdThis = GetMMFromMSDBySeqId((PMSD) pdnmsSlave->data.ptrvalue, sip);
902 if (!pmmdThis) {
903 Message(MSG_ERROR, "error matching slave MMD to target row %i", row);
904 return;
905 }
906 pmmdThis->iTargetRow = row;
907 }
908 }
909
910
911 /******************************************************************************
912 *
913 * Opens the file with filename and tries to read in NcbiMimeAsn1. Doesn't
914 * care if it binary or text encoded. If removeIt is set, deletes the file
915 * afterwards. The NcbiMimeAsn1 is read into the object manager and MMDBapi
916 *
917 ******************************************************************************/
918
919 Boolean OpenMimeFileWithDeletion(CharPtr filename, Boolean removeIt)
920 {
921 Boolean retval = FALSE;
922 AsnIoPtr aip;
923 Char buf[50];
924 NcbiMimeAsn1Ptr mime;
925 FILE *fp = FileOpen(filename, "r");
926
927 WatchCursor();
928 if (!fp)
929 return FALSE;
930
931 FileRead(buf, 1, StrLen(PRINT_FORM_MIME_NAME), fp);
932 FileClose(fp);
933 if (StrNCmp(buf, PRINT_FORM_MIME_NAME, StrLen(PRINT_FORM_MIME_NAME)) ==
934 0) aip = AsnIoOpen(filename, "r");
935 else
936 aip = AsnIoOpen(filename, "rb");
937 if (!aip)
938 return FALSE;
939 mime = NcbiMimeAsn1AsnRead(aip, NULL);
940 AsnIoClose(aip);
941 if (!mime)
942 return FALSE;
943 Cn3DMime = mime->choice;
944
945 Cn3D_OpenStart();
946 Mime_ReadIn = TRUE;
947 retval = MMDB_ReadMime(mime);
948 Cn3D_OpenEnd();
949
950 if (removeIt) {
951 FileRemove(filename);
952 }
953 ArrowCursor();
954
955 return retval;
956 }
957
958 /*
959 * callback to initialize MG's PARS list with default PARS (passed as ptr)
960 */
961 void LIBCALLBACK fnSetGlobalPARSinMG(PFB pfbThis, Int4 iModel,
962 Int4 iIndex, Pointer ptr)
963 {
964 ValNodeAddPointer(&(((PMGD) pfbThis)->pvnPARSList), 0, (VoidPtr) ptr);
965 }
966
967 NLM_EXTERN void Cn3D_SetPars(PARS parsThis, PDNMS pdnms)
968 {
969 PMSD pmsdThis;
970
971 if(parsThis == NULL || pdnms == NULL) return;
972 pmsdThis = pdnms->data.ptrvalue;
973 pmsdThis->pGlobalPARS = parsThis;
974 TraverseGraphs(pdnms, 0, 0, (Pointer) parsThis, (pNodeFunc) fnSetGlobalPARSinMG);
975 }
976
977 /******************************************************************************
978 *
979 * Meant to be an ncbiobj and mmdb dependent function to process mime input
980 * into objects and MSD's. Still has a few dependencies to be eliminated
981 *
982 ******************************************************************************/
983 Boolean MMDB_ReadMime(NcbiMimeAsn1Ptr mime)
984 {
985 Boolean retval = FALSE;
986 BiostrucFeaturePtr pbsfThis;
987 PMSD pmsdSlave = NULL, pmsdMaster = NULL;
988 PDNMS pdnmsMaster = NULL, pdnmsSlave = NULL;
989 BiostrucAlignSeqPtr pbsasThis = NULL;
990 SeqAnnotPtr sap = NULL;
991
992
993 do { { /* TRY */
994 EntrezGeneralPtr egp;
995 BiostrucAlignPtr pbsaThis;
996 BiostrucSeqPtr bssp;
997 BiostrucSeqsPtr bsssp;
998 PDNMS pdnms = NULL;
999 PMSD pmsdThis = NULL;
1000 PDNML pdnmlThis = NULL;
1001 ValNodePtr pvnAlignment;
1002 PDNTRN pdnTransform = NULL;
1003 PARS parsThis;
1004 BiostrucPtr pbsThis;
1005
1006 switch (mime->choice) {
1007
1008 case NcbiMimeAsn1_entrez:
1009 egp = (EntrezGeneralPtr) mime->data.ptrvalue;
1010 if (!egp || !egp->Data_data)
1011 break; /* THROW */
1012
1013 retval = TRUE;
1014 switch (egp->Data_data->choice) {
1015 case Data_data_structure:
1016 pdnms =
1017 MakeAModelstruc((BiostrucPtr) egp->Data_data->data.ptrvalue);
1018 if (!pdnms) break;
1019
1020 pmsdThis = (PMSD) pdnms->data.ptrvalue;
1021 pmsdThis->iMimeType = NcbiMimeAsn1_entrez;
1022 MMDB_OpenTraverse(pmsdThis);
1023 Cn3D_SetPars(NewStructureRenderSet(), pdnms);
1024 break;
1025
1026 case Data_data_nuc:
1027 case Data_data_prot:
1028 case Data_data_ml:
1029 case Data_data_genome:
1030 default:
1031 break;
1032 }
1033 break;
1034
1035 case NcbiMimeAsn1_strucseq:
1036 bssp = (BiostrucSeqPtr) mime->data.ptrvalue;
1037 pdnms = MakeAModelstruc((BiostrucPtr) bssp->structure);
1038 if (!pdnms) break;
1039
1040 pmsdThis = (PMSD) pdnms->data.ptrvalue;
1041 Cn3D_SetPars(NewStructureRenderSet(), pdnms);
1042 pmsdThis->iMimeType = NcbiMimeAsn1_strucseq;
1043
1044 MMDB_OpenTraverse(pmsdThis);
1045 Cn3D_RegisterSeqEntry(bssp->sequences);
1046 break;
1047
1048 case NcbiMimeAsn1_strucseqs:
1049 bsssp = (BiostrucSeqsPtr) mime->data.ptrvalue;
1050 pdnms = MakeAModelstruc((BiostrucPtr) bsssp->structure);
1051 if (!pdnms) break;
1052
1053 pmsdThis = (PMSD) pdnms->data.ptrvalue;
1054 pmsdThis->iMimeType = NcbiMimeAsn1_strucseqs;
1055 MMDB_OpenTraverse(pmsdThis);
1056 Cn3D_MarkStrucSeqs(pdnms, bsssp->seqalign);
1057
1058 sap = Cn3D_ShredCBlast(bsssp->seqalign);
1059 Cn3D_RegisterSeqAnnot(sap, TRUE, TRUE);
1060 Cn3D_RegisterSeqEntry(bsssp->sequences);
1061 parsThis = NewStructureRenderSet();
1062 parsThis->PBBColor = C_BYSEQCONS;
1063 parsThis->ConsColAlg = CSC_SHOWIDENTITY;
1064 Cn3D_SetPars(parsThis, pdnms);
1065 /* after indexing/IBM, store "original" row numbers in corresponding MMD */
1066 Cn3D_StoreAlignRowNumsInMMDs(sap);
1067 break;
1068
1069 case NcbiMimeAsn1_alignseq:
1070 /*
1071 pbsasThis = (BiostrucAlignSeqPtr) mime->data.ptrvalue;
1072 sap = Cn3D_ShredCBlast(pbsasThis->seqalign);
1073 Cn3D_RegisterSeqAnnot(sap, TRUE, TRUE);
1074 Cn3D_RegisterSeqEntry(pbsasThis->sequences);
1075 */
1076 Message(MSG_ERROR, "Cn3D: Sorry, can't view alignments without structures (yet).");
1077 exit(-1);
1078 return retval;
1079
1080 case NcbiMimeAsn1_alignstruc: /* this is the code that received alignments */
1081 pbsaThis = (BiostrucAlignPtr) mime->data.ptrvalue;
1082 if (!pbsaThis) break; /* THROW */
1083 retval = TRUE;
1084 /* load in the master */
1085 pdnmsMaster = MakeAModelstruc((BiostrucPtr) pbsaThis->master); /* grab the master struc */
1086 if (!pdnmsMaster) break;
1087
1088 pmsdMaster = (PMSD) pdnmsMaster->data.ptrvalue;
1089
1090 pmsdMaster->iMimeType = NcbiMimeAsn1_alignstruc;
1091
1092 parsThis = NewAlignRenderSet();
1093 Cn3D_SetPars(parsThis, pdnmsMaster);
1094
1095 pmsdMaster->bVisible = TRUE;
1096 MMDB_OpenTraverse(pmsdMaster);
1097
1098 /* add the alignment seq annot ptr, etc. */
1099 pmsdMaster->psaStrucAlignment = pbsaThis->alignments;
1100 Cn3D_RegisterSeqAnnot(pbsaThis->seqalign, TRUE, TRUE);
1101 Cn3D_RegisterSeqEntry(pbsaThis->sequences);
1102
1103 SetNeighborOn(); /* turn on neighbor mode */
1104
1105 SetMasterModelstruc(pdnmsMaster);
1106
1107 /* do a slave */
1108 pbsThis = (BiostrucPtr) pbsaThis->slaves;
1109 pbsfThis = (BiostrucFeaturePtr)
1110 pbsaThis->alignments->features->features;
1111 pvnAlignment = NULL;
1112 TraverseGraphs(pdnmsMaster, 0, 0, NULL,
1113 (pNodeFunc) fnClearMarkedResidues);
1114
1115 while (pbsThis) {
1116 pdnmsSlave = MakeAModelstruc(pbsThis);
1117 if (!pdnmsSlave)
1118 break;
1119 TraverseGraphs(pdnmsSlave, 0, 0, NULL,
1120 (pNodeFunc) fnClearMarkedResidues);
1121 pmsdSlave = (PMSD) pdnmsSlave->data.ptrvalue;
1122 pmsdSlave->bMaster = FALSE; /* this is not a master struct */
1123 pmsdMaster->bAligned++;
1124 pmsdSlave->pbAligned = &(pmsdMaster->bAligned);
1125
1126 MMDB_OpenTraverse(pmsdSlave);
1127 Cn3D_SetPars(parsThis, pdnmsSlave);
1128
1129 pmsdSlave->bVisible = TRUE; /* turn them all on by default */
1130
1131 pvnAlignment =
1132 fnMarkAlignedResidues(pdnmsMaster, pdnmsSlave, pbsfThis);
1133 if (!pvnAlignment) break;
1134
1135 /* create the spatial transformation */
1136 pdnTransform = NULL;
1137 TransformToDNTRN(&pdnTransform,
1138 ((ChemGraphAlignmentPtr) pvnAlignment->data.ptrvalue)->transform);
1139 /* reverse transforms order to pass to Vibrant/shim3d/OpenGL as ValNode */
1140 if (pdnTransform) {
1141 while (pdnTransform->next) pdnTransform = pdnTransform->next;
1142 while (pdnTransform) {
1143 ValNodeAddPointer(&(pmsdSlave->pdnSlaveToMasterTransforms),
1144 pdnTransform->choice, pdnTransform->data.ptrvalue);
1145 pdnTransform = pdnTransform->last;
1146 }
1147
1148 }
1149
1150 /* loop over the slave's models with the transformation */
1151 /*
1152 if (pdnTransform == NULL) break;
1153 pdnmlThis = pmsdSlave->pdnmlModels;
1154
1155 while (pdnmlThis) {
1156 TraverseAtoms(pdnmsSlave, pdnmlThis->choice, 0,
1157 pdnTransform, DoApplyTransform);
1158 TraverseSolids(pdnmsSlave, pdnmlThis->choice, 0,
1159 pdnTransform, DoApplyTransform);
1160 pdnmlThis = pdnmlThis->next;
1161 }
1162 */
1163
1164 FreeDNTRN(pdnTransform);
1165
1166 pbsThis = pbsThis->next;
1167 pbsfThis = pbsfThis->next;
1168 } /*while pbsThis */
1169
1170 /* after indexing/IBM, store "original" row numbers in corresponding MMD */
1171 Cn3D_StoreAlignRowNumsInMMDs(pbsaThis->seqalign);
1172 break;
1173
1174 default:
1175 break;
1176 }
1177
1178 }
1179 } while (0); /* End-of-TRY-block */
1180
1181 return retval;
1182 }
1183
1184
1185 static void Cn3D_OpenEnableProc(TexT t)
1186 {
1187 Char str[32];
1188 GetTitle(Cn3D_tOpen, str, sizeof(str));
1189 if (StringLen(str) == 0) {
1190 Disable(Cn3D_bOpenAccept);
1191 } else {
1192 Enable(Cn3D_bOpenAccept);
1193 }
1194 return;
1195 }
1196
1197 static void Cn3D_NetOpenAcceptProc(ButtoN b)
1198 {
1199 Char str[32];
1200 BiostrucPtr pbsBiostruc = NULL;
1201 PDNMS pdnmsModelstruc = NULL;
1202 PMSD pmsdThis = NULL;
1203 Int4 MdlNo, MdlLvl;
1204
1205 WatchCursor();
1206 Cn3D_OpenStart();
1207
1208 GetTitle(Cn3D_tOpen, str, sizeof(str));
1209
1210 switch (GetValue(Cn3D_gMdlLvl)) {
1211 case 1:
1212 MdlLvl = ONECOORDATOM;
1213 break;
1214 case 2:
1215 MdlLvl = ONECOORDRES;
1216 break;
1217 case 3:
1218 MdlLvl = ALLMDL;
1219 break;
1220 case 4:
1221 MdlLvl = VECMODEL;
1222 break;
1223 case 5:
1224 MdlLvl = ALLSIMPLEMDL;
1225 break;
1226 case 6:
1227 MdlLvl = BSEVERYTHING;
1228 break;
1229 default:
1230 MdlLvl = ONECOORDATOM; /* set from config-file default */
1231 }
1232 switch (GetValue(Cn3D_gMdlNo)) {
1233 case 1:
1234 MdlNo = 1;
1235 break;
1236 case 2:
1237 MdlNo = 2;
1238 break;
1239 case 3:
1240 MdlNo = 5;
1241 break;
1242 case 4:
1243 MdlNo = 10;
1244 break;
1245 case 5:
1246 MdlNo = 15;
1247 break;
1248 case 6:
1249 MdlNo = 20;
1250 break;
1251 case 7:
1252 MdlNo = MAX_MDLNO;
1253 break;
1254 case 8:
1255 default:
1256 MdlNo = 1; /* set from config-file default */
1257 }
1258 if (GetValue(Cn3D_gMdlLvl) == 6)
1259 MdlNo = MAX_MDLNO; /* get all */
1260 if (GetValue(Cn3D_gAccType) == 1) { /* PDB */
1261 pbsBiostruc = FetchBiostrucPDB(str, MdlLvl, MdlNo);
1262 } else { /* MMDB */
1263
1264 pbsBiostruc =
1265 FetchBS(str, INP_GI, MdlLvl, MdlNo, GetMMDBAPIbExtent());
1266 }
1267 ArrowCursor();
1268 if (pbsBiostruc != NULL) {
1269 WatchCursor();
1270 pdnmsModelstruc = MakeAModelstruc(pbsBiostruc);
1271 ArrowCursor();
1272 }
1273 if (pdnmsModelstruc == NULL) {
1274 /* return a not found error here */
1275 Remove(Cn3D_wNetOpen);
1276 Cn3D_EnableFileOps();
1277 Cn3D_Open_InUse = FALSE;
1278 return;
1279 }
1280 if (GetValue(Cn3D_gMdlLvl) == 5) { /* turn off backbone model if "All" models present */
1281 pmsdThis = (PMSD) pdnmsModelstruc->data.ptrvalue;
1282 MMDB_OpenTraverse(pmsdThis);
1283 }
1284 Cn3D_SetPars(NewStructureRenderSet(), pdnmsModelstruc);
1285
1286 Remove(Cn3D_wNetOpen);
1287 Cn3D_EnableFileOps();
1288
1289 /*CALL TO initialize the view */
1290
1291 Cn3D_Open_InUse = FALSE;
1292
1293 Cn3D_OpenEnd();
1294
1295 return;
1296 }
1297
1298
1299 static void Cn3D_NetOpenCancelProc(GraphiC g)
1300 {
1301 Remove(Cn3D_wNetOpen);
1302 Cn3D_EnableFileOps();
1303 Cn3D_Open_InUse = FALSE;
1304 return;
1305 }
1306
1307 NLM_EXTERN void Cn3D_NetOpenBiostruc(IteM i)
1308 {
1309 GrouP g, hg;
1310 ButtoN b;
1311
1312 if (Cn3D_Open_InUse)
1313 return;
1314 else
1315 Cn3D_Open_InUse = TRUE;
1316
1317 Cn3D_StartNet(TRUE);
1318 if (!Cn3D_ColorData.EntrezOn) return;
1319
1320 Cn3D_wNetOpen =
1321 MovableModalWindow(-30, -20, -10, -10, " Internet retrieve from MMDB ",
1322 NULL);
1323 hg = HiddenGroup(Cn3D_wNetOpen, 3, 0, NULL);
1324 SetGroupSpacing(hg, 30, 30);
1325 g = NormalGroup(hg, 1, 0, " Enter accession code:", systemFont, NULL);
1326 SetGroupMargins(g, 10, 15);
1327 Cn3D_tOpen = DialogText(g, "", 10, (TxtActnProc) Cn3D_OpenEnableProc);
1328 Cn3D_gAccType =
1329 NormalGroup(hg, 1, 2, " accession type", systemFont, NULL);
1330 SetGroupMargins(Cn3D_gAccType, 10, 10);
1331 RadioButton(Cn3D_gAccType, "PDB Code");
1332 RadioButton(Cn3D_gAccType, "MMDB ID");
1333
1334 g = HiddenGroup(hg, 1, 2, NULL);
1335 SetGroupSpacing(g, 15, 15);
1336 Cn3D_bOpenAccept =
1337 DefaultButton(g, "OK", (BtnActnProc) Cn3D_NetOpenAcceptProc);
1338 b = PushButton(g, "Cancel", (BtnActnProc) Cn3D_NetOpenCancelProc);
1339
1340 Cn3D_gMdlLvl =
1341 NormalGroup(Cn3D_wNetOpen, 2, 3, " model complexity", systemFont,
1342 NULL);
1343 SetGroupMargins(Cn3D_gMdlLvl, 10, 10);
1344 SetGroupSpacing(Cn3D_gMdlLvl, 10, 5);
1345 RadioButton(Cn3D_gMdlLvl, "a) NCBI one XYZ per atom model");
1346 RadioButton(Cn3D_gMdlLvl, "c) NCBI backbone model");
1347 RadioButton(Cn3D_gMdlLvl, "b) original PDB models 1-n");
1348 RadioButton(Cn3D_gMdlLvl, "d) NCBI vector model");
1349 RadioButton(Cn3D_gMdlLvl, "Viewing Subset (a, c and d)");
1350 RadioButton(Cn3D_gMdlLvl, "Everything");
1351
1352 Cn3D_gMdlNo =
1353 NormalGroup(Cn3D_wNetOpen, 7, 0, " n = ", systemFont, NULL);
1354 RadioButton(Cn3D_gMdlNo, "1");
1355 RadioButton(Cn3D_gMdlNo, "2");
1356 RadioButton(Cn3D_gMdlNo, "5");
1357 RadioButton(Cn3D_gMdlNo, "10");
1358 RadioButton(Cn3D_gMdlNo, "15");
1359 RadioButton(Cn3D_gMdlNo, "20");
1360 RadioButton(Cn3D_gMdlNo, "maximum");
1361
1362
1363 SetValue(Cn3D_gMdlNo, 7);
1364 SetValue(Cn3D_gAccType, 1);
1365 SetValue(Cn3D_gMdlLvl, 5);
1366 Disable(Cn3D_bOpenAccept);
1367 Cn3D_DisableFileOps();
1368 Select(Cn3D_tOpen);
1369 Show(Cn3D_wNetOpen);
1370 return;
1371 }
1372
1373 /*********************************************/
1374 /* below this are the file i/o open-er procs */
1375 /*********************************************/
1376
1377 NLM_EXTERN void Cn3D_OpenBiostruc(IteM i)
1378 {
1379 Char str[PATH_MAX];
1380 unsigned char szBegin[10];
1381 BiostrucPtr pbsBiostruc;
1382 PDNMS pdnmsModelstruc;
1383 PMSD pmsdThis = NULL;
1384 Int4 MdlNo = MAX_MDLNO;
1385 FILE *hFile;
1386 Char buf[50];
1387
1388 StrCpy(str,"");
1389 GetInputFileName(str, sizeof(str), NULL, NULL);
1390 if(StrCmp(str,"") == 0) return;
1391 WatchCursor();
1392 hFile = FileOpen(str, "rb");
1393 if(hFile == NULL) return;
1394 FileGets((CharPtr) szBegin, 2, hFile);
1395 if (hFile == NULL) szBegin[0] = (Char) 0;
1396 FileClose(hFile);
1397 if(szBegin[0] == 31 && szBegin[1] == 139) {
1398 Message(MSG_ERROR,
1399 "This file may require a newer version of Cn3D. Go to http://www.ncbi.nlm.nih.gov/Structure/CN3D for more information");
1400 return;
1401 }
1402 /* to make cn3d to take strucseq for which szBegin[0] is 78 */
1403 /* for single biostruc szBegin[0] is 48 */
1404 if (szBegin[0] > 70) { /* mime */
1405 if (!OpenMimeFileWithDeletion(str, FALSE)) {
1406 return;
1407 }
1408 } else { /* not mime */
1409
1410 Cn3D_OpenStart();
1411 hFile = FileOpen(str, "r");
1412
1413 FileRead(buf, 1, StrLen(PRINT_FORM_BIOSTRUC), hFile);
1414 FileClose(hFile);
1415 if (StrNCmp(buf, PRINT_FORM_BIOSTRUC, StrLen(PRINT_FORM_BIOSTRUC)) ==
1416 0) { /* ASCII */
1417 /* these get everything in the file , ignoring modellevel */
1418 pbsBiostruc =
1419 FetchBS(str, INP_ASCII_FILE, BSEVERYTHING, MdlNo,
1420 CONVERT_ALL);
1421 } else { /* Binary */
1422 pbsBiostruc =
1423 FetchBS(str, INP_BINARY_FILE, BSEVERYTHING, MdlNo,
1424 CONVERT_ALL);
1425 }
1426 ArrowCursor();
1427 if (pbsBiostruc != NULL) {
1428 WatchCursor();
1429 pdnmsModelstruc = MakeAModelstruc(pbsBiostruc);
1430 pmsdThis = (PMSD) pdnmsModelstruc->data.ptrvalue;
1431 MMDB_OpenTraverse(pmsdThis);
1432 Cn3D_SetPars(NewStructureRenderSet(), pdnmsModelstruc);
1433
1434 ArrowCursor();
1435 } else return;
1436
1437 Cn3D_OpenEnd();
1438 } /* switch between mime and non-mime */
1439 }
1440
1441 /* generic set up for new alignment */
1442 static void Cn3D_ImportSAEnd(SeqAlign *salp, Boolean Neat)
1443 {
1444 SeqAnnot * annot;
1445 PMSD pmsdThis;
1446 PDNMS pdnmsThis;
1447 Uint2 entityID;
1448 PARS pars = NULL;
1449
1450 if (salp == NULL) return;
1451 pdnmsThis = GetSelectedModelstruc();
1452 if (!pdnmsThis) return;
1453
1454 /* close the sequence window */
1455 entityID =
1456 ObjMgrGetEntityIDForPointer((void *) Cn3D_ColorData.pvnsep);
1457 ObjMgrSendMsg(OM_MSG_FLUSH, entityID, 0, 0);
1458
1459 /* fetch the active structure */
1460 pars = (PARS) ((PMSD) pdnmsThis->data.ptrvalue)->pGlobalPARS;
1461 if (pars) {
1462 pars->ConsColAlg = (Nlm_Int2) 0;
1463 pars->PBBColor = C_BYSEQCONS;
1464 pars->PResColor = C_BYSEQCONS;
1465 pars->ObjectOn = FALSE;
1466 }
1467
1468 annot = SeqAnnotNew();
1469 if(annot == NULL) return;
1470 annot->type = 2;
1471 annot->data = salp;
1472
1473 /* change mime type for saving */
1474 if(pdnmsThis) {
1475 pmsdThis = pdnmsThis->data.ptrvalue;
1476 if(pmsdThis) pmsdThis->iMimeType = NcbiMimeAsn1_strucseqs;
1477 Cn3D_MarkStrucSeqs(pdnmsThis, annot);
1478 }
1479
1480 Cn3D_ColorData.pDDVColorGlobal = NULL; /* force creation of new color object */
1481 Cn3D_RegisterSeqAnnot(annot, Neat, Neat); /* register annot? */
1482 Cn3D_StoreAlignRowNumsInMMDs(annot);
1483 Cn3D_LaunchSeqAnnot(annot);
1484 ViewMgr_Update(salp);
1485 Disable(Cn3D_ColorData.BlastMany);
1486 }
1487
1488
1489 #if 0
1490
1491 static void Cn3D_ImportSAEndCB(UDV_BlastDlgData *bddp)
1492 {
1493 if(bddp) Cn3D_ImportSAEnd(bddp->salp, bddp->IBM);
1494 }
1495
1496
1497 /*******************************************************************************
1498
1499 Function : Cn3D_BlastDlg()
1500
1501 Purpose : Blast alignment dialog for multiple alignment
1502
1503 Parameters : i; menu
1504
1505 *******************************************************************************/
1506 NLM_EXTERN void Cn3D_BlastDlg(IteM i)
1507 {
1508 UDV_BlastDlgData *bddp;
1509
1510 if(Cn3D_ColorData.sap) return;
1511 Cn3D_StartNet(TRUE);
1512 if (!Cn3D_ColorData.EntrezOn) {
1513 Message(MSG_ERROR, "Blast requires network access");
1514 return;
1515 }
1516
1517 bddp = (UDV_BlastDlgData *)MemNew(sizeof(UDV_BlastDlgData));
1518 if (bddp == NULL) return;
1519 bddp->pvnSips = SAM_ExtractSips(Cn3D_ColorData.pvnsep);
1520 bddp->callback = Cn3D_ImportSAEndCB;
1521 bddp->IBM = FALSE;
1522
1523 UDV_BlastDlg(bddp);
1524 }
1525
1526 #endif /* 0 */
1527
1528 static void Cn3D_ImportSeqEntry(DDV_ImportDialog *idp)
1529 {
1530 DDVUpdateMSG dum;
1531 Uint2 entityID, entityIDsalp;
1532 ValNode *pvn;
1533
1534 entityID = ObjMgrGetEntityIDForPointer((void *) idp->bsp);
1535
1536 if(Cn3D_ColorData.sap && (idp->mode == DDVIMPNET2SA
1537 || idp->mode == DDVIMPSE2SA)) {
1538 MemSet(&dum, 0, sizeof(DDVUpdateMSG));
1539 dum.data = &entityID;
1540 dum.type = UPDATE_TYPE_NEWSEQ;
1541 entityIDsalp = ObjMgrGetEntityIDForPointer((void *) Cn3D_ColorData.sap->data);
1542 ObjMgrSendProcMsg(OM_MSG_UPDATE, entityIDsalp, 0, OBJ_SEQALIGN,
1543 0, 0, (Pointer)&dum);
1544 }
1545
1546 if(idp->mode & DDVIMPNET)
1547 {
1548 idp->sep = GetBestTopParentForData(entityID, idp->bsp);
1549 for(pvn = Cn3D_ColorData.pvnsep; pvn != NULL; pvn = pvn->next)
1550 if(pvn == idp->sep) return;
1551 }
1552 ValNodeLink(&Cn3D_ColorData.pvnsep, idp->sep);
1553 idp->sep->next = NULL;
1554 SAM_MakeViewerFree((void *) idp->sep);
1555 if(IS_Bioseq(idp->sep)) GatherSpecificProcLaunch(0, "Seq-Struc Communication",
1556 OMPROC_VIEW, FALSE, entityID, 0, OBJ_BIOSEQ);
1557 else GatherSpecificProcLaunch(0, "Seq-Struc Communication", OMPROC_VIEW,
1558 FALSE, entityID, 0, OBJ_BIOSEQSET);
1559 }
1560
1561 /*******************************************************************************
1562
1563 Function : Cn3D_ImportCBSE()
1564
1565 Purpose : callback for importing single sequence into a seqalign
1566
1567 *******************************************************************************/
1568 static void Cn3D_ImportCBSE(DDV_ImportDialog *idp, SeqAlign *salpdest,
1569 SeqAlign *salp)
1570 {
1571 if (salpdest == NULL || salp == NULL) return;
1572 SeqAlignSetFree(salp->next);
1573 salp->next = NULL;
1574 ViewMgr_Add(salpdest, salp);
1575 Cn3D_ImportSeqEntry(idp);
1576 }
1577
1578 /*******************************************************************************
1579
1580 Function : Cn3D_ImportCB()
1581
1582 Purpose : callback for importing single sequence and creating a new pairwise
1583 seqalign
1584
1585 *******************************************************************************/
1586 static void Cn3D_ImportCB(DDV_ImportDialog *idp, SeqAlign *salpdest,
1587 SeqAlign *salp)
1588 {
1589 if (salp == NULL) return;
1590 SeqAlignSetFree(salp->next);
1591 salp->next = NULL;
1592 Cn3D_ImportSAEnd(salp, TRUE);
1593 Cn3D_ImportSeqEntry(idp);
1594 }
1595
1596 /*******************************************************************************
1597
1598 Function : Cn3D_ImportBioseq()
1599
1600 Purpose : Import a single bioseq via the net
1601
1602 *******************************************************************************/
1603 static void Cn3D_sImportBioseq(Boolean Gap)
1604 {
1605 DDV_ImportDialog *idp;
1606
1607 idp = MemNew(sizeof(DDV_ImportDialog));
1608 if(idp == NULL) return;
1609
1610 idp->AccessionCB = Cn3D_Accession2Gi;
1611 idp->Gap = Gap;
1612 Cn3D_StartNet(TRUE);
1613 if (!Cn3D_ColorData.EntrezOn) {
1614 Message(MSG_ERROR, "Blast requires network access");
1615 return;
1616 }
1617
1618 if(Cn3D_ColorData.sap == NULL) {
1619 idp->sap = NULL;
1620 idp->callback = Cn3D_ImportCB;
1621 idp->pvnSips = SAM_ExtractSips(Cn3D_ColorData.pvnsep);
1622 idp->mode = DDVIMPNET2SE;
1623 }
1624 else {
1625 idp->sap = (SeqAlign *)Cn3D_ColorData.sap->data;
1626 idp->sip = AlnMgrFindMaster(idp->sap);
1627 idp->callback = Cn3D_ImportCBSE;
1628 idp->mode = DDVIMPNET2SA;
1629 }
1630
1631 DDV_ImportBioseqDlg(idp);
1632 }
1633
1634 NLM_EXTERN void Cn3D_ImportBioseq(IteM i)
1635 {
1636 Cn3D_sImportBioseq(FALSE);
1637 }
1638
1639 NLM_EXTERN void Cn3D_ImportBioseqGap(IteM i)
1640 {
1641 Cn3D_sImportBioseq(TRUE);
1642 }
1643
1644
1645 /*******************************************************************************
1646
1647 Function : Cn3D_ImportBioseqFile()
1648
1649 Purpose : Import a single bioseq from a fasta file
1650
1651 *******************************************************************************/
1652 static void Cn3D_sImportBioseqFile(Boolean Gap)
1653 {
1654 DDV_ImportDialog *idp;
1655 SeqEntry *sep; /* need to deallocate! */
1656 Char str[PATH_MAX];
1657 FILE *fp;
1658 Bioseq *bsp;
1659
1660 StrCpy(str,"");
1661 GetInputFileName(str, sizeof(str), NULL, NULL);
1662 if(StrCmp(str,"") == 0) return;
1663
1664 fp = FileOpen(str,"r");
1665
1666 sep = FastaToSeqEntry(fp, FALSE);
1667 FileClose(fp);
1668 if (sep == NULL) {
1669 Message(MSG_ERROR, "Sequence Import Error");
1670 return;
1671 }
1672
1673 if (IS_Bioseq(sep)) {
1674 bsp = (BioseqPtr) sep->data.ptrvalue;
1675 if (bsp != NULL) ObjMgrRegister (OBJ_BIOSEQ, (Pointer) bsp);
1676 } else {
1677 SeqEntryFree(sep);
1678 Message(MSG_ERROR, "Sequence Import Error: must be a single sequence");
1679 return;
1680 }
1681
1682 idp = MemNew(sizeof(DDV_ImportDialog));
1683 if(idp == NULL) return;
1684 idp->sep = sep;
1685 idp->Gap = Gap;
1686 idp->sipslave = SAM_ExtractSips(sep);
1687 idp->AccessionCB = Cn3D_Accession2Gi;
1688
1689 if(Cn3D_ColorData.sap == NULL) {
1690 idp->sap = NULL;
1691 idp->callback = Cn3D_ImportCB;
1692 idp->pvnSips = SAM_ExtractSips(Cn3D_ColorData.pvnsep);
1693 idp->mode = DDVIMPSE2SE;
1694 DDV_ImportBioseqDlg(idp);
1695 }
1696 else {
1697 idp->sap = (SeqAlign *)Cn3D_ColorData.sap->data;
1698 idp->sip = AlnMgrFindMaster(idp->sap);
1699 idp->callback = Cn3D_ImportCBSE;
1700 idp->mode = DDVIMPSE2SA;
1701 DDV_DoAlign(idp);
1702 }
1703
1704 }
1705
1706 NLM_EXTERN void Cn3D_ImportBioseqFile(IteM i)
1707 {
1708 Cn3D_sImportBioseqFile(FALSE);
1709 }
1710
1711 NLM_EXTERN void Cn3D_ImportBioseqFileGap(IteM i)
1712 {
1713 Cn3D_sImportBioseqFile(TRUE);
1714 }
1715
1716
1717 NLM_EXTERN Int4 Cn3D_Accession2Gi (CharPtr string, Boolean IsAmino)
1718 {
1719 CharPtr str;
1720 LinkSetPtr lsp;
1721 Int4 gi;
1722 DocType AAorNN; /* is this of TYP_AA or TYP_NA */
1723
1724 if (!EntrezIsInited ()) {
1725 Message (MSG_ERROR, "Network connection to Entrez unavailable");
1726 return 0;
1727 }
1728
1729 if(IsAmino) AAorNN = TYP_AA;
1730 else AAorNN = TYP_NT;
1731
1732 str = MemNew (StringLen (string) + 10);
1733 sprintf (str, "\"%s\" [ACCN]", string);
1734 lsp = EntrezTLEvalString (str, AAorNN, -1, NULL, NULL);
1735 MemFree (str);
1736 if (lsp == NULL) return 0;
1737 if (lsp->num <= 0) {
1738 LinkSetFree (lsp);
1739 return 0;
1740 }
1741 gi = lsp->uids [0];
1742 LinkSetFree (lsp);
1743 return gi;
1744 }
1745 |
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more information. |