1 /* gbfview.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: gbfview.c
27 *
28 * Author: Jonathan Kans
29 *
30 * Version Creation Date: 2/5/97
31 *
32 * $Revision: 6.106 $
33 *
34 * File Description:
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * Date Name Description of modification
39 * ------- ---------- -----------------------------------------------------
40 *
41 *
42 * ==========================================================================
43 */
44
45 #include <bspview.h>
46 #include <objsub.h>
47 #include <asn2gnbp.h>
48 #include <asn2gnbi.h>
49 #include <tofasta.h>
50 #include <explore.h>
51 #include <subutil.h>
52
53 static ParData ffParFmt = {FALSE, FALSE, FALSE, FALSE, TRUE, 0, 0};
54 static ColData ffColFmt = {0, 0, 80, 0, NULL, 'l', FALSE, FALSE, FALSE, FALSE, TRUE};
55
56 typedef struct docdescrstruct {
57 Uint2 entityID, itemtype;
58 Uint4 itemID;
59 Int2 docitem;
60 } DocDescrStruct, PNTR DocDescrPtr;
61
62 #define NOT_A_CDS 0
63 #define CDS_UNTESTED 1
64 #define CDS_OKAY 2
65 #define CDS_INVALID 3
66
67 typedef struct flatstruct {
68 Asn2gbJobPtr ajp;
69 BaseBlockPtr PNTR paragraphs;
70 Int4 numParagraphs;
71 SeqEntryPtr sep;
72 Int4 numdescr;
73 DocDescrPtr descr;
74 Uint1Ptr cdsstatus;
75 } FlatStruct, PNTR FlatStructPtr;
76
GetIDsFromDoc(DoC d,Int2 item,Uint2Ptr entityPtr,Uint4Ptr itemPtr,Uint2Ptr typePtr)77 static Boolean GetIDsFromDoc (DoC d, Int2 item, Uint2Ptr entityPtr,
78 Uint4Ptr itemPtr, Uint2Ptr typePtr)
79
80 {
81 BaseBlockPtr bbp;
82 BioseqViewPtr bvp;
83 Pointer dataPtr;
84 Uint2 entityID;
85 FlatStructPtr fsp;
86 Uint4 itemID;
87 Uint2 itemtype;
88 Boolean okay;
89 BaseBlockPtr PNTR paragraphs;
90
91 okay = FALSE;
92 entityID = 0;
93 itemID = 0;
94 itemtype = 0;
95 bvp = (BioseqViewPtr) GetObjectExtra (d);
96 if (bvp != NULL) {
97 if (! bvp->highlightSelections) return FALSE;
98 if (bvp->useScrollText) return FALSE;
99 GetItemParams (d, item, NULL, NULL, NULL, NULL, &dataPtr);
100 if (dataPtr != NULL) {
101 fsp = (FlatStructPtr) dataPtr;
102 paragraphs = fsp->paragraphs;
103 if (paragraphs != NULL) {
104 bbp = paragraphs [item - 1];
105 if (bbp != NULL) {
106 entityID = bbp->entityID;
107 itemID = bbp->itemID;
108 itemtype = bbp->itemtype;
109 okay = (Boolean) (entityID > 0 && itemID > 0 && itemtype > 0);
110 }
111 }
112 }
113 }
114 if (entityPtr != NULL) {
115 *entityPtr = entityID;
116 }
117 if (itemPtr != NULL) {
118 *itemPtr = itemID;
119 }
120 if (typePtr != NULL) {
121 *typePtr = itemtype;
122 }
123 return okay;
124 }
125
DrawIcon(DoC d,RectPtr r,Int2 item,Int2 firstLine)126 static void DrawIcon (DoC d, RectPtr r, Int2 item, Int2 firstLine)
127
128 {
129 BioseqViewPtr bvp;
130 Uint2 entityID;
131 Uint4 itemID;
132 Uint2 itemtype;
133 RecT rct;
134 SelStructPtr sel;
135
136 bvp = (BioseqViewPtr) GetObjectExtra (d);
137 if (bvp == NULL) return;
138 if (! bvp->highlightSelections) return;
139 if (GetIDsFromDoc (d, item, &entityID, &itemID, &itemtype)) {
140 for (sel = ObjMgrGetSelected (); sel != NULL; sel = sel->next) {
141 if (entityID == sel->entityID &&
142 itemID == sel->itemID &&
143 itemtype == sel->itemtype) {
144 rct = *r;
145 rct.right = rct.left + 4;
146 PaintRect (&rct);
147 }
148 }
149 }
150 }
151
FindFFPDocDescr(DocDescrPtr doscr,Int4 numdescr,Uint2 entityID,Uint2 itemID,Uint2 itemtype)152 static DocDescrPtr FindFFPDocDescr (DocDescrPtr doscr, Int4 numdescr,
153 Uint2 entityID, Uint2 itemID, Uint2 itemtype)
154
155 {
156 DocDescrPtr dsp;
157 Int4 L, R, mid;
158 DocDescrPtr rsult;
159
160 L = 0;
161 R = numdescr - 1;
162 while (L <= R) {
163 mid = (L + R) / 2;
164 dsp = &(doscr [mid]);
165 if (dsp == NULL) return NULL;
166 if (dsp->entityID > entityID) {
167 R = mid - 1;
168 } else if (dsp->entityID < entityID) {
169 L = mid + 1;
170 } else if (dsp->itemtype > itemtype) {
171 R = mid - 1;
172 } else if (dsp->itemtype < itemtype) {
173 L = mid + 1;
174 } else if (dsp->itemID > itemID) {
175 R = mid - 1;
176 } else if (dsp->itemID < itemID) {
177 L = mid + 1;
178 } else {
179 rsult = dsp;
180 /* scan to first paragraph for item */
181 while (mid >= 0) {
182 dsp = &(doscr [mid]);
183 if (dsp != NULL) {
184 if (dsp->entityID == entityID &&
185 dsp->itemtype == itemtype &&
186 dsp->itemID == itemID) {
187 rsult = dsp;
188 }
189 }
190 mid--;
191 }
192 return rsult;
193 }
194 }
195
196 return NULL;
197 }
198
OverlapgGeneIsPseudo(SeqFeatPtr sfp)199 static Boolean OverlapgGeneIsPseudo (SeqFeatPtr sfp)
200
201 {
202 SeqFeatPtr gene;
203 GeneRefPtr grp;
204
205 if (sfp == NULL)
206 return FALSE;
207 grp = SeqMgrGetGeneXref (sfp);
208 if (grp != NULL) {
209 if (grp->pseudo)
210 return TRUE;
211 return FALSE;
212 }
213 gene = SeqMgrGetOverlappingGene (sfp->location, NULL);
214 if (gene != NULL) {
215 if (gene->pseudo)
216 return TRUE;
217 grp = (GeneRefPtr) gene->data.value.ptrvalue;
218 if (grp != NULL) {
219 if (grp->pseudo)
220 return TRUE;
221 }
222 }
223 return FALSE;
224 }
225
226 static CharPtr bypass_cds_check [] = {
227 "RNA editing",
228 "reasons given in citation",
229 "artificial frameshift",
230 "rearrangement required for product",
231 "unclassified translation discrepancy",
232 "mismatches in translation",
233 "adjusted for low-quality genome",
234 NULL
235 };
236
CdsIsInvalid(SeqFeatPtr sfp)237 static Boolean CdsIsInvalid (SeqFeatPtr sfp)
238
239 {
240 ByteStorePtr bs;
241 BioseqPtr bsp;
242 Char ch;
243 CdRegionPtr crp;
244 Int2 i;
245 CharPtr ptr, str1, str2;
246
247 if (sfp->pseudo) return FALSE;
248 if (OverlapgGeneIsPseudo (sfp)) return FALSE;
249
250 crp = (CdRegionPtr) (sfp->data.value.ptrvalue);
251 if (crp != NULL && crp->conflict) return FALSE;
252
253 if (sfp->excpt && StringDoesHaveText (sfp->except_text)) {
254 for (i = 0; bypass_cds_check [i] != NULL; i++) {
255 if (StringISearch (sfp->except_text, bypass_cds_check [i]) != NULL) return FALSE;
256 }
257 }
258
259 bsp = BioseqFindFromSeqLoc (sfp->product);
260 str1 = GetSequenceByBsp (bsp);
261 if (str1 != NULL) {
262 ptr = str1;
263 ch = *ptr;
264 while (ch != '\0') {
265 if (ch == '-' || ch == '*') {
266 MemFree (str1);
267 return TRUE;
268 }
269 ptr++;
270 ch = *ptr;
271 }
272 }
273 bs = TransTableTranslateCdRegion (NULL, sfp, FALSE, FALSE, FALSE);
274 str2 = (CharPtr) BSMerge (bs, NULL);
275 BSFree (bs);
276
277 if (str1 != NULL && str2 != NULL && StringCmp (str1, str2) != 0) {
278 MemFree (str1);
279 MemFree (str2);
280 return TRUE;
281 }
282
283 MemFree (str1);
284 MemFree (str2);
285
286 return FALSE;
287 }
288
ColorIcon(DoC d,Int2 item,Int2 row,Int2 col)289 static Boolean ColorIcon (
290 DoC d,
291 Int2 item,
292 Int2 row,
293 Int2 col
294 )
295
296 {
297 SeqMgrFeatContext context;
298 Uint2 entityID;
299 FlatStructPtr fsp;
300 Uint4 itemID;
301 Uint2 itemtype;
302 SeqFeatPtr sfp;
303 Uint1 status;
304
305 fsp = (FlatStructPtr) GetDocData (d);
306 if (fsp == NULL) return FALSE;
307
308 status = fsp->cdsstatus [item - 1];
309 if (status == NOT_A_CDS) return FALSE;
310 if (status == CDS_OKAY) return FALSE;
311
312 if (status == CDS_UNTESTED) {
313 if (GetIDsFromDoc (d, item, &entityID, &itemID, &itemtype) && itemtype == OBJ_SEQFEAT) {
314 sfp = SeqMgrGetDesiredFeature (entityID, NULL, itemID, 0, NULL, &context);
315 if (sfp != NULL && sfp->idx.subtype == FEATDEF_CDS) {
316 if (CdsIsInvalid (sfp)) {
317 status = CDS_INVALID;
318 fsp->cdsstatus [item - 1] = status;
319 }
320 }
321 }
322 }
323
324 if (status == CDS_INVALID) {
325 Red ();
326 return TRUE;
327 }
328
329 fsp->cdsstatus [item - 1] = CDS_OKAY;
330 return FALSE;
331 }
332
ClickIcon(DoC d,PoinT pt)333 static void ClickIcon (DoC d, PoinT pt)
334
335 {
336 BioseqViewPtr bvp;
337
338 bvp = (BioseqViewPtr) GetObjectExtra (d);
339 if (bvp == NULL) return;
340 bvp->wasDoubleClick = dblClick;
341 bvp->wasShiftKey = shftKey;
342 MapDocPoint (d, pt, &(bvp->itemClicked), NULL, NULL, NULL);
343 }
344
345 typedef struct matchstruc {
346 CharPtr str;
347 Uint4 editItemID;
348 Boolean found;
349 Boolean slashgene;
350 Boolean slashproduct;
351 } MatchStruc, PNTR MatchStrucPtr;
352
FindStringCallBack(AsnExpOptStructPtr pAEOS)353 static void LIBCALLBACK FindStringCallBack (AsnExpOptStructPtr pAEOS)
354
355 {
356 MatchStrucPtr msp;
357 CharPtr pchSource;
358
359 if (pAEOS == NULL) return;
360 msp = (MatchStrucPtr) pAEOS->data;
361 if (msp == NULL) return;
362 if (! ISA_STRINGTYPE (AsnFindBaseIsa (pAEOS->atp))) return;
363 pchSource = (CharPtr) pAEOS->dvp->ptrvalue;
364 if (StringSearch (pchSource, msp->str) == NULL) return;
365 msp->found = TRUE;
366 }
367
CheckForStringInFeature(SeqFeatPtr sfp,MatchStrucPtr msp)368 static void CheckForStringInFeature (SeqFeatPtr sfp, MatchStrucPtr msp)
369
370 {
371 AsnExpOptPtr aeop;
372 AsnIoPtr aip;
373 SeqLocPtr location;
374 SeqLocPtr product;
375 ValNode vn;
376
377 if (sfp == NULL || msp == NULL) return;
378 msp->found = FALSE;
379 aip = AsnIoNullOpen ();
380 if (aip != NULL) {
381 aeop = AsnExpOptNew (aip, NULL, NULL, FindStringCallBack);
382 if (aeop != NULL) {
383 aeop->user_data = msp;
384 location = sfp->location;
385 product = sfp->product;
386 vn.choice = SEQLOC_NULL;
387 vn.data.ptrvalue = NULL;
388 sfp->location = &vn;
389 sfp->product = &vn;
390 SeqFeatAsnWrite (sfp, aip, NULL);
391 sfp->location = location;
392 sfp->product = product;
393 }
394 AsnIoClose (aip);
395 }
396 }
397
398 typedef struct protgenegatherlist {
399 SeqLocPtr slp;
400 Uint2 choice;
401 Int4 min;
402 Uint2 entityID;
403 Uint4 itemID;
404 Uint2 itemtype;
405 Boolean found;
406 } ProtGeneGatherList, PNTR ProtGeneGatherPtr;
407
ProtGeneMatchFunc(GatherContextPtr gcp)408 static Boolean ProtGeneMatchFunc (GatherContextPtr gcp)
409
410 {
411 Int4 diff;
412 ProtGeneGatherPtr pgp;
413 SeqFeatPtr sfp;
414
415 if (gcp == NULL) return TRUE;
416
417 pgp = (ProtGeneGatherPtr) gcp->userdata;
418 if (pgp == NULL) return TRUE;
419
420 if (gcp->thistype != OBJ_SEQFEAT) return TRUE;
421 sfp = (SeqFeatPtr) gcp->thisitem;
422 if (sfp == NULL || sfp->data.choice != pgp->choice ||
423 sfp->data.value.ptrvalue == NULL) return TRUE;
424 if (pgp->choice == SEQFEAT_PROT) {
425 diff = SeqLocAinB (sfp->location, pgp->slp);
426 } else {
427 diff = SeqLocAinB (pgp->slp, sfp->location);
428 }
429 if (diff < 0) return TRUE;
430 if (diff >= pgp->min) return TRUE;
431 pgp->min = diff;
432 pgp->entityID = gcp->entityID;
433 pgp->itemID = gcp->itemID;
434 pgp->itemtype = gcp->thistype;
435 pgp->found = TRUE;
436
437 return TRUE;
438 }
439
GetBestGeneOrProteinFeature(Uint2 entityID,SeqEntryPtr scope,SeqLocPtr location,Uint2 choice)440 static Uint2 GetBestGeneOrProteinFeature (Uint2 entityID, SeqEntryPtr scope,
441 SeqLocPtr location, Uint2 choice)
442
443 {
444 GatherScope gs;
445 ProtGeneGatherList pgl;
446
447 if (entityID == 0 || location == NULL) return 0;
448 pgl.entityID = 0;
449 pgl.itemID = 0;
450 pgl.itemtype = 0;
451 pgl.found = FALSE;
452 pgl.slp = location;
453 pgl.choice = choice;
454 pgl.min = INT4_MAX;
455 MemSet ((Pointer) (&gs), 0, sizeof (GatherScope));
456 gs.seglevels = 1;
457 gs.get_feats_location = FALSE;
458 gs.scope = scope;
459 MemSet((Pointer)(gs.ignore), (int)(TRUE), (size_t)(OBJ_MAX * sizeof(Boolean)));
460 gs.ignore[OBJ_BIOSEQ] = FALSE;
461 gs.ignore[OBJ_BIOSEQ_SEG] = FALSE;
462 gs.ignore[OBJ_SEQFEAT] = FALSE;
463 gs.ignore[OBJ_SEQANNOT] = FALSE;
464 GatherEntity (entityID, (Pointer) &pgl, ProtGeneMatchFunc, &gs);
465 return pgl.itemID;
466 }
467
MatchSubItemInFlatFileProc(GatherContextPtr gcp)468 static Boolean MatchSubItemInFlatFileProc (GatherContextPtr gcp)
469
470 {
471 MatchStrucPtr msp;
472 SeqFeatPtr sfp;
473
474 if (gcp == NULL || gcp->thisitem == NULL || gcp->thistype != OBJ_SEQFEAT) {
475 return FALSE;
476 }
477 msp = (MatchStrucPtr) gcp->userdata;
478 if (msp == NULL) return FALSE;
479 sfp = (SeqFeatPtr) gcp->thisitem;
480 CheckForStringInFeature (sfp, msp);
481 return FALSE;
482 }
483
MatchItemInFlatFileProc(GatherContextPtr gcp)484 static Boolean MatchItemInFlatFileProc (GatherContextPtr gcp)
485
486 {
487 Uint4 itemID;
488 MatchStrucPtr msp;
489 SeqFeatPtr sfp;
490
491 if (gcp == NULL || gcp->thisitem == NULL || gcp->thistype != OBJ_SEQFEAT) {
492 return FALSE;
493 }
494 msp = (MatchStrucPtr) gcp->userdata;
495 if (msp == NULL) return FALSE;
496 sfp = (SeqFeatPtr) gcp->thisitem;
497 /*
498 if (msp->slashgene) {
499 itemID = GetBestGeneOrProteinFeature (gcp->entityID, NULL, sfp->location, SEQFEAT_GENE);
500 if (itemID != 0) {
501 GatherItem (gcp->entityID, itemID, OBJ_SEQFEAT, (Pointer) msp, MatchSubItemInFlatFileProc);
502 if (msp->found) {
503 msp->editItemID = itemID;
504 return TRUE;
505 }
506 }
507 }
508 CheckForStringInFeature (sfp, msp);
509 if (msp->found) {
510 return TRUE;
511 }
512 */
513 if (sfp->data.choice == SEQFEAT_CDREGION) {
514 itemID = GetBestGeneOrProteinFeature (gcp->entityID, NULL, sfp->product, SEQFEAT_PROT);
515 if (itemID != 0) {
516 GatherItem (gcp->entityID, itemID, OBJ_SEQFEAT, (Pointer) msp, MatchSubItemInFlatFileProc);
517 if (msp->found) {
518 msp->editItemID = itemID;
519 return TRUE;
520 }
521 }
522 }
523 /*
524 if (! msp->slashgene) {
525 itemID = GetBestGeneOrProteinFeature (gcp->entityID, NULL, sfp->location, SEQFEAT_GENE);
526 if (itemID != 0) {
527 GatherItem (gcp->entityID, itemID, OBJ_SEQFEAT, (Pointer) msp, MatchSubItemInFlatFileProc);
528 if (msp->found) {
529 msp->editItemID = itemID;
530 return TRUE;
531 }
532 }
533 }
534 */
535 return FALSE;
536 }
537
MatchItemInFlatFile(Uint2 entityID,Uint4 itemID,CharPtr str,Boolean slashgene,Boolean slashproduct)538 static Uint2 MatchItemInFlatFile (Uint2 entityID, Uint4 itemID, CharPtr str,
539 Boolean slashgene, Boolean slashproduct)
540
541 {
542 MatchStruc ms;
543
544 ms.editItemID = itemID;
545 ms.str = str;
546 ms.slashgene = slashgene;
547 ms.slashproduct = slashproduct;
548 GatherItem (entityID, itemID, OBJ_SEQFEAT, (Pointer) &ms, MatchItemInFlatFileProc);
549 return ms.editItemID;
550 }
551
552 static CharPtr google_earth_1 =
553 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" \
554 "<kml xmlns=\"http://earth.google.com/kml/2.2\">\n" \
555 "<Document>\n" \
556 " <name>KmlFile</name>\n" \
557 " <StyleMap id=\"default_copy0+nicon=http://maps.google.com/mapfiles/kml/pal3/icon60.png+hicon=http://maps.google.com/mapfiles/kml/pal3/icon52.png\">\n" \
558 " <Pair>\n" \
559 " <key>normal</key>\n" \
560 " <styleUrl>#default_copy0+icon=http://maps.google.com/mapfiles/kml/pal3/icon60.png</styleUrl>\n" \
561 " </Pair>\n" \
562 " <Pair>\n" \
563 " <key>highlight</key>\n" \
564 " <styleUrl>#default_copy0+icon=http://maps.google.com/mapfiles/kml/pal3/icon52.png</styleUrl>\n" \
565 " </Pair>\n" \
566 " </StyleMap>\n" \
567 " <Style id=\"default_copy0+icon=http://maps.google.com/mapfiles/kml/pal3/icon60.png\">\n" \
568 " <IconStyle>\n" \
569 " <Icon>\n" \
570 " <href>http://maps.google.com/mapfiles/kml/pal3/icon60.png</href>\n" \
571 " </Icon>\n" \
572 " </IconStyle>\n" \
573 " </Style>\n" \
574 " <Placemark>\n";
575
576 static CharPtr google_earth_2 =
577 " <styleUrl>#default_copy0+nicon=http://maps.google.com/mapfiles/kml/pal3/icon60.png+hicon=http://maps.google.com/mapfiles/kml/pal3/icon52.png</styleUrl>\n" \
578 " <Point>\n";
579
580 static CharPtr google_earth_3 =
581 " </Point>\n" \
582 " </Placemark>\n" \
583 "</Document>\n" \
584 "</kml>\n";
585
ReleaseIcon(DoC d,PoinT pt)586 static void ReleaseIcon (DoC d, PoinT pt)
587
588 {
589 BioSourcePtr biop;
590 BioseqViewPtr bvp;
591 Char ch;
592 SeqMgrDescContext context;
593 CharPtr dst;
594 Uint4 editItemID;
595 Uint2 entityID;
596 Boolean format_ok = FALSE;
597 FILE *fp;
598 Int2 handled;
599 Int2 item;
600 Uint4 itemID;
601 Uint2 itemtype;
602 FloatHi lat = 0.0;
603 FloatHi lon = 0.0;
604 CharPtr lat_lon = NULL;
605 Boolean lat_in_range = FALSE;
606 Boolean lon_in_range = FALSE;
607 Char path [PATH_MAX];
608 Boolean precision_ok = FALSE;
609 Int2 row;
610 SeqDescPtr sdp;
611 SeqEntryPtr sep;
612 Boolean slashgene;
613 Boolean slashproduct;
614 CharPtr src;
615 SubSourcePtr ssp;
616 CharPtr str;
617 #ifdef OS_UNIX
618 Char cmmd [256];
619 #endif
620
621 bvp = (BioseqViewPtr) GetObjectExtra (d);
622 if (bvp == NULL) return;
623 MapDocPoint (d, pt, &item, &row, NULL, NULL);
624 if (row != 0 && item != 0 && item == bvp->itemClicked) {
625 if (GetIDsFromDoc (d, item, &entityID, &itemID, &itemtype)) {
626 if (bvp->wasDoubleClick) {
627
628 if (bvp->wasShiftKey) {
629 if (itemtype == OBJ_SEQDESC) {
630 sdp = SeqMgrGetDesiredDescriptor (entityID, NULL, itemID, 0, NULL, &context);
631 if (sdp != NULL && sdp->choice == Seq_descr_source) {
632 biop = (BioSourcePtr) sdp->data.ptrvalue;
633 if (biop != NULL) {
634 for (ssp = biop->subtype; ssp != NULL; ssp = ssp->next) {
635 if (ssp->subtype != SUBSRC_lat_lon) continue;
636 lat_lon = ssp->name;
637 if (StringHasNoText (lat_lon)) continue;
638 IsCorrectLatLonFormat (lat_lon, &format_ok, &precision_ok, &lat_in_range, &lon_in_range);
639 if (! format_ok) continue;
640 /*
641 if (! precision_ok) continue;
642 */
643 if (! lat_in_range) continue;
644 if (! lon_in_range) continue;
645 if (! ParseLatLon (lat_lon, &lat, &lon)) continue;
646 TmpNam (path);
647 /* write to original temp file, so next temp file name will not collide */
648 fp = FileOpen (path, "w");
649 if (fp != NULL) {
650 fprintf (fp, "\n");
651 FileClose (fp);
652 RememberSqnTempFile (path);
653 }
654 /* now append .kml extension so proper application is launched */
655 StringCat (path, ".kml");
656 fp = FileOpen (path, "w");
657 if (fp != NULL) {
658 fprintf (fp, "%s", google_earth_1);
659 fprintf (fp, " <name>%s</name>\n", lat_lon);
660 fprintf (fp, "%s", google_earth_2);
661 fprintf (fp, " <coordinates>%lf,%lf</coordinates>\n", (double) lon, (double) lat);
662 fprintf (fp, "%s", google_earth_3);
663 FileClose (fp);
664 RememberSqnTempFile (path);
665 #ifdef OS_UNIX
666 sprintf (cmmd, "open %s", path);
667 system (cmmd);
668 #endif
669 #ifdef WIN_MSWIN
670 Nlm_MSWin_OpenDocument (path);
671 #endif
672 }
673 return;
674 }
675 }
676 }
677 }
678 }
679
680 sep = GetTopSeqEntryForEntityID (entityID);
681 if (bvp->launchSubviewers) {
682 WatchCursor ();
683 Update ();
684 LaunchNewBioseqViewer (bvp->bsp, entityID, itemID, itemtype);
685 ArrowCursor ();
686 Update ();
687 return;
688 } else if (LaunchViewerNotEditor (bvp, sep, entityID, itemID, itemtype)) {
689 WatchCursor ();
690 Update ();
691 LaunchNewBioseqViewer (bvp->bsp, entityID, itemID, itemtype);
692 ArrowCursor ();
693 Update ();
694 return;
695 } else if (bvp->launchEditors) {
696 WatchCursor ();
697 Update ();
698 editItemID = itemID;
699 if (itemtype == OBJ_SEQFEAT && GetAppProperty ("InternalNcbiSequin") != NULL) {
700 str = GetDocText (d, item, row, 1);
701 TrimSpacesAroundString (str);
702 src = str;
703 dst = str;
704 ch = *src;
705 slashgene = FALSE;
706 slashproduct = FALSE;
707 if (str != NULL && str [0] == '/') {
708 if (StringStr (str, "/gene") != NULL) {
709 slashgene = TRUE;
710 }
711 if (StringStr (str, "/product") != NULL) {
712 slashproduct = TRUE;
713 }
714 while (ch != '=' && ch != '\0') {
715 src++;
716 ch = *src;
717 }
718 if (ch == '=') {
719 src++;
720 ch = *src;
721 }
722 }
723 while (ch != '\0') {
724 if (ch != '"') {
725 *dst = ch;
726 dst++;
727 }
728 src++;
729 ch = *src;
730 }
731 *dst = '\0';
732 editItemID = MatchItemInFlatFile (entityID, itemID, str, slashgene, slashproduct);
733 MemFree (str);
734 }
735 handled = GatherProcLaunch (OMPROC_EDIT, FALSE, entityID, editItemID,
736 itemtype, 0, 0, itemtype, 0);
737 ArrowCursor ();
738 Update ();
739 if (handled == OM_MSG_RET_DONE || handled == OM_MSG_RET_NOPROC) {
740 return;
741 }
742 } else {
743 return;
744 }
745 }
746 if (! bvp->sendSelectMessages) return;
747 if (bvp->wasShiftKey) {
748 ObjMgrAlsoSelect (entityID, itemID, itemtype,0,NULL);
749 } else {
750 ObjMgrSelect (entityID, itemID, itemtype,0,NULL);
751 }
752 }
753 } else if (item == bvp->itemClicked) {
754 if (! bvp->sendSelectMessages) return;
755 ObjMgrDeSelect (0, 0, 0,0,NULL);
756 }
757 }
758
DocFreeFlat(DoC d,VoidPtr data)759 static void DocFreeFlat (DoC d, VoidPtr data)
760
761 {
762 FlatStructPtr fsp;
763
764 if (data != NULL) {
765 fsp = (FlatStructPtr) data;
766 fsp->ajp = asn2gnbk_cleanup (fsp->ajp);
767 MemFree (fsp->descr);
768 MemFree (fsp->cdsstatus);
769 MemFree (fsp);
770 }
771 }
772
FFPrintFunc(DoC d,Int2 index,Pointer data)773 static CharPtr FFPrintFunc (DoC d, Int2 index, Pointer data)
774
775 {
776 BaseBlockPtr bbp;
777 BaseFormPtr bfp;
778 BioseqPtr bsp;
779 BioseqViewPtr bvp;
780 FlatStructPtr fsp;
781 ErrSev level;
782 SeqEntryPtr oldsep = NULL;
783 OMUserDataPtr omudp;
784 BaseBlockPtr PNTR paragraphs;
785 CharPtr str = NULL;
786 SeqEntryPtr topsep;
787
788 bvp = (BioseqViewPtr) GetObjectExtra (d);
789 fsp = (FlatStructPtr) data;
790 if (bvp == NULL || bvp->bsp == NULL || fsp == NULL) return StringSave ("?\n");
791 level = ErrSetMessageLevel (SEV_MAX);
792 bsp = BioseqLock (bvp->bsp);
793 bfp = (BaseFormPtr) GetObjectExtra (bvp->form);
794 if (bfp != NULL) {
795 topsep = GetTopSeqEntryForEntityID (bfp->input_entityID);
796 oldsep = SeqEntrySetScope (topsep);
797 }
798 str = asn2gnbk_format (fsp->ajp, (Int4) (index - 1));
799 if (oldsep != NULL) {
800 SeqEntrySetScope (oldsep);
801 }
802 if (bfp != NULL && bfp->userkey > 0) {
803 paragraphs = fsp->paragraphs;
804 if (paragraphs != NULL) {
805 bbp = paragraphs [index - 1];
806 if (bbp != NULL && bbp->entityID != 0 && bbp->entityID != bfp->input_entityID) {
807 if (! InBioseqViewEntityList (bbp->entityID, bvp)) {
808 ValNodeAddInt (&(bvp->entityList), 0, (Int4) bbp->entityID);
809 omudp = ObjMgrAddUserData (bbp->entityID, bfp->procid,
810 OMPROC_VIEW, bfp->userkey);
811 if (omudp != NULL) {
812 omudp->userdata.ptrvalue = (Pointer) bfp;
813 omudp->messagefunc = BioseqViewMsgFunc;
814 }
815 }
816 }
817 }
818 }
819 BioseqUnlock (bsp);
820 ErrSetMessageLevel (level);
821 return str;
822 }
823
SortDescrProc(VoidPtr vp1,VoidPtr vp2)824 static int LIBCALLBACK SortDescrProc (VoidPtr vp1, VoidPtr vp2)
825
826 {
827 DocDescrPtr descr1;
828 DocDescrPtr descr2;
829
830 descr1 = (DocDescrPtr) vp1;
831 descr2 = (DocDescrPtr) vp2;
832 if (descr1 == NULL || descr2 == NULL) return 0;
833
834 if (descr1->entityID > descr2->entityID) return 1;
835 if (descr1->entityID < descr2->entityID) return -1;
836
837 if (descr1->itemtype > descr2->itemtype) return 1;
838 if (descr1->itemtype < descr2->itemtype) return -1;
839
840 if (descr1->itemID > descr2->itemID) return 1;
841 if (descr1->itemID < descr2->itemID) return -1;
842
843 if (descr1->docitem > descr2->docitem) return 1;
844 if (descr1->docitem < descr2->docitem) return -1;
845
846 return 0;
847 }
848
849 typedef struct locallookforids {
850 Boolean isGED;
851 Boolean isNTorNWorNG;
852 Boolean isNC;
853 Boolean isTPA;
854 Boolean isAEorCH;
855 } LocalLookForIDs, PNTR LocalLookForIDsPtr;
856
LookForSeqIDs(BioseqPtr bsp,Pointer userdata)857 static void LookForSeqIDs (BioseqPtr bsp, Pointer userdata)
858
859 {
860 LocalLookForIDsPtr lfip;
861 SeqIdPtr sip;
862 TextSeqIdPtr tsip;
863
864 lfip = (LocalLookForIDsPtr) userdata;
865 for (sip = bsp->id; sip != NULL; sip = sip->next) {
866 switch (sip->choice) {
867 case SEQID_GENBANK :
868 case SEQID_EMBL :
869 case SEQID_DDBJ :
870 lfip->isGED = TRUE;
871 tsip = (TextSeqIdPtr) sip->data.ptrvalue;
872 if (tsip != NULL) {
873 if (StringNCmp (tsip->accession, "AE", 2) == 0) {
874 lfip->isAEorCH = TRUE;
875 } else if (StringNCmp (tsip->accession, "CH", 2) == 0) {
876 lfip->isAEorCH = TRUE;
877 }
878 }
879 break;
880 case SEQID_TPG :
881 case SEQID_TPE :
882 case SEQID_TPD :
883 lfip->isTPA = TRUE;
884 break;
885 case SEQID_OTHER :
886 tsip = (TextSeqIdPtr) sip->data.ptrvalue;
887 if (tsip != NULL) {
888 if (StringNCmp (tsip->accession, "NC_", 3) == 0) {
889 lfip->isNC = TRUE;
890 } else if (StringNCmp (tsip->accession, "NT_", 3) == 0) {
891 lfip->isNTorNWorNG = TRUE;
892 } else if (StringNCmp (tsip->accession, "NW_", 3) == 0) {
893 lfip->isNTorNWorNG = TRUE;
894 } else if (StringNCmp (tsip->accession, "NG_", 3) == 0) {
895 lfip->isNTorNWorNG = TRUE;
896 }
897 }
898 break;
899 default :
900 break;
901 }
902 }
903 }
904
LookForGEDetc(SeqEntryPtr topsep,BoolPtr isGED,BoolPtr isNTorNWorNG,BoolPtr isNC,BoolPtr isTPA,BoolPtr isAEorCH)905 static void LookForGEDetc (
906 SeqEntryPtr topsep,
907 BoolPtr isGED,
908 BoolPtr isNTorNWorNG,
909 BoolPtr isNC,
910 BoolPtr isTPA,
911 BoolPtr isAEorCH
912 )
913
914 {
915 LocalLookForIDs lfi;
916
917 MemSet (&lfi, 0, sizeof (LocalLookForIDs));
918 VisitBioseqsInSep (topsep, &lfi, LookForSeqIDs);
919 *isGED = lfi.isGED;
920 *isNTorNWorNG = lfi.isNTorNWorNG;
921 *isNC = lfi.isNC;
922 *isTPA = lfi.isTPA;
923 *isAEorCH = lfi.isAEorCH;
924 }
925
LookForNonLocalID(BioseqPtr bsp,Pointer userdata)926 static void LookForNonLocalID (BioseqPtr bsp, Pointer userdata)
927
928 {
929 BoolPtr isNonLocalPtr;
930 SeqIdPtr sip;
931
932 isNonLocalPtr = (BoolPtr) userdata;
933 for (sip = bsp->id; sip != NULL; sip = sip->next) {
934 switch (sip->choice) {
935 case SEQID_LOCAL :
936 break;
937 default :
938 *isNonLocalPtr = TRUE;
939 break;
940 }
941 }
942 }
943
LookForPubs(BioseqPtr bsp,Pointer userdata)944 static void LookForPubs (BioseqPtr bsp, Pointer userdata)
945
946 {
947 BoolPtr hasPub;
948
949 hasPub = (BoolPtr) userdata;
950 *hasPub = TRUE;
951 }
952
CheckVersionWithGi(BioseqPtr bsp,Pointer userdata)953 static void CheckVersionWithGi (BioseqPtr bsp, Pointer userdata)
954
955 {
956 Boolean hasGi = FALSE;
957 BoolPtr missingVersion;
958 SeqIdPtr sip;
959 TextSeqIdPtr tsip;
960 Boolean zeroVersion = FALSE;
961
962 for (sip = bsp->id; sip != NULL; sip = sip->next) {
963 switch (sip->choice) {
964 case SEQID_TPG:
965 case SEQID_TPE:
966 case SEQID_TPD:
967 case SEQID_GENBANK:
968 case SEQID_EMBL:
969 case SEQID_DDBJ:
970 tsip = (TextSeqIdPtr) sip->data.ptrvalue;
971 if (tsip != NULL && tsip->version == 0) {
972 zeroVersion = TRUE;
973 }
974 break;
975 case SEQID_GI :
976 hasGi = TRUE;
977 break;
978 default :
979 break;
980 }
981 }
982 if (hasGi && zeroVersion) {
983 missingVersion = (BoolPtr) userdata;
984 *missingVersion = TRUE;
985 }
986 }
987
988 static CharPtr relmodemsg1 = "Record cannot only have a local Seq-id for release mode";
989 static CharPtr relmodemsg2 = "Record must have a publication for release mode";
990 static CharPtr relmodemsg3 = "Record with gi must have version number for release mode";
991 static CharPtr relmodemsg4 = "Release mode failure";
992
RelModeFailText(BioseqPtr bsp,SeqEntryPtr usethetop,SeqEntryPtr topsep)993 static CharPtr RelModeFailText (
994 BioseqPtr bsp,
995 SeqEntryPtr usethetop,
996 SeqEntryPtr topsep
997 )
998
999 {
1000 SeqMgrDescContext dcontext;
1001 SeqMgrFeatContext fcontext;
1002 Boolean missingVersion;
1003 Boolean nonLocalID;
1004 Boolean hasPubs;
1005
1006 nonLocalID = FALSE;
1007 if (usethetop) {
1008 VisitBioseqsInSep (usethetop, (Pointer) &nonLocalID, LookForNonLocalID);
1009 } else {
1010 LookForNonLocalID (bsp, (Pointer) &nonLocalID);
1011 }
1012 if (! nonLocalID) {
1013 return StringSave (relmodemsg1);
1014 }
1015
1016 hasPubs = FALSE;
1017 if (usethetop) {
1018 if (VisitPubdescsInSep (usethetop, NULL, NULL) == 0) {
1019 return StringSave (relmodemsg2);
1020 }
1021 } else {
1022 if (SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_pub, &dcontext) == NULL) {
1023 if (SeqMgrGetNextFeature (bsp, NULL, SEQFEAT_PUB, 0, &fcontext) == NULL) {
1024 return StringSave (relmodemsg2);
1025 }
1026 }
1027 }
1028
1029 missingVersion = FALSE;
1030 VisitBioseqsInSep (topsep, (Pointer) &missingVersion, CheckVersionWithGi);
1031 if (missingVersion) {
1032 return StringSave (relmodemsg3);
1033 }
1034
1035 return StringSave (relmodemsg4);
1036 }
1037
1038 static Int2 asn2gb_line_estimate [30] = {
1039 0,
1040 1,
1041 1,
1042 1,
1043 1,
1044 1,
1045 1,
1046 1,
1047 1,
1048 1,
1049 1,
1050 1,
1051 1, /* source */
1052 2, /* organism */
1053 1, /* ref-stats */
1054 6, /* reference */
1055 4, /* primary */
1056 4, /* comment */
1057 1, /* feat-stats */
1058 1,
1059 4, /* source */
1060 6, /* feature */
1061 1,
1062 1,
1063 20, /* sequence */
1064 4, /* contig */
1065 1, /* wgs */
1066 1, /* genome */
1067 1, /* slash */
1068 1 /* tail */
1069 };
1070
PopulateFF(DoC d,SeqEntryPtr sep,BioseqPtr bsp,SeqEntryPtr usethetop,FmtType format,ModType mode,StlType style,FlgType flags,CstType custom)1071 static Boolean PopulateFF (
1072 DoC d,
1073 SeqEntryPtr sep,
1074 BioseqPtr bsp,
1075 SeqEntryPtr usethetop,
1076 FmtType format,
1077 ModType mode,
1078 StlType style,
1079 FlgType flags,
1080 CstType custom
1081 )
1082
1083 {
1084 Asn2gbJobPtr ajp;
1085 BaseBlockPtr bbp;
1086 BlockType blocktype;
1087 BioseqSetPtr bssp;
1088 BioseqViewPtr bvp;
1089 Uint1Ptr cdsstatus;
1090 DocDescrPtr doscr;
1091 DocDescrPtr doscrp;
1092 Int2 estimate;
1093 XtraBlock extra;
1094 FeatBlockPtr fbp;
1095 FonT fnt;
1096 FlatStructPtr fsp;
1097 Int4 index;
1098 ErrSev level;
1099 Boolean rsult;
1100
1101 rsult = FALSE;
1102 if (d != NULL && sep != NULL && bsp != NULL && spop != NULL) {
1103 fnt = programFont;
1104 bvp = (BioseqViewPtr) GetObjectExtra (d);
1105 if (bvp != NULL && bvp->displayFont != NULL) {
1106 fnt = bvp->displayFont;
1107 }
1108 fsp = MemNew (sizeof (FlatStruct));
1109 if (fsp != NULL) {
1110 fsp->sep = sep;
1111 SetDocData (d, (Pointer) fsp, DocFreeFlat);
1112 level = ErrSetMessageLevel (SEV_MAX);
1113 MemSet ((Pointer) &extra, 0, sizeof (XtraBlock));
1114 if (usethetop != NULL && IS_Bioseq_set (usethetop)) {
1115 bssp = (BioseqSetPtr) usethetop->data.ptrvalue;
1116 ajp = asn2gnbk_setup (NULL, bssp, NULL, format, mode, style, flags, 0, custom, &extra);
1117 } else {
1118 ajp = asn2gnbk_setup (bsp, NULL, NULL, format, mode, style, flags, 0, custom, &extra);
1119 }
1120 if (ajp == NULL) return FALSE;
1121 fsp->ajp = ajp;
1122 fsp->numParagraphs = ajp->numParagraphs;
1123 fsp->paragraphs = ajp->paragraphArray;
1124 if (fsp->numParagraphs > 0 && fsp->paragraphs != NULL) {
1125 fsp->numdescr = 0;
1126 for (index = 0; index < fsp->numParagraphs; index++) {
1127 estimate = 1;
1128 bbp = fsp->paragraphs [index];
1129 if (bbp != NULL) {
1130 blocktype = bbp->blocktype;
1131 if (blocktype >= HEAD_BLOCK && blocktype <= TAIL_BLOCK) {
1132 estimate = asn2gb_line_estimate [(int) blocktype];
1133 }
1134 }
1135 AppendItem (d, FFPrintFunc, (Pointer) fsp, FALSE,
1136 estimate, &ffParFmt, &ffColFmt, fnt);
1137 if (bbp != NULL) {
1138 (fsp->numdescr)++;
1139 }
1140 }
1141 doscrp = (DocDescrPtr) MemNew (sizeof (DocDescrStruct) * (size_t) (fsp->numdescr + 1));
1142 fsp->descr = doscrp;
1143 cdsstatus = (Uint1Ptr) MemNew (sizeof (Uint1) * (size_t) (fsp->numdescr + 1));
1144 fsp->cdsstatus = cdsstatus;
1145 fsp->numdescr = 0;
1146 if (doscrp != NULL && cdsstatus != NULL) {
1147 for (index = 0; index < fsp->numParagraphs; index++) {
1148 bbp = fsp->paragraphs [index];
1149 if (bbp != NULL) {
1150 doscr = &(doscrp [fsp->numdescr]);
1151 doscr->entityID = bbp->entityID;
1152 doscr->itemID = bbp->itemID;
1153 doscr->itemtype = bbp->itemtype;
1154 doscr->docitem = index + 1;
1155 if (bbp->blocktype == FEATURE_BLOCK) {
1156 fbp = (FeatBlockPtr) bbp;
1157 if (fbp->featdeftype == FEATDEF_CDS) {
1158 cdsstatus [index] = CDS_UNTESTED;
1159 }
1160 }
1161 (fsp->numdescr)++;
1162 }
1163 }
1164 }
1165 HeapSort (doscrp, (size_t) fsp->numdescr, sizeof (DocDescrStruct), SortDescrProc);
1166 rsult = TRUE;
1167 }
1168 ErrSetMessageLevel (level);
1169 }
1170 }
1171 return rsult;
1172 }
1173
LookForTpa(SeqDescrPtr sdp,Pointer userdata)1174 static void LookForTpa (
1175 SeqDescrPtr sdp,
1176 Pointer userdata
1177 )
1178
1179 {
1180 BoolPtr hastpaP;
1181 ObjectIdPtr oip;
1182 UserObjectPtr uop;
1183
1184 if (sdp == NULL || sdp->choice != Seq_descr_user) return;
1185 uop = (UserObjectPtr) sdp->data.ptrvalue;
1186 if (uop == NULL) return;
1187
1188 oip = uop->type;
1189 if (oip == NULL) return;
1190 if (StringCmp (oip->str, "TpaAssembly") != 0) return;
1191
1192 hastpaP = (BoolPtr) userdata;
1193 *hastpaP = TRUE;
1194 }
1195
LookForTsa(SeqDescrPtr sdp,Pointer userdata)1196 static void LookForTsa (
1197 SeqDescrPtr sdp,
1198 Pointer userdata
1199 )
1200
1201 {
1202 BoolPtr hastsaP;
1203 MolInfoPtr mip;
1204
1205 if (sdp == NULL || sdp->choice != Seq_descr_molinfo) return;
1206 mip = (MolInfoPtr) sdp->data.ptrvalue;
1207 if (mip == NULL) return;
1208
1209 if (mip->tech != MI_TECH_tsa) return;
1210
1211 hastsaP = (BoolPtr) userdata;
1212 *hastsaP = TRUE;
1213 }
1214
LookForFarBsp(BioseqPtr bsp,Pointer userdata)1215 static void LookForFarBsp (
1216 BioseqPtr bsp,
1217 Pointer userdata
1218 )
1219
1220 {
1221 BoolPtr doColorsP;
1222
1223 if (bsp == NULL) return;
1224 doColorsP = (BoolPtr) userdata;
1225 if (doColorsP == NULL) return;
1226
1227 if (bsp->repr == Seq_repr_seg && (! SegHasParts (bsp))) {
1228 *doColorsP = FALSE;
1229 } else if (bsp->repr == Seq_repr_delta && (! DeltaLitOnly (bsp))) {
1230 *doColorsP = FALSE;
1231 }
1232 }
1233
LookForFarProds(SeqFeatPtr sfp,Pointer userdata)1234 static void LookForFarProds (
1235 SeqFeatPtr sfp,
1236 Pointer userdata
1237 )
1238
1239 {
1240 BoolPtr doColorsP;
1241
1242 if (sfp == NULL) return;
1243 doColorsP = (BoolPtr) userdata;
1244 if (doColorsP == NULL) return;
1245
1246 if (sfp->idx.subtype != FEATDEF_CDS) return;
1247 if (sfp->product == NULL) return;
1248 if (BioseqFindFromSeqLoc (sfp->product) == NULL) {
1249 *doColorsP = FALSE;
1250 }
1251 }
1252
GbfLookFarFeatFetchPolicy(SeqDescrPtr sdp,Pointer userdata)1253 static void GbfLookFarFeatFetchPolicy (
1254 SeqDescrPtr sdp,
1255 Pointer userdata
1256 )
1257
1258 {
1259 BoolPtr forceOnlyNearFeatsP;
1260 ObjectIdPtr oip;
1261 UserFieldPtr ufp;
1262 UserObjectPtr uop;
1263
1264 if (sdp == NULL || sdp->choice != Seq_descr_user) return;
1265 forceOnlyNearFeatsP = (BoolPtr) userdata;
1266 if (forceOnlyNearFeatsP == NULL) return;
1267
1268 uop = (UserObjectPtr) sdp->data.ptrvalue;
1269 if (uop == NULL) return;
1270 oip = uop->type;
1271 if (oip == NULL) return;
1272 if (StringCmp (oip->str, "FeatureFetchPolicy") != 0) return;
1273
1274 for (ufp = uop->data; ufp != NULL; ufp = ufp->next) {
1275 oip = ufp->label;
1276 if (oip == NULL || ufp->data.ptrvalue == NULL) continue;
1277 if (StringCmp (oip->str, "Policy") == 0) {
1278 if (StringICmp ((CharPtr) ufp->data.ptrvalue, "OnlyNearFeatures") == 0) {
1279 *forceOnlyNearFeatsP = TRUE;
1280 }
1281 }
1282 }
1283 }
1284
PopulateFlatFile(BioseqViewPtr bvp,FmtType format,FlgType flags)1285 static void PopulateFlatFile (BioseqViewPtr bvp, FmtType format, FlgType flags)
1286
1287 {
1288 BioseqPtr bsp;
1289 SeqMgrFeatContext context;
1290 CstType custom = 0;
1291 DoC doc;
1292 Boolean doColors;
1293 Boolean doLockFarComponents = FALSE;
1294 Uint2 entityID;
1295 Int4 feats_with_product_count;
1296 FonT fnt;
1297 Boolean forceOnlyNearFeats = FALSE;
1298 FILE *fp;
1299 Boolean hastpaaligns;
1300 Boolean hastsaaligns;
1301 Int2 into;
1302 Boolean isAEorCH;
1303 Boolean isGED;
1304 Boolean isNTorNWorNG;
1305 Boolean isNC;
1306 Boolean isTPA;
1307 Int2 item;
1308 ErrSev level;
1309 Boolean lockFar = FALSE;
1310 Boolean lookupFar = FALSE;
1311 ModType mode = SEQUIN_MODE;
1312 SeqEntryPtr oldsep;
1313 Char path [PATH_MAX];
1314 BaR sb = NULL;
1315 SeqEntryPtr sep;
1316 SeqFeatPtr sfp;
1317 Int4 startsAt;
1318 CharPtr str;
1319 StlType style = NORMAL_STYLE;
1320 SeqViewProcsPtr svpp;
1321 SeqEntryPtr topsep;
1322 TexT txt;
1323 SeqEntryPtr usethetop = NULL;
1324 Int2 val;
1325
1326 if (bvp == NULL) return;
1327 if (bvp->hasTargetControl && bvp->ffModeCtrl != NULL) {
1328 val = GetValue (bvp->ffModeCtrl);
1329 switch (val) {
1330 case 1 :
1331 mode = RELEASE_MODE;
1332 break;
1333 case 2 :
1334 mode = ENTREZ_MODE;
1335 break;
1336 case 3 :
1337 mode = SEQUIN_MODE;
1338 break;
1339 case 4 :
1340 mode = DUMP_MODE;
1341 break;
1342 default :
1343 break;
1344 }
1345 }
1346 /* now using control instead of seqid type */
1347 if (bvp->ffStyleCtrl != NULL) {
1348 val = GetValue (bvp->ffStyleCtrl);
1349 switch (val) {
1350 case 1 :
1351 style = NORMAL_STYLE;
1352 lookupFar = TRUE;
1353 break;
1354 case 2 :
1355 style = SEGMENT_STYLE;
1356 lockFar = TRUE;
1357 break;
1358 case 3 :
1359 style = MASTER_STYLE;
1360 lockFar = TRUE;
1361 break;
1362 case 4 :
1363 style = CONTIG_STYLE;
1364 lookupFar = TRUE;
1365 break;
1366 default :
1367 break;
1368 }
1369 }
1370
1371 bsp = bvp->bsp;
1372 entityID = ObjMgrGetEntityIDForPointer (bsp);
1373 topsep = GetTopSeqEntryForEntityID (entityID);
1374 LookForGEDetc (topsep, &isGED, &isNTorNWorNG, &isNC, &isTPA, &isAEorCH);
1375 VisitDescriptorsInSep (topsep, (Pointer) &forceOnlyNearFeats, GbfLookFarFeatFetchPolicy);
1376
1377 if ((flags & SHOW_CONTIG_FEATURES) != 0 || (flags & SHOW_CONTIG_SOURCES) != 0) {
1378 if (isNTorNWorNG || isTPA) {
1379 lockFar = FALSE;
1380 lookupFar = TRUE;
1381 if (GetAppProperty ("InternalNcbiSequin") != NULL) {
1382 doLockFarComponents = TRUE;
1383 }
1384 } else {
1385 lockFar = TRUE;
1386 }
1387 }
1388 if (bvp->hasTargetControl && bvp->ffCustomBtn != NULL) {
1389 if (GetValue (bvp->ffCustomBtn) == 2) {
1390 flags |= REFSEQ_CONVENTIONS | SHOW_TRANCRIPTION | SHOW_PEPTIDE | FORCE_PRIMARY_BLOCK | RELAXED_MAPPING;
1391 }
1392 }
1393 if (bvp->hasTargetControl && bvp->ffRifCtrl != NULL) {
1394 val = GetValue (bvp->ffRifCtrl);
1395 switch (val) {
1396 case 1 :
1397 break;
1398 case 2 :
1399 custom |= HIDE_GENE_RIFS;
1400 break;
1401 case 3 :
1402 custom |= ONLY_GENE_RIFS;
1403 break;
1404 case 4 :
1405 custom |= NEWEST_PUBS;
1406 break;
1407 case 5 :
1408 custom |= OLDEST_PUBS;
1409 break;
1410 case 6 :
1411 custom |= ONLY_REVIEW_PUBS;
1412 break;
1413 case 7 :
1414 custom |= HIDE_ALL_PUBS;
1415 break;
1416 default :
1417 break;
1418 }
1419 }
1420 doc = NULL;
1421 txt = NULL;
1422 bsp = bvp->bsp;
1423 if (bvp->useScrollText) {
1424 txt = bvp->text;
1425 Reset (txt);
1426 Update ();
1427 } else {
1428 doc = bvp->doc;
1429 GetScrlParams (doc, NULL, &item, &into);
1430 sb = GetSlateVScrollBar ((SlatE) doc);
1431 Reset (doc);
1432 SetDocShade (doc, NULL, NULL, NULL, NULL);
1433 SetDocProcs (doc, NULL, NULL, NULL, NULL);
1434 SetDocCache (doc, NULL, NULL, NULL);
1435 Update ();
1436 SetDocAutoAdjust (doc, FALSE);
1437 }
1438 if (bsp == NULL) return;
1439 if (spop == NULL) {
1440 spop = StdPrintOptionsNew (NULL);
1441 if (spop != NULL) {
1442 spop->newline = "\r";
1443 spop->indent = "";
1444 } else {
1445 Message (MSG_ERROR, "StdPrintOptionsNew failed");
1446 }
1447 }
1448
1449 svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
1450 if (svpp != NULL) {
1451 if (svpp->lockFarComponents) {
1452 doLockFarComponents = TRUE;
1453 }
1454 }
1455
1456 if (mode == ENTREZ_MODE) {
1457 doLockFarComponents = FALSE;
1458 lockFar = FALSE;
1459 lookupFar = FALSE;
1460 flags = flags ^ (SHOW_CONTIG_FEATURES | SHOW_CONTIG_SOURCES | SHOW_FAR_TRANSLATION);
1461 }
1462
1463 if (doLockFarComponents) {
1464 entityID = ObjMgrGetEntityIDForPointer (bsp);
1465 sep = GetTopSeqEntryForEntityID (entityID);
1466 if (bvp->bsplist == NULL && lockFar) {
1467 bvp->bsplist = LockFarComponentsEx (sep, TRUE, FALSE, FALSE, NULL);
1468 }
1469 if (lookupFar) {
1470 feats_with_product_count = 0;
1471 sfp = SeqMgrGetNextFeature (bsp, NULL, 0, 0, &context);
1472 while (sfp != NULL) {
1473 if (sfp->product != NULL) {
1474 feats_with_product_count++;
1475 }
1476 sfp = SeqMgrGetNextFeature (bsp, sfp, 0, 0, &context);
1477 }
1478 if (feats_with_product_count > 500) {
1479 /* too many to lookup with older caching implementation - now sufficiently fast */
1480 /*
1481 lookupFar = FALSE;
1482 */
1483 }
1484 }
1485 if (lookupFar) {
1486 hastpaaligns = FALSE;
1487 hastsaaligns = FALSE;
1488 VisitDescriptorsInSep (sep, (Pointer) &hastpaaligns, LookForTpa);
1489 VisitDescriptorsInSep (sep, (Pointer) &hastsaaligns, LookForTsa);
1490 LookupFarSeqIDs (sep, TRUE, TRUE, TRUE, FALSE, hastpaaligns || hastsaaligns, FALSE, TRUE);
1491 }
1492 }
1493
1494 sep = SeqMgrGetSeqEntryForData (bsp);
1495 entityID = ObjMgrGetEntityIDForChoice (sep);
1496 if (bvp->hasTargetControl) {
1497 if (bvp->viewWholeEntity) {
1498 sep = GetTopSeqEntryForEntityID (entityID);
1499 usethetop = sep;
1500 if (format == FTABLE_FMT) {
1501 custom |= SHOW_PROT_FTABLE;
1502 }
1503 } else if (ISA_na (bsp->mol) && bsp->repr == Seq_repr_seg) {
1504 sep = GetBestTopParentForData (entityID, bsp);
1505 } else if (ISA_aa (bsp->mol) && bsp->repr == Seq_repr_seg) {
1506 sep = GetBestTopParentForData (entityID, bsp);
1507 }
1508 } else {
1509 if (ISA_na (bsp->mol) || bsp->repr == Seq_repr_seg) {
1510 sep = GetBestTopParentForData (entityID, bsp);
1511 }
1512 }
1513 if (sep == NULL) return;
1514
1515 topsep = GetTopSeqEntryForEntityID (entityID);
1516 oldsep = SeqEntrySetScope (topsep);
1517
1518 WatchCursor ();
1519 ffColFmt.pixWidth = screenRect.right - screenRect.left;
1520 ffColFmt.pixInset = 8;
1521 /* LookForGEDetc (topsep, &isGED, &isNTorNWorNG, &isNC, &isTPA); */
1522 if ((flags & SHOW_CONTIG_FEATURES) != 0 || (flags & SHOW_CONTIG_SOURCES) != 0) {
1523 if (forceOnlyNearFeats) {
1524 flags |= ONLY_NEAR_FEATURES;
1525 } else if (isNTorNWorNG || isTPA) {
1526 flags |= ONLY_NEAR_FEATURES;
1527 } else if (isNC) {
1528 flags |= NEAR_FEATURES_SUPPRESS;
1529 } else if (isAEorCH) {
1530 flags |= NEAR_FEATURES_SUPPRESS;
1531 }
1532 }
1533 if (bvp->useScrollText) {
1534 TmpNam (path);
1535 fp = FileOpen (path, "w");
1536 if (fp != NULL) {
1537 level = ErrSetMessageLevel (SEV_MAX);
1538 if (SeqEntryToGnbk (sep, NULL, format, mode, style, flags, 0, custom, NULL, fp)) {
1539 FileClose (fp);
1540 if (! FileToScrollText (txt, path)) {
1541 SetTitle (txt, "(Text is too large to be displayed in this control.)");
1542 }
1543 } else if (mode == RELEASE_MODE) {
1544 str = RelModeFailText (bsp, usethetop, topsep);
1545 if (str != NULL) {
1546 fprintf (fp, "%s", str);
1547 }
1548 FileClose (fp);
1549 if (str != NULL) {
1550 FileToScrollText (txt, path);
1551 }
1552 MemFree (str);
1553 } else {
1554 FileClose (fp);
1555 }
1556 ErrSetMessageLevel (level);
1557 }
1558 FileRemove (path);
1559 } else {
1560 if (PopulateFF (doc, sep, bsp, usethetop, format, mode, style, flags, custom)) {
1561 doColors = TRUE;
1562 /*
1563 VisitBioseqsInSep (topsep, (Pointer) &doColors, LookForFarBsp);
1564 if (doColors) {
1565 VisitFeaturesInSep (topsep, (Pointer) &doColors, LookForFarProds);
1566 }
1567 if (doColors) {
1568 SetDocShade (doc, DrawIcon, NULL, NULL, ColorIcon);
1569 } else {
1570 SetDocShade (doc, DrawIcon, NULL, NULL, NULL);
1571 }
1572 */
1573 SetDocShade (doc, DrawIcon, NULL, NULL, NULL);
1574 SetDocProcs (doc, ClickIcon, NULL, ReleaseIcon, NULL);
1575 SetDocCache (doc, StdPutDocCache, StdGetDocCache, StdResetDocCache);
1576 SetDocAutoAdjust (doc, FALSE);
1577 ForceFormat (doc, item);
1578 SetDocAutoAdjust (doc, TRUE);
1579 AdjustDocScroll (doc);
1580 GetItemParams4 (doc, item, &startsAt, NULL, NULL, NULL, NULL);
1581 CorrectBarValue (sb, startsAt + into);
1582 UpdateDocument (doc, 0, 0);
1583 } else if (mode == RELEASE_MODE) {
1584 str = RelModeFailText (bsp, usethetop, topsep);
1585 if (str != NULL) {
1586 fnt = programFont;
1587 if (bvp != NULL && bvp->displayFont != NULL) {
1588 fnt = bvp->displayFont;
1589 }
1590 AppendText (doc, str, &ffParFmt, &ffColFmt, fnt);
1591 }
1592 MemFree (str);
1593 UpdateDocument (doc, 0, 0);
1594 }
1595 }
1596
1597 SeqEntrySetScope (oldsep);
1598
1599 ArrowCursor ();
1600 Update ();
1601 }
1602
PopulateGenBank(BioseqViewPtr bvp)1603 static void PopulateGenBank (BioseqViewPtr bvp)
1604
1605 {
1606 PopulateFlatFile (bvp, GENBANK_FMT, SHOW_CONTIG_FEATURES | SHOW_CONTIG_SOURCES | SHOW_FAR_TRANSLATION);
1607 }
1608
PopulateEMBL(BioseqViewPtr bvp)1609 static void PopulateEMBL (BioseqViewPtr bvp)
1610
1611 {
1612 if (bvp == NULL) return;
1613 if (bvp->hasTargetControl) {
1614 PopulateFlatFile (bvp, EMBL_FMT, 0);
1615 } else {
1616 PopulateFlatFile (bvp, EMBL_FMT, 0);
1617 }
1618 }
1619
PopulateDDBJ(BioseqViewPtr bvp)1620 static void PopulateDDBJ (BioseqViewPtr bvp)
1621
1622 {
1623 PopulateFlatFile (bvp, GENBANK_FMT, DDBJ_VARIANT_FORMAT);
1624 }
1625
PopulateGenPept(BioseqViewPtr bvp)1626 static void PopulateGenPept (BioseqViewPtr bvp)
1627
1628 {
1629 PopulateFlatFile (bvp, GENPEPT_FMT, 0);
1630 }
1631
PopulateFTable(BioseqViewPtr bvp)1632 static void PopulateFTable (BioseqViewPtr bvp)
1633
1634 {
1635 PopulateFlatFile (bvp, FTABLE_FMT, 0);
1636 }
1637
PopulateFasta(BioseqViewPtr bvp)1638 static void PopulateFasta (BioseqViewPtr bvp)
1639
1640 {
1641 BioseqPtr bsp;
1642 DoC doc;
1643 Uint2 entityID;
1644 Boolean fastaOK;
1645 Boolean fastaNucOK;
1646 Boolean fastaPrtOK;
1647 FonT fnt;
1648 FILE *fp;
1649 Uint1 group_segs;
1650 Int2 into = 0;
1651 Int2 item = 0;
1652 Boolean master_style;
1653 Char path [PATH_MAX];
1654 BaR sb = NULL;
1655 SeqEntryPtr sep;
1656 Int4 startsAt = 0;
1657 SeqViewProcsPtr svpp;
1658 TexT txt;
1659
1660 if (bvp == NULL) return;
1661 doc = NULL;
1662 txt = NULL;
1663 bsp = bvp->bsp;
1664 if (bvp->useScrollText) {
1665 txt = bvp->text;
1666 Reset (txt);
1667 Update ();
1668 } else {
1669 doc = bvp->doc;
1670 GetScrlParams (doc, NULL, &item, &into);
1671 sb = GetSlateVScrollBar ((SlatE) doc);
1672 Reset (doc);
1673 SetDocShade (doc, NULL, NULL, NULL, NULL);
1674 SetDocProcs (doc, NULL, NULL, NULL, NULL);
1675 SetDocCache (doc, NULL, NULL, NULL);
1676 Update ();
1677 SetDocAutoAdjust (doc, FALSE);
1678 }
1679 if (bsp == NULL) return;
1680
1681 svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
1682 if (svpp != NULL && svpp->lockFarComponents) {
1683 entityID = ObjMgrGetEntityIDForPointer (bsp);
1684 sep = GetTopSeqEntryForEntityID (entityID);
1685 if (bvp->bsplist == NULL) {
1686 bvp->bsplist = LockFarComponentsEx (sep, TRUE, FALSE, FALSE, NULL);
1687 }
1688 }
1689
1690 sep = SeqMgrGetSeqEntryForData (bsp);
1691 if (bvp->hasTargetControl) {
1692 if (bvp->viewWholeEntity) {
1693 entityID = ObjMgrGetEntityIDForChoice (sep);
1694 sep = GetTopSeqEntryForEntityID (entityID);
1695 }
1696 } else {
1697 if (ISA_na (bsp->mol) || bsp->repr == Seq_repr_seg) {
1698 entityID = ObjMgrGetEntityIDForChoice (sep);
1699 sep = GetBestTopParentForData (entityID, bsp);
1700 }
1701 }
1702 if (sep == NULL) return;
1703
1704 WatchCursor ();
1705 ffColFmt.pixWidth = screenRect.right - screenRect.left;
1706 ffColFmt.pixInset = 8;
1707 TmpNam (path);
1708 fp = FileOpen (path, "w");
1709 if (fp != NULL) {
1710 fnt = programFont;
1711 if (bvp != NULL && bvp->displayFont != NULL) {
1712 fnt = bvp->displayFont;
1713 }
1714 fastaOK = FALSE;
1715 fastaNucOK = FALSE;
1716 fastaPrtOK = FALSE;
1717 if (ISA_na (bsp->mol)) {TRUE,
1718 group_segs = 0;
1719 master_style = FALSE;
1720 if (bvp->hasTargetControl) {
1721 if (bvp->viewWholeEntity) {
1722 if (bsp->repr == Seq_repr_seg) {
1723 group_segs = 2;
1724 }
1725 /*
1726 fastaNucOK = SeqEntrysToFasta (sep, fp, TRUE, group_segs);
1727 fastaPrtOK = SeqEntrysToFasta (sep, fp, FALSE, 0);
1728 */
1729 if (SeqEntryFastaStream (sep, fp, STREAM_EXPAND_GAPS | STREAM_CORRECT_INVAL,
1730 70, 0, 0, TRUE, FALSE, master_style) > 0)
1731 {
1732 fastaNucOK = TRUE;
1733 }
1734 else
1735 {
1736 fastaNucOK = FALSE;
1737 }
1738 if (SeqEntryFastaStream (sep, fp, STREAM_EXPAND_GAPS | STREAM_CORRECT_INVAL,
1739 70, 0, 0, FALSE, TRUE, master_style) > 0)
1740 {
1741 fastaPrtOK = TRUE;
1742 }
1743 else
1744 {
1745 fastaPrtOK = FALSE;
1746 }
1747 fastaOK = fastaNucOK || fastaPrtOK;
1748 } else {
1749 if (bsp->repr == Seq_repr_seg) {
1750 group_segs = 1;
1751 master_style = TRUE;
1752 } else if (bsp->repr == Seq_repr_delta) {
1753 group_segs = 3;
1754 }
1755 /*
1756 fastaOK = SeqEntrysToFasta (sep, fp, TRUE, group_segs);
1757 */
1758 if (SeqEntryFastaStream (sep, fp, STREAM_EXPAND_GAPS | STREAM_CORRECT_INVAL,
1759 70, 0, 0, TRUE, FALSE, master_style) > 0)
1760 {
1761 fastaOK = TRUE;
1762 }
1763 else
1764 {
1765 fastaOK = FALSE;
1766 }
1767 }
1768 } else {
1769 if (bsp->repr == Seq_repr_seg) {
1770 group_segs = 1;
1771 master_style = TRUE;
1772 } else if (bsp->repr == Seq_repr_delta) {
1773 group_segs = 3;
1774 }
1775 /*
1776 fastaOK = SeqEntrysToFasta (sep, fp, TRUE, group_segs);
1777 */
1778 if (SeqEntryFastaStream (sep, fp, STREAM_EXPAND_GAPS | STREAM_CORRECT_INVAL,
1779 70, 0, 0, TRUE, FALSE, master_style) > 0)
1780 {
1781 fastaOK = TRUE;
1782 }
1783 else
1784 {
1785 fastaOK = FALSE;
1786 }
1787 }
1788 } else if (ISA_aa (bsp->mol)) {
1789 /*
1790 fastaOK = SeqEntrysToFasta (sep, fp, FALSE, 0);
1791 */
1792 if (SeqEntryFastaStream (sep, fp, STREAM_EXPAND_GAPS | STREAM_CORRECT_INVAL,
1793 70, 0, 0, FALSE, TRUE, FALSE) > 0)
1794 {
1795 fastaOK = TRUE;
1796 }
1797 else
1798 {
1799 fastaOK = FALSE;
1800 }
1801 }
1802 if (fastaOK) {
1803 FileClose (fp);
1804 if (bvp->useScrollText) {
1805 if (! FileToScrollText (txt, path)) {
1806 SetTitle (txt, "(Text is too large to be displayed in this control.)");
1807 }
1808 } else {
1809 DisplayFancy (doc, path, &ffParFmt, &ffColFmt, fnt, 4);
1810 SetDocCache (doc, StdPutDocCache, StdGetDocCache, StdResetDocCache);
1811 SetDocAutoAdjust (doc, FALSE);
1812 ForceFormat (doc, item);
1813 SetDocAutoAdjust (doc, TRUE);
1814 AdjustDocScroll (doc);
1815 GetItemParams4 (doc, item, &startsAt, NULL, NULL, NULL, NULL);
1816 CorrectBarValue (sb, startsAt + into);
1817 UpdateDocument (doc, 0, 0);
1818 }
1819 } else {
1820 FileClose (fp);
1821 }
1822 }
1823 FileRemove (path);
1824 ArrowCursor ();
1825 Update ();
1826 }
1827
PrintQualProc(CharPtr buf,Uint4 buflen,Pointer userdata)1828 static void PrintQualProc (CharPtr buf, Uint4 buflen, Pointer userdata)
1829
1830 {
1831 FILE *fp;
1832
1833 fp = (FILE*) userdata;
1834 fprintf (fp, "%s", buf);
1835 }
1836
PrintQualScoresProc(SeqEntryPtr sep,Pointer mydata,Int4 index,Int2 indent)1837 static void PrintQualScoresProc (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
1838
1839 {
1840 BioseqPtr bsp;
1841 FILE *fp;
1842
1843 if (! IS_Bioseq (sep)) return;
1844 bsp = (BioseqPtr) sep->data.ptrvalue;
1845 if (bsp == NULL) return;
1846 fp = (FILE*) mydata;
1847 PrintQualityScoresToBuffer (bsp, FALSE, fp, PrintQualProc);
1848 }
1849
PrintFarQualScoresProc(SeqEntryPtr sep,Pointer mydata,Int4 index,Int2 indent)1850 static void PrintFarQualScoresProc (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
1851
1852 {
1853 BioseqPtr bsp;
1854 FILE *fp;
1855
1856 if (! IS_Bioseq (sep)) return;
1857 bsp = (BioseqPtr) sep->data.ptrvalue;
1858 if (bsp == NULL) return;
1859 fp = (FILE*) mydata;
1860 PrintQualityScoresForContig (bsp, FALSE, fp);
1861 }
1862
PopulateQuality(BioseqViewPtr bvp)1863 static void PopulateQuality (BioseqViewPtr bvp)
1864
1865 {
1866 BioseqPtr bsp;
1867 DoC doc;
1868 Uint2 entityID;
1869 FonT fnt;
1870 FILE *fp;
1871 Int2 into;
1872 Int2 item = 0;
1873 Char path [PATH_MAX];
1874 BaR sb = NULL;
1875 SeqEntryPtr sep;
1876 Int4 startsAt;
1877 TexT txt;
1878
1879 if (bvp == NULL) return;
1880 doc = NULL;
1881 txt = NULL;
1882 bsp = bvp->bsp;
1883 if (bvp->useScrollText) {
1884 txt = bvp->text;
1885 Reset (txt);
1886 Update ();
1887 } else {
1888 doc = bvp->doc;
1889 GetScrlParams (doc, NULL, &item, &into);
1890 sb = GetSlateVScrollBar ((SlatE) doc);
1891 Reset (doc);
1892 SetDocShade (doc, NULL, NULL, NULL, NULL);
1893 SetDocProcs (doc, NULL, NULL, NULL, NULL);
1894 SetDocCache (doc, NULL, NULL, NULL);
1895 Update ();
1896 SetDocAutoAdjust (doc, FALSE);
1897 }
1898 if (bsp == NULL) return;
1899 sep = SeqMgrGetSeqEntryForData (bsp);
1900 if (bvp->hasTargetControl) {
1901 if (bvp->viewWholeEntity) {
1902 entityID = ObjMgrGetEntityIDForChoice (sep);
1903 sep = GetTopSeqEntryForEntityID (entityID);
1904 }
1905 } else {
1906 if (ISA_na (bsp->mol) || bsp->repr == Seq_repr_seg) {
1907 entityID = ObjMgrGetEntityIDForChoice (sep);
1908 sep = GetBestTopParentForData (entityID, bsp);
1909 }
1910 }
1911 if (sep == NULL) return;
1912
1913 WatchCursor ();
1914 ffColFmt.pixWidth = screenRect.right - screenRect.left;
1915 ffColFmt.pixInset = 8;
1916 TmpNam (path);
1917 fp = FileOpen (path, "w");
1918 if (fp != NULL) {
1919 fnt = programFont;
1920 if (bvp != NULL && bvp->displayFont != NULL) {
1921 fnt = bvp->displayFont;
1922 }
1923 if (VisitGraphsInSep (sep, NULL, NULL) > 0) {
1924 SeqEntryExplore (sep, (Pointer) fp, PrintQualScoresProc);
1925 } else if (bsp->repr == Seq_repr_delta) {
1926 SeqEntryExplore (sep, (Pointer) fp, PrintFarQualScoresProc);
1927 } else {
1928 SeqEntryExplore (sep, (Pointer) fp, PrintQualScoresProc);
1929 }
1930 FileClose (fp);
1931 if (bvp->useScrollText) {
1932 if (! FileToScrollText (txt, path)) {
1933 SetTitle (txt, "(Text is too large to be displayed in this control.)");
1934 }
1935 } else {
1936 DisplayFancy (doc, path, &ffParFmt, &ffColFmt, fnt, 4);
1937 SetDocCache (doc, StdPutDocCache, StdGetDocCache, StdResetDocCache);
1938 SetDocAutoAdjust (doc, FALSE);
1939 ForceFormat (doc, item);
1940 SetDocAutoAdjust (doc, TRUE);
1941 AdjustDocScroll (doc);
1942 GetItemParams4 (doc, item, &startsAt, NULL, NULL, NULL, NULL);
1943 CorrectBarValue (sb, startsAt + into);
1944 UpdateDocument (doc, 0, 0);
1945 }
1946 }
1947 FileRemove (path);
1948 ArrowCursor ();
1949 Update ();
1950 }
1951
1952 NLM_EXTERN void AsnPrintNewLine PROTO((AsnIoPtr aip));
1953
PopulateAsnOrXML(BioseqViewPtr bvp,CharPtr outmode,Boolean doGbseq)1954 static void PopulateAsnOrXML (BioseqViewPtr bvp, CharPtr outmode, Boolean doGbseq)
1955
1956 {
1957 AsnIoPtr aipout = NULL;
1958 AsnTypePtr atp = NULL;
1959 BioseqPtr bsp;
1960 CstType custom = 0;
1961 DoC doc;
1962 Uint2 entityID;
1963 XtraPtr extra = NULL;
1964 FlgType flags = CREATE_XML_GBSEQ_FILE;
1965 FonT fnt;
1966 FmtType format = GENBANK_FMT;
1967 GBSeq gbsq;
1968 GBSet gbst;
1969 Int2 into = 0;
1970 Int2 item = 0;
1971 Boolean lockFar = FALSE;
1972 Boolean lookupFar = FALSE;
1973 ModType mode = SEQUIN_MODE;
1974 Char path [PATH_MAX];
1975 BaR sb = NULL;
1976 SeqEntryPtr sep;
1977 Int4 startsAt = 0;
1978 StlType style = NORMAL_STYLE;
1979 TexT txt;
1980 Int2 val;
1981 Char xmlbuf [128];
1982 XtraBlock xtra;
1983
1984 if (bvp == NULL) return;
1985 doc = NULL;
1986 txt = NULL;
1987 bsp = bvp->bsp;
1988 if (bvp->useScrollText) {
1989 txt = bvp->text;
1990 Reset (txt);
1991 Update ();
1992 } else {
1993 doc = bvp->doc;
1994 GetScrlParams (doc, NULL, &item, &into);
1995 sb = GetSlateVScrollBar ((SlatE) doc);
1996 Reset (doc);
1997 SetDocShade (doc, NULL, NULL, NULL, NULL);
1998 SetDocProcs (doc, NULL, NULL, NULL, NULL);
1999 SetDocCache (doc, NULL, NULL, NULL);
2000 Update ();
2001 SetDocAutoAdjust (doc, FALSE);
2002 }
2003 if (bsp == NULL) return;
2004 sep = SeqMgrGetSeqEntryForData (bsp);
2005 if (bvp->hasTargetControl) {
2006 if (bvp->viewWholeEntity) {
2007 entityID = ObjMgrGetEntityIDForChoice (sep);
2008 sep = GetTopSeqEntryForEntityID (entityID);
2009 }
2010 } else {
2011 if (ISA_na (bsp->mol) || bsp->repr == Seq_repr_seg) {
2012 entityID = ObjMgrGetEntityIDForChoice (sep);
2013 sep = GetBestTopParentForData (entityID, bsp);
2014 }
2015 }
2016 if (sep == NULL) return;
2017
2018 WatchCursor ();
2019 ffColFmt.pixWidth = screenRect.right - screenRect.left;
2020 ffColFmt.pixInset = 8;
2021 TmpNam (path);
2022 aipout = AsnIoOpen (path, outmode);
2023 fnt = programFont;
2024 if (bvp != NULL && bvp->displayFont != NULL) {
2025 fnt = bvp->displayFont;
2026 }
2027 if (bsp != NULL && ISA_aa (bsp->mol)) {
2028 format = GENPEPT_FMT;
2029 }
2030 if (doGbseq && aipout != NULL) {
2031 if (bvp->hasTargetControl && bvp->ffModeCtrl != NULL) {
2032 val = GetValue (bvp->ffModeCtrl);
2033 switch (val) {
2034 case 1 :
2035 mode = RELEASE_MODE;
2036 break;
2037 case 2 :
2038 mode = ENTREZ_MODE;
2039 break;
2040 case 3 :
2041 mode = SEQUIN_MODE;
2042 break;
2043 case 4 :
2044 mode = DUMP_MODE;
2045 break;
2046 default :
2047 break;
2048 }
2049 }
2050 /* now using control instead of seqid type */
2051 if (bvp->ffStyleCtrl != NULL) {
2052 val = GetValue (bvp->ffStyleCtrl);
2053 switch (val) {
2054 case 1 :
2055 style = NORMAL_STYLE;
2056 lookupFar = TRUE;
2057 break;
2058 case 2 :
2059 style = SEGMENT_STYLE;
2060 lockFar = TRUE;
2061 break;
2062 case 3 :
2063 style = MASTER_STYLE;
2064 lockFar = TRUE;
2065 break;
2066 case 4 :
2067 style = CONTIG_STYLE;
2068 lookupFar = TRUE;
2069 break;
2070 default :
2071 break;
2072 }
2073 }
2074 if (bvp->hasTargetControl && bvp->ffCustomBtn != NULL) {
2075 if (GetValue (bvp->ffCustomBtn) == 2) {
2076 flags = REFSEQ_CONVENTIONS | SHOW_TRANCRIPTION | SHOW_PEPTIDE | FORCE_PRIMARY_BLOCK | RELAXED_MAPPING;
2077 }
2078 }
2079 if (bvp->hasTargetControl && bvp->ffRifCtrl != NULL) {
2080 val = GetValue (bvp->ffRifCtrl);
2081 switch (val) {
2082 case 1 :
2083 break;
2084 case 2 :
2085 custom |= HIDE_GENE_RIFS;
2086 break;
2087 case 3 :
2088 custom |= ONLY_GENE_RIFS;
2089 break;
2090 case 4 :
2091 custom |= NEWEST_PUBS;
2092 break;
2093 case 5 :
2094 custom |= OLDEST_PUBS;
2095 break;
2096 case 6 :
2097 custom |= ONLY_REVIEW_PUBS;
2098 break;
2099 case 7 :
2100 custom |= HIDE_ALL_PUBS;
2101 break;
2102 default :
2103 break;
2104 }
2105 }
2106 if (GetAppParam ("NCBI", "SETTINGS", "XMLPREFIX", NULL, xmlbuf, sizeof (xmlbuf))) {
2107 AsnSetXMLmodulePrefix (StringSave (xmlbuf));
2108 }
2109 objgbseqAsnLoad ();
2110 objinsdseqAsnLoad ();
2111 MemSet ((Pointer) &xtra, 0, sizeof (XtraBlock));
2112 MemSet ((Pointer) &gbsq, 0, sizeof (GBSeq));
2113 xtra.gbseq = &gbsq;
2114 xtra.aip = aipout;
2115 /*
2116 atp = AsnLinkType (NULL, AsnFind ("GBSet"));
2117 xtra.atp = AsnLinkType (NULL, AsnFind ("GBSet.E"));
2118 */
2119 atp = AsnLinkType (NULL, AsnFind ("INSDSet"));
2120 xtra.atp = AsnLinkType (NULL, AsnFind ("INSDSet.E"));
2121 extra = &xtra;
2122 MemSet ((Pointer) &gbst, 0, sizeof (GBSet));
2123 AsnOpenStruct (aipout, atp, (Pointer) &gbst);
2124 if (SeqEntryToGnbk (sep, NULL, format, mode, style, flags, 0, custom, extra, NULL)) {
2125 AsnCloseStruct (aipout, atp, NULL);
2126 AsnPrintNewLine (aipout);
2127 AsnIoClose (aipout);
2128 if (bvp->useScrollText) {
2129 if (! FileToScrollText (txt, path)) {
2130 SetTitle (txt, "(Text is too large to be displayed in this control.)");
2131 }
2132 } else {
2133 DisplayFancy (doc, path, &ffParFmt, &ffColFmt, fnt, 4);
2134 SetDocCache (doc, StdPutDocCache, StdGetDocCache, StdResetDocCache);
2135 SetDocAutoAdjust (doc, FALSE);
2136 ForceFormat (doc, item);
2137 SetDocAutoAdjust (doc, TRUE);
2138 AdjustDocScroll (doc);
2139 GetItemParams4 (doc, item, &startsAt, NULL, NULL, NULL, NULL);
2140 CorrectBarValue (sb, startsAt + into);
2141 UpdateDocument (doc, 0, 0);
2142 }
2143 } else {
2144 AsnIoClose (aipout);
2145 }
2146 } else if (aipout != NULL) {
2147 if (SeqEntryAsnWrite (sep, aipout, NULL)) {
2148 AsnIoClose (aipout);
2149 if (bvp->useScrollText) {
2150 if (! FileToScrollText (txt, path)) {
2151 SetTitle (txt, "(Text is too large to be displayed in this control.)");
2152 }
2153 } else {
2154 DisplayFancy (doc, path, &ffParFmt, &ffColFmt, fnt, 4);
2155 SetDocCache (doc, StdPutDocCache, StdGetDocCache, StdResetDocCache);
2156 SetDocAutoAdjust (doc, FALSE);
2157 ForceFormat (doc, item);
2158 SetDocAutoAdjust (doc, TRUE);
2159 AdjustDocScroll (doc);
2160 GetItemParams4 (doc, item, &startsAt, NULL, NULL, NULL, NULL);
2161 CorrectBarValue (sb, startsAt + into);
2162 UpdateDocument (doc, 0, 0);
2163 }
2164 } else {
2165 AsnIoClose (aipout);
2166 }
2167 }
2168 FileRemove (path);
2169 ArrowCursor ();
2170 Update ();
2171 }
2172
PopulateXML(BioseqViewPtr bvp)2173 static void PopulateXML (BioseqViewPtr bvp)
2174
2175 {
2176 PopulateAsnOrXML (bvp, "wx", FALSE);
2177 }
2178
PopulateAsn(BioseqViewPtr bvp)2179 static void PopulateAsn (BioseqViewPtr bvp)
2180
2181 {
2182 PopulateAsnOrXML (bvp, "w", FALSE);
2183 }
2184
PopulateGBSeq(BioseqViewPtr bvp)2185 static void PopulateGBSeq (BioseqViewPtr bvp)
2186
2187 {
2188 PopulateAsnOrXML (bvp, "wx", TRUE);
2189 }
2190
ShowFlatFile(BioseqViewPtr bvp,Boolean show)2191 static void ShowFlatFile (BioseqViewPtr bvp, Boolean show)
2192
2193 {
2194 if (bvp == NULL) return;
2195 if (show) {
2196 if (bvp->useScrollText) {
2197 SafeShow (bvp->text);
2198 } else {
2199 SafeShow (bvp->doc);
2200 }
2201 SafeShow (bvp->baseCtgControlGrp);
2202 SafeShow (bvp->modeControlGrp);
2203 SafeShow (bvp->extraControlGrp);
2204 SafeShow (bvp->docTxtControlGrp);
2205 SafeShow (bvp->clickMe);
2206 } else {
2207 SafeHide (bvp->text);
2208 SafeHide (bvp->doc);
2209 Reset (bvp->text);
2210 Reset (bvp->doc);
2211 SetDocShade (bvp->doc, NULL, NULL, NULL, NULL);
2212 SetDocProcs (bvp->doc, NULL, NULL, NULL, NULL);
2213 SetDocCache (bvp->doc, NULL, NULL, NULL);
2214 SafeHide (bvp->styleControlGrp);
2215 SafeHide (bvp->scaleControlGrp);
2216 EnableDisableLegendItem (bvp, FALSE);
2217 SafeHide (bvp->findGeneGrp);
2218 SafeHide (bvp->docTxtControlGrp);
2219 SafeHide (bvp->baseCtgControlGrp);
2220 SafeHide (bvp->modeControlGrp);
2221 SafeHide (bvp->extraControlGrp);
2222 SafeHide (bvp->newGphControlGrp);
2223 SafeHide (bvp->clickMe);
2224 }
2225 }
2226
ShowFastaOrAsn(BioseqViewPtr bvp,Boolean show)2227 static void ShowFastaOrAsn (BioseqViewPtr bvp, Boolean show)
2228
2229 {
2230 if (bvp == NULL) return;
2231 if (show) {
2232 if (bvp->useScrollText) {
2233 SafeShow (bvp->text);
2234 } else {
2235 SafeShow (bvp->doc);
2236 }
2237 SafeHide (bvp->modeControlGrp);
2238 SafeHide (bvp->baseCtgControlGrp);
2239 SafeHide (bvp->extraControlGrp);
2240 SafeShow (bvp->docTxtControlGrp);
2241 SafeHide (bvp->clickMe);
2242 } else {
2243 SafeHide (bvp->text);
2244 SafeHide (bvp->doc);
2245 Reset (bvp->text);
2246 Reset (bvp->doc);
2247 SetDocShade (bvp->doc, NULL, NULL, NULL, NULL);
2248 SetDocProcs (bvp->doc, NULL, NULL, NULL, NULL);
2249 SetDocCache (bvp->doc, NULL, NULL, NULL);
2250 SafeHide (bvp->styleControlGrp);
2251 SafeHide (bvp->scaleControlGrp);
2252 EnableDisableLegendItem (bvp, FALSE);
2253 SafeHide (bvp->findGeneGrp);
2254 SafeHide (bvp->docTxtControlGrp);
2255 SafeHide (bvp->baseCtgControlGrp);
2256 SafeHide (bvp->modeControlGrp);
2257 SafeHide (bvp->extraControlGrp);
2258 SafeHide (bvp->newGphControlGrp);
2259 SafeHide (bvp->clickMe);
2260 }
2261 }
2262
ShowGBSeq(BioseqViewPtr bvp,Boolean show)2263 static void ShowGBSeq (BioseqViewPtr bvp, Boolean show)
2264
2265 {
2266 if (bvp == NULL) return;
2267 if (show) {
2268 if (bvp->useScrollText) {
2269 SafeShow (bvp->text);
2270 } else {
2271 SafeShow (bvp->doc);
2272 }
2273 SafeShow (bvp->modeControlGrp);
2274 SafeShow (bvp->baseCtgControlGrp);
2275 SafeShow (bvp->extraControlGrp);
2276 SafeShow (bvp->docTxtControlGrp);
2277 SafeHide (bvp->clickMe);
2278 } else {
2279 SafeHide (bvp->text);
2280 SafeHide (bvp->doc);
2281 Reset (bvp->text);
2282 Reset (bvp->doc);
2283 SetDocShade (bvp->doc, NULL, NULL, NULL, NULL);
2284 SetDocProcs (bvp->doc, NULL, NULL, NULL, NULL);
2285 SetDocCache (bvp->doc, NULL, NULL, NULL);
2286 SafeHide (bvp->styleControlGrp);
2287 SafeHide (bvp->scaleControlGrp);
2288 EnableDisableLegendItem (bvp, FALSE);
2289 SafeHide (bvp->findGeneGrp);
2290 SafeHide (bvp->docTxtControlGrp);
2291 SafeHide (bvp->baseCtgControlGrp);
2292 SafeHide (bvp->modeControlGrp);
2293 SafeHide (bvp->extraControlGrp);
2294 SafeHide (bvp->newGphControlGrp);
2295 SafeHide (bvp->clickMe);
2296 }
2297 }
2298
SelectFlatFile(BioseqViewPtr bvp,Uint2 selentityID,Uint4 selitemID,Uint2 selitemtype,SeqLocPtr region,Boolean select,Boolean scrollto)2299 static void SelectFlatFile (BioseqViewPtr bvp, Uint2 selentityID, Uint4 selitemID,
2300 Uint2 selitemtype, SeqLocPtr region,
2301 Boolean select, Boolean scrollto)
2302
2303 {
2304 Int2 bottom = 0;
2305 DoC doc;
2306 DocDescrPtr dsp;
2307 FlatStructPtr fsp;
2308 Uint2 entityID;
2309 Uint4 itemID;
2310 Uint2 itemtype;
2311 Int2 item;
2312 Boolean needToScroll;
2313 Int2 numItems;
2314 RecT rct;
2315 BaR sb;
2316 Int2 scrollhere;
2317 Int4 startsAt;
2318 WindoW tempPort;
2319 CharPtr text;
2320 Int2 top = 0;
2321
2322 if (bvp == NULL) return;
2323 if (! bvp->highlightSelections) return;
2324 if (bvp->useScrollText) return;
2325 doc = bvp->doc;
2326 if (doc == NULL) return;
2327 tempPort = SavePort (doc);
2328 Select (doc);
2329 GetDocParams (doc, &numItems, NULL);
2330 needToScroll = TRUE;
2331 scrollhere = 0;
2332 fsp = (FlatStructPtr) GetDocData (doc);
2333 if (fsp != NULL && fsp->descr != NULL && fsp->numdescr > 0) {
2334 if (GetScrlParams (doc, NULL, &item, NULL)) {
2335 while (item <= numItems && ItemIsVisible (doc, item, &top, &bottom, NULL)) {
2336 if (GetIDsFromDoc (doc, item, &entityID, &itemID, &itemtype)) {
2337 if (entityID == selentityID &&
2338 itemID == selitemID &&
2339 itemtype == selitemtype) {
2340 needToScroll = FALSE;
2341 ObjectRect (doc, &rct);
2342 InsetRect (&rct, 4, 4);
2343 rct.right = rct.left + 4;
2344 rct.top = top;
2345 rct.bottom = bottom;
2346 InsetRect (&rct, -1, -1);
2347 InvalRect (&rct);
2348 }
2349 }
2350 item++;
2351 }
2352 }
2353 dsp = FindFFPDocDescr (fsp->descr, fsp->numdescr,
2354 selentityID, selitemID, selitemtype);
2355 scrollhere = 0;
2356 if (dsp != NULL) {
2357 scrollhere = dsp->docitem;
2358 }
2359 if (scrollhere > 0) {
2360 if (ItemIsVisible (doc, scrollhere, &top, &bottom, NULL)) {
2361 needToScroll = FALSE;
2362 }
2363 ObjectRect (doc, &rct);
2364 InsetRect (&rct, 4, 4);
2365 rct.right = rct.left + 4;
2366 rct.top = top;
2367 rct.bottom = bottom;
2368 InsetRect (&rct, -1, -1);
2369 InvalRect (&rct);
2370 } else if (selitemtype == OBJ_BIOSEQ) { /* not preindexed in fsp descr */
2371 ObjectRect (doc, &rct);
2372 InsetRect (&rct, 4, 4);
2373 rct.right = rct.left + 4;
2374 rct.top = top;
2375 rct.bottom = bottom;
2376 InsetRect (&rct, -1, -1);
2377 InvalRect (&rct);
2378 }
2379 }
2380 /* for items currently not preindexed (LOCUS, ORGANISM), do a short linear search */
2381 if (/* scrollhere == 0 && */ selitemID > 0 /* && needToScroll */) {
2382 for (item = 1; item <= numItems && item < 10; item++) {
2383 if (GetIDsFromDoc (doc, item, &entityID, &itemID, &itemtype)) {
2384 if (entityID == selentityID &&
2385 itemID == selitemID &&
2386 itemtype == selitemtype) {
2387 /*
2388 if (ItemIsVisible (doc, item, &top, &bottom, NULL)) {
2389 needToScroll = FALSE;
2390 ObjectRect (doc, &rct);
2391 InsetRect (&rct, 4, 4);
2392 rct.right = rct.left + 4;
2393 rct.top = top;
2394 rct.bottom = bottom;
2395 InsetRect (&rct, -1, -1);
2396 InvalRect (&rct);
2397 } else if (scrollhere == 0) {
2398 scrollhere = item;
2399 }
2400 */
2401 if (needToScroll) {
2402 scrollhere = item;
2403 item = 10; /* break the for loop */
2404 }
2405 }
2406 }
2407 }
2408 }
2409 if (scrollto && needToScroll && scrollhere > 0 && selitemtype != OBJ_BIOSEQ) {
2410 text = GetDocText (doc, scrollhere, 0, 1); /* forces format if not before */
2411 MemFree (text);
2412 ForceFormat (doc, scrollhere); /* forces UpdateLineStarts */
2413 GetItemParams4 (doc, scrollhere, &startsAt, NULL, NULL, NULL, NULL);
2414 sb = GetSlateVScrollBar ((SlatE) doc);
2415 CorrectBarValue (sb, startsAt);
2416 ObjectRect (doc, &rct);
2417 InsetRect (&rct, 4, 4);
2418 InsetRect (&rct, -1, -1);
2419 InvalRect (&rct);
2420 }
2421 RestorePort (tempPort);
2422 }
2423
CopyFlatFileFastaOrAsn(BioseqViewPtr bvp)2424 static void CopyFlatFileFastaOrAsn (BioseqViewPtr bvp)
2425
2426 {
2427 FILE *fp;
2428 Char path [PATH_MAX];
2429
2430 if (bvp == NULL) return;
2431 if (bvp->useScrollText) {
2432 if (bvp->text != NULL) {
2433 CopyText (bvp->text);
2434 }
2435 } else {
2436 TmpNam (path);
2437 fp = FileOpen (path, "w");
2438 if (fp != NULL) {
2439 SaveDocument (bvp->doc, fp);
2440 FileClose (fp);
2441 FileToClipboard (path);
2442 }
2443 FileRemove (path);
2444 }
2445 }
2446
2447 #ifdef WIN_MOTIF
2448 extern CharPtr Nlm_XrmGetResource (const Char PNTR _resource);
2449 #endif
2450
PrintFlatFileFastaOrAsn(BioseqViewPtr bvp)2451 static void PrintFlatFileFastaOrAsn (BioseqViewPtr bvp)
2452
2453 {
2454 DoC doc;
2455 TexT txt;
2456 #ifdef WIN_MOTIF
2457 Char cmmd [256];
2458 Int2 len;
2459 CharPtr printCmd;
2460 Char str [PATH_MAX];
2461 #endif
2462
2463 if (bvp == NULL) return;
2464 if (bvp->bsp == NULL) return;
2465 doc = NULL;
2466 txt = NULL;
2467 if (bvp->useScrollText) {
2468 txt = bvp->text;
2469 } else {
2470 doc = bvp->doc;
2471 }
2472 if (doc != NULL) {
2473 PrintDocument (doc);
2474 } else if (txt != NULL) {
2475 #ifdef WIN_MOTIF
2476 TmpNam (str);
2477 ScrollTextToFile (txt, str);
2478 printCmd = Nlm_XrmGetResource ("printCommand");
2479 if (printCmd != NULL) {
2480 StringNCpy_0 (cmmd, printCmd, sizeof (cmmd) - 1);
2481 } else {
2482 StringCpy (cmmd, "lp -c");
2483 }
2484 MemFree (printCmd);
2485 len = (Int2) StringLen (cmmd);
2486 while (len > 0 && cmmd [len] == ' ') {
2487 cmmd [len] = '\0';
2488 len--;
2489 }
2490 StringCat (cmmd, " ");
2491 StringCat (cmmd, str);
2492 StringCat (cmmd, "; rm ");
2493 StringCat (cmmd, str);
2494 system (cmmd);
2495 /*
2496 FileRemove (str);
2497 */
2498 #endif
2499 }
2500 }
2501
ExportFlatFileFastaOrAsnEx(BioseqViewPtr bvp,CharPtr filename,CharPtr dfault,Boolean specialSave)2502 static void ExportFlatFileFastaOrAsnEx (BioseqViewPtr bvp, CharPtr filename, CharPtr dfault, Boolean specialSave)
2503
2504 {
2505 Char ch;
2506 Char dfaultFile [32];
2507 DoC doc;
2508 FILE *f;
2509 Int2 i;
2510 Int2 j;
2511 Int2 k;
2512 Int2 numItems;
2513 Char path [PATH_MAX];
2514 CharPtr str;
2515 TexT txt;
2516
2517 if (bvp == NULL) return;
2518 if (bvp->bsp == NULL) return;
2519 doc = NULL;
2520 txt = NULL;
2521 if (bvp->useScrollText) {
2522 txt = bvp->text;
2523 } else {
2524 doc = bvp->doc;
2525 }
2526 if (doc != NULL || txt != NULL) {
2527 dfault [0] = '\0';
2528 StringNCpy_0 (dfaultFile, dfault, sizeof (dfaultFile));
2529 j = 0;
2530 k = 0;
2531 ch = dfaultFile [j];
2532 while (j < sizeof (dfaultFile) && ch != '\0') {
2533 if (ch <= ' ') {
2534 j++;
2535 } else {
2536 dfaultFile [k] = dfaultFile [j];
2537 k++;
2538 j++;
2539 }
2540 ch = dfaultFile [j];
2541 }
2542 dfaultFile [k] = '\0';
2543 #ifdef WIN_MSWIN
2544 j = 0;
2545 ch = dfaultFile [j];
2546 while (j < sizeof (dfaultFile) && ch != '\0') {
2547 if (ch == '_' || IS_ALPHANUM (ch)) {
2548 j++;
2549 ch = dfaultFile [j];
2550 } else {
2551 ch = '\0';
2552 }
2553 }
2554 dfaultFile [j] = '\0';
2555 #endif
2556 path [0] = '\0';
2557 StringNCpy_0 (path, filename, sizeof (path));
2558 if (path [0] != '\0' || GetOutputFileName (path, sizeof (path), dfaultFile)) {
2559 WatchCursor ();
2560 #ifdef WIN_MAC
2561 f = FileOpen (path, "r");
2562 if (f != NULL) {
2563 FileClose (f);
2564 } else {
2565 FileCreate (path, "TEXT", "ttxt");
2566 }
2567 #endif
2568 if (filename == NULL || filename [0] == '\0') {
2569 f = FileOpen (path, "w");
2570 } else {
2571 f = FileOpen (path, "a");
2572 }
2573 if (f != NULL) {
2574 if (bvp->useScrollText) {
2575 ScrollTextToFile (txt, path);
2576 } else if (specialSave) {
2577 GetDocParams (doc, &numItems, NULL);
2578 for (i = 1; i <= numItems; i++) {
2579 str = GetDocText (doc, i, 0, 0);
2580 if (! StringHasNoText (str)) {
2581 fprintf (f, "%s", str);
2582 }
2583 MemFree (str);
2584 }
2585 } else {
2586 SaveDocument (doc, f);
2587 }
2588 FileClose (f);
2589 }
2590 ArrowCursor ();
2591 }
2592 }
2593 }
2594
ExportFlatFileFastaOrAsn(BioseqViewPtr bvp,CharPtr filename,CharPtr dfault)2595 static void ExportFlatFileFastaOrAsn (BioseqViewPtr bvp, CharPtr filename, CharPtr dfault)
2596
2597 {
2598 ExportFlatFileFastaOrAsnEx (bvp, filename, dfault, FALSE);
2599 }
2600
ExportFeatureTable(BioseqViewPtr bvp,CharPtr filename,CharPtr dfault)2601 static void ExportFeatureTable (BioseqViewPtr bvp, CharPtr filename, CharPtr dfault)
2602
2603 {
2604 ExportFlatFileFastaOrAsnEx (bvp, filename, dfault, TRUE);
2605 }
2606
2607 static CharPtr asnconfirmmsg =
2608 "'Export' saves only the targeted portion of the record.\n\
2609 Use 'Save' to save the entire record to a file, so that\n\
2610 it can be submitted to the database. Proceed with export?";
2611
ExportAsnAfterConfirming(BioseqViewPtr bvp,CharPtr filename,CharPtr dfault)2612 static void ExportAsnAfterConfirming (BioseqViewPtr bvp, CharPtr filename, CharPtr dfault)
2613
2614 {
2615 MsgAnswer ans;
2616
2617 if (bvp->hasTargetControl) {
2618 ans = Message (MSG_YN, "%s", asnconfirmmsg);
2619 if (ans == ANS_NO) return;
2620 }
2621 ExportFlatFileFastaOrAsn (bvp, filename, dfault);
2622 }
2623
ResizeFlatFileFastaOrAsn(BioseqViewPtr bvp)2624 static void ResizeFlatFileFastaOrAsn (BioseqViewPtr bvp)
2625
2626 {
2627 if (bvp == NULL) return;
2628 if (bvp->doc != NULL) {
2629 if (Visible (bvp->doc) && AllParentsVisible (bvp->doc)) {
2630 UpdateDocument (bvp->doc, 0, 0);
2631 }
2632 }
2633 }
2634
2635 BioseqPageData gbgnPageData = {
2636 "GenBank", FALSE, FALSE, TRUE, FALSE, -1,
2637 PopulateGenBank, ShowFlatFile, SelectFlatFile,
2638 CopyFlatFileFastaOrAsn, PrintFlatFileFastaOrAsn,
2639 ExportFlatFileFastaOrAsn, NULL, ResizeFlatFileFastaOrAsn, NULL
2640 };
2641
2642 BioseqPageData gnbkPageData = {
2643 "GenBank", TRUE, FALSE, FALSE, FALSE, -1,
2644 PopulateGenBank, ShowFlatFile, SelectFlatFile,
2645 CopyFlatFileFastaOrAsn, PrintFlatFileFastaOrAsn,
2646 ExportFlatFileFastaOrAsn, NULL, ResizeFlatFileFastaOrAsn, NULL
2647 };
2648
2649 BioseqPageData emblPageData = {
2650 "EMBL", TRUE, FALSE, FALSE, FALSE, -1,
2651 PopulateEMBL, ShowFlatFile, SelectFlatFile,
2652 CopyFlatFileFastaOrAsn, PrintFlatFileFastaOrAsn,
2653 ExportFlatFileFastaOrAsn, NULL, ResizeFlatFileFastaOrAsn, NULL
2654 };
2655
2656 BioseqPageData ddbjPageData = {
2657 "DDBJ", TRUE, FALSE, FALSE, FALSE, -1,
2658 PopulateDDBJ, ShowFlatFile, SelectFlatFile,
2659 CopyFlatFileFastaOrAsn, PrintFlatFileFastaOrAsn,
2660 ExportFlatFileFastaOrAsn, NULL, ResizeFlatFileFastaOrAsn, NULL
2661 };
2662
2663 BioseqPageData gnptPageData = {
2664 "GenPept", FALSE, TRUE, FALSE, FALSE, -1,
2665 PopulateGenPept, ShowFlatFile, SelectFlatFile,
2666 CopyFlatFileFastaOrAsn, PrintFlatFileFastaOrAsn,
2667 ExportFlatFileFastaOrAsn, NULL, ResizeFlatFileFastaOrAsn, NULL
2668 };
2669
2670 BioseqPageData ftblPageData = {
2671 "Table", TRUE, TRUE, TRUE, FALSE, -1,
2672 PopulateFTable, ShowFlatFile, SelectFlatFile,
2673 CopyFlatFileFastaOrAsn, PrintFlatFileFastaOrAsn,
2674 ExportFeatureTable, NULL, ResizeFlatFileFastaOrAsn, NULL
2675 };
2676
2677 BioseqPageData fstaPageData = {
2678 "FASTA", TRUE, TRUE, TRUE, FALSE, -1,
2679 PopulateFasta, ShowFastaOrAsn, NULL,
2680 CopyFlatFileFastaOrAsn, PrintFlatFileFastaOrAsn,
2681 ExportFlatFileFastaOrAsn, NULL, ResizeFlatFileFastaOrAsn, NULL
2682 };
2683
2684 BioseqPageData qualPageData = {
2685 "Quality", TRUE, TRUE, FALSE, FALSE, -1,
2686 PopulateQuality, ShowFastaOrAsn, NULL,
2687 CopyFlatFileFastaOrAsn, PrintFlatFileFastaOrAsn,
2688 ExportFlatFileFastaOrAsn, NULL, ResizeFlatFileFastaOrAsn, NULL
2689 };
2690
2691 BioseqPageData asnPageData = {
2692 "ASN.1", TRUE, TRUE, TRUE, FALSE, -1,
2693 PopulateAsn, ShowFastaOrAsn, NULL,
2694 CopyFlatFileFastaOrAsn, PrintFlatFileFastaOrAsn,
2695 ExportAsnAfterConfirming, NULL, ResizeFlatFileFastaOrAsn, NULL
2696 };
2697
2698 BioseqPageData xmlPageData = {
2699 "XML", TRUE, TRUE, TRUE, FALSE, -1,
2700 PopulateXML, ShowFastaOrAsn, NULL,
2701 CopyFlatFileFastaOrAsn, PrintFlatFileFastaOrAsn,
2702 ExportAsnAfterConfirming, NULL, ResizeFlatFileFastaOrAsn, NULL
2703 };
2704
2705 BioseqPageData gbseqPageData = {
2706 "INSDSeq", TRUE, TRUE, TRUE, FALSE, -1,
2707 PopulateGBSeq, ShowGBSeq, NULL,
2708 CopyFlatFileFastaOrAsn, PrintFlatFileFastaOrAsn,
2709 ExportAsnAfterConfirming, NULL, ResizeFlatFileFastaOrAsn, NULL
2710 };
2711
2712