1 /*   docsum.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:  docsum.c
27 *
28 * Author:  Jonathan Kans, Jonathan Epstein
29 *
30 * Version Creation Date:   9/13/96
31 *
32 * $Revision: 6.57 $
33 *
34 * File Description:
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * $Log: docsum.c,v $
39 * Revision 6.57  2006/07/13 17:14:49  bollin
40 * use Uint4 instead of Uint2 for itemID values
41 *
42 * Revision 6.56  2003/12/02 20:42:06  kans
43 * fixed sprintf calls in SetDefaultFailureMessae
44 *
45 * Revision 6.55  2002/11/06 21:30:57  ucko
46 * ChangeViewerLinkData: when extracting a string from vnp->data, use
47 * ptrvalue rather than intvalue (which may be the wrong width)
48 *
49 * Revision 6.54  2002/01/03 16:53:52  kans
50 * use left, top passed in
51 *
52 * Revision 6.53  2001/11/02 12:51:01  kans
53 * add EntrezDocSum time log if environment variable set on UNIX
54 *
55 * Revision 6.52  2001/02/15 18:06:55  kans
56 * FileToString fixed for PC
57 *
58 * Revision 6.51  2000/11/17 22:58:57  kans
59 * BioseqFindEntityByGi and others clear vn.next, LaunchSequenceViewer clears scope - somehow remains set on PC - and FetchDocSum dynamically allocates str, since pfam records overflowed the 1K buffer
60 *
61 * Revision 6.50  2000/08/18 19:53:52  kans
62 * do not remove file sent to Cn3D on any platform
63 *
64 * Revision 6.49  2000/08/17 22:19:16  kans
65 * launch Cn3D with system command, not Execv, which requires full path
66 *
67 * Revision 6.48  2000/08/17 20:32:24  kans
68 * launch remote Cn3D
69 *
70 * Revision 6.47  2000/04/03 21:05:53  lewisg
71 * fix launch of cn3d from sequin
72 *
73 * Revision 6.46  2000/01/04 15:55:50  lewisg
74 * don't hang on disconnected network and fix memory leak/hang at exit
75 *
76 * Revision 6.45  1999/11/02 21:42:23  kans
77 * genpept view only gets sep for bsp, not for top of entity
78 *
79 * Revision 6.44  1999/09/21 17:20:56  kans
80 * added progress monitor when exporting reports
81 *
82 * Revision 6.43  1999/08/25 18:58:52  kans
83 * Boolean bit flags are now unsigned int - int for AIX, unsigned since document.[ch] already used that style
84 *
85 * Revision 6.42  1999/08/04 21:43:52  kans
86 * tells Cn3D it can use network Entrez (LYG)
87 *
88 * Revision 6.41  1999/06/18 19:04:27  kans
89 * set message level MAX for SeqEntryToFlat
90 *
91 * Revision 6.40  1999/03/03 18:26:02  kans
92 * calls ClearStructures before MakeAModelstruc
93 *
94 * Revision 6.39  1999/01/14 19:18:46  kans
95 * new parameters for Cn3DWin_Entrez
96 *
97 * Revision 6.38  1999/01/13 19:26:46  kans
98 * added RetrieveSimpleSeqs, switched from tracking SeqEntry to SimpleSeq, to allow lower case, avoid Bioseq ID collision
99 *
100 * Revision 6.37  1999/01/11 16:25:49  kans
101 * forgot to add parameter to ReadAsnFastaOrFlatFile
102 *
103 * Revision 6.36  1998/11/20 19:01:06  kans
104 * set refine button count if setting retrieve button to evaluate
105 *
106 * Revision 6.35  1998/11/18 16:21:29  kans
107 * added UseDelayedNeighbor to control from preference
108 *
109 * Revision 6.34  1998/11/18 15:55:06  kans
110 * added controls for user to change immediate/delayed neighbor mode
111 *
112 * Revision 6.33  1998/11/18 15:14:02  kans
113 * added retrieveMode to Evaluate neighbors/links only on command
114 *
115 * Revision 6.32  1998/08/14 16:23:01  kans
116 * AddBlastAlignment now passed proper query bioseq
117 *
118 * Revision 6.31  1998/06/12 00:00:31  kans
119 * now calling CleanupEntrezPrefsProc, other minor fixes
120 *
121 * Revision 6.30  1998/05/11 21:48:10  kans
122 * calls GetIdStringsForSeqEntryAligns for count to avoid database hit until retrieve
123 *
124 * Revision 6.29  1998/05/07 01:38:56  kans
125 * retrieve generation hides fasta format control of instantiated uid-less bioseqs
126 *
127 * Revision 6.28  1998/05/05 15:13:02  kans
128 * added lgp->onlyFromThis, control (hidden)
129 *
130 * Revision 6.27  1998/05/02 23:09:56  kans
131 * calls SeqnSeqEntrysToFasta to trim long deflines
132 *
133 * Revision 6.26  1998/04/29 15:15:57  kans
134 * double click only if uids present
135 *
136 * Revision 6.25  1998/04/23 12:48:08  kans
137 * read asn/fasta bioseq collection tries to use sep already attached to bsp
138 *
139 * Revision 6.24  1998/04/22 18:07:47  kans
140 * docsum import label says FASTA or Uid List
141 *
142 * Revision 6.23  1998/04/22 17:35:14  kans
143 * docsum import collects bioseqs into a project, refine button disabled if 0 items
144 *
145 * Revision 6.22  1998/04/21 12:56:00  kans
146 * support for blast choices in database alist, neighbor/link control for blasting a record that already has a uid
147 *
148 * Revision 6.21  1998/04/19 23:49:29  kans
149 * added parseFastaSeqId parameter to ReadAsnFastaOrFlatFile
150 *
151 * Revision 6.20  1998/04/19 23:28:30  kans
152 * initial implementation of import docsum function
153 *
154 * Revision 6.19  1998/04/19 22:56:11  kans
155 * cast for ValNodeLink in building project
156 *
157 * Revision 6.18  1998/04/19 22:08:42  kans
158 * nuc, prot flags to DocSumCanSaveFasta, ExportDocSumFasta
159 *
160 * Revision 6.17  1998/04/18 02:38:32  kans
161 * export docsum fasta does not add newlines, for consistency with export bioseq view fasta
162 *
163 * Revision 6.16  1998/04/18 02:08:11  kans
164 * added DocSumCanSaveFasta and ExportDocSumFasta
165 *
166 * Revision 6.15  1998/04/17 16:44:36  kans
167 * empty function for ImportDocSumForm, implemented ExportDocSumForm
168 *
169 * Revision 6.14  1998/04/16 19:16:27  kans
170 * fasta format sets group_segs to handle seg, delta sequences
171 *
172 * Revision 6.13  1998/04/14 21:46:48  kans
173 * added FetchUid, xxx ID radio button choices
174 *
175 * Revision 6.12  1998/04/14 18:13:45  kans
176 * SetDefaultFailureMessage for docsum items
177 *
178 * Revision 6.11  1998/04/13 19:26:54  kans
179 * forgot to NULL out sfp->seqentry when MemFreeing it
180 *
181 * Revision 6.10  1998/04/13 16:47:16  kans
182 * implemented SetDocSumImportExportItems
183 *
184 * Revision 6.9  1998/04/11 16:20:03  kans
185 * can now read uid or sep project, save sep project
186 *
187 * Revision 6.8  1998/04/11 00:47:00  kans
188 * initial work on handling instantiated bioseqs as projects
189 *
190 * Revision 6.7  1998/03/25 15:25:33  kans
191 * use >PubMed instead of >MEDLINE
192 *
193 * Revision 6.6  1998/03/01 22:04:49  kans
194 * blast wordsize 10 for 16-bit Windows
195 *
196 * Revision 6.5  1998/02/21 22:11:46  kans
197 * implement copy to clipboard
198 *
199 * Revision 6.4  1998/01/07 19:11:47  kans
200 * added UpdateViewerLinkTarget
201 *
202 * Revision 6.3  1997/12/03 22:47:30  kans
203 * AddBlastAlignment returns if no alignments to do
204 *
205 * Revision 6.2  1997/11/01 22:58:36  kans
206 * added alignDefault preference control
207 *
208 * Revision 6.1  1997/09/22 18:13:45  kans
209 * removed obsolete explosion mode
210 *
211 * Revision 6.0  1997/08/25 18:48:42  madden
212 * Revision changed to 6.0
213 *
214 * Revision 1.20  1997/08/12 18:43:36  kans
215 * calls SaveDocumentItem if docsums checked
216 *
217 * Revision 1.19  1997/07/23 18:09:09  kans
218 * DS and TL specific Save/LoadUidProcList functions
219 *
220 * Revision 1.18  1997/07/22 20:05:43  kans
221 * new parameter to BLASTSetUpSearch
222 *
223 * Revision 1.17  1997/07/21 14:25:58  kans
224 * load/save uid list now uses text database tag
225 *
226 * Revision 1.16  1997/06/27 17:07:05  kans
227 * do not limit FileToString to 32K
228 *
229 * Revision 1.15  1997/06/01 23:25:07  kans
230 * flat files use displayFont
231 *
232 * Revision 1.14  1997/04/29 18:47:15  kans
233 * uses persistDefault field if parentsPersist not yet set (PC or UNIX)
234 *
235  * Revision 1.13  1997/04/21  15:36:35  kans
236  * added LoadUidListProc and SaveUidListProc
237  *
238  * Revision 1.12  1997/03/31  18:54:00  kans
239  * watch cursor/arrow cursor calls flank export and print docsum
240  *
241  * Revision 1.11  1997/03/20  21:17:44  kans
242  * change display font should send redraw message on all platforms
243  *
244  * Revision 1.10  1997/03/20  19:05:10  vakatov
245  * [!WIN16] Included <cn3dentr.h>; now use Cn3DWin_Entrez() instead of Cn3DWin()
246  * In FetchPDB() and LaunchStructureViewer(), check for BiostrucAvail() [J.K.]
247  *
248 *
249 * ==========================================================================
250 */
251 
252 #include <vibrant.h>
253 #include <document.h>
254 #include <accentr.h>
255 #include <objmgr.h>
256 #include <gather.h>
257 #include <asn2ff.h>
258 #include <tomedlin.h>
259 #include <tofasta.h>
260 #include <simple.h>
261 #include <dlogutil.h>
262 #include <objproj.h>
263 #include <mmdbapi.h>
264 #ifndef WIN16
265 #include <cn3dmain.h>
266 #include <cn3dopen.h>  /* added by lyg */
267 #include <algorend.h>
268 #include <cn3dentr.h>
269 #include <udviewer.h>
270 #include <ddvopen.h>
271 #endif
272 
273 #include <blast.h>
274 #include <blastpri.h>
275 #include <simutil.h>
276 
277 #include <bspview.h>
278 #include <medview.h>
279 
280 #include <entrez.h>
281 
282 #ifndef MAX_MDLNO
283 #define MAX_MDLNO 1000
284 #endif
285 
286 #define MAX_DBS 6
287 
288 #define FETCH_MODE        1
289 #define EVAL_MODE         2
290 
291 typedef struct docsumstatedata {
292   unsigned int       checked     : 1;
293   unsigned int       hasAbstract : 1;
294   unsigned int       noSuchUid   : 1;
295 } StateData, PNTR StateDataPtr;
296 
297 typedef struct summformdata {
298   FORM_MESSAGE_BLOCK
299 
300   PopuP              target;
301   DoC                docsum;
302   GrouP              formats [MAX_DBS + 1];
303   CharPtr            label;
304   GrouP              controls;
305 
306   Int2               dsClickItem;
307   Int2               dsClickRow;
308   Int2               dsClickCol;
309   Boolean            wasDoubleClick;
310 
311   Boolean            usingDelay;
312   Int2               retrieveMode;
313 
314   ButtoN             retrieve;
315   ButtoN             refine;
316 
317   EnumFieldAssocPtr  dbalist;
318 
319   Int4Ptr            uids;
320   SimpleSeqPtr PNTR  simple;
321   StateDataPtr       state;
322   Int2               numUids;
323   Int2               numParents;
324 
325   Int4Ptr            neighbors;
326   Int2               numNeighbors;
327   Int2               neighborDb;
328   Int2               currDb;
329 
330   Int2               lineHeight;
331   Int2               linesPerIcon;
332 
333   CharPtr            historyFile;
334   Int4Ptr            historyOffsets;
335   Int2               generations;
336   Int2               present;
337 
338   ButtoN             nextBtn;
339   ButtoN             prevBtn;
340 
341   FonT               docsumFont;
342 } SummFormData, PNTR SummFormPtr;
343 
344 static Uint1  hasabstract [] = {
345   0x07, 0xF8, 0x1F, 0xE0, 0x78, 0x07, 0xE0, 0x1E,
346   0x40, 0x01, 0x80, 0x02, 0x40, 0x01, 0x80, 0x02,
347   0x40, 0x01, 0x80, 0x02, 0x4F, 0xF9, 0x9F, 0xF2,
348   0x40, 0x01, 0x80, 0x02, 0x4F, 0xF9, 0x9F, 0xF2,
349   0x40, 0x01, 0x80, 0x02, 0x4F, 0xF9, 0x9F, 0xF2,
350   0x40, 0x01, 0x80, 0x02, 0x4F, 0xF9, 0x9F, 0xF2,
351   0x40, 0x01, 0x80, 0x02, 0x4F, 0xF9, 0x9F, 0xF2,
352   0x40, 0x01, 0x80, 0x02, 0x4F, 0xF9, 0x9F, 0xF2,
353   0x40, 0x01, 0x80, 0x02, 0x40, 0x01, 0x80, 0x02,
354   0x40, 0x01, 0x80, 0x02, 0x47, 0xF9, 0x9F, 0xE2,
355   0x7F, 0xFF, 0xFF, 0xFE, 0x7F, 0xFF, 0xFF, 0xFE
356 };
357 
358 static Uint1  noabstract [] = {
359   0x07, 0xF8, 0x1F, 0xE0, 0x78, 0x07, 0xE0, 0x1E,
360   0x40, 0x01, 0x80, 0x02, 0x40, 0x01, 0x80, 0x02,
361   0x40, 0x01, 0x80, 0x02, 0x40, 0x01, 0x80, 0x02,
362   0x40, 0x01, 0x80, 0x02, 0x40, 0x01, 0x80, 0x02,
363   0x40, 0x01, 0x80, 0x02, 0x40, 0x01, 0x80, 0x02,
364   0x40, 0x01, 0x80, 0x02, 0x40, 0x01, 0x80, 0x02,
365   0x40, 0x01, 0x80, 0x02, 0x40, 0x01, 0x80, 0x02,
366   0x40, 0x01, 0x80, 0x02, 0x40, 0x01, 0x80, 0x02,
367   0x40, 0x01, 0x80, 0x02, 0x40, 0x01, 0x80, 0x02,
368   0x40, 0x01, 0x80, 0x02, 0x47, 0xF9, 0x9F, 0xE2,
369   0x7F, 0xFF, 0xFF, 0xFE, 0x7F, 0xFF, 0xFF, 0xFE
370 };
371 
372 static Uint1  proteinicon [] = {
373   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
374   0x40, 0x00, 0x00, 0x02, 0x43, 0x83, 0x80, 0x02,
375   0x44, 0x44, 0x40, 0x02, 0x43, 0xC3, 0xC0, 0x02,
376   0x44, 0x44, 0x40, 0x02, 0x44, 0x44, 0x40, 0x02,
377   0x44, 0x44, 0x40, 0x02, 0x43, 0xE3, 0xE0, 0x02,
378   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
379   0x40, 0x00, 0x00, 0x02, 0x47, 0xE7, 0xE7, 0xE2,
380   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
381   0x47, 0xE7, 0xE7, 0xE2, 0x40, 0x00, 0x00, 0x02,
382   0x40, 0x00, 0x00, 0x02, 0x47, 0xE7, 0xE7, 0xE2,
383   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
384 };
385 
386 static Uint1  dnaicon [] = {
387   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
388   0x40, 0x00, 0x00, 0x02, 0x45, 0x81, 0x00, 0x02,
389   0x46, 0x41, 0x00, 0x02, 0x44, 0x47, 0xC0, 0x02,
390   0x44, 0x41, 0x00, 0x02, 0x44, 0x41, 0x00, 0x02,
391   0x44, 0x41, 0x00, 0x02, 0x44, 0x60, 0xC0, 0x02,
392   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
393   0x40, 0x00, 0x00, 0x02, 0x4F, 0x7B, 0xDE, 0xF2,
394   0x40, 0x00, 0x00, 0x02, 0x4F, 0x7B, 0xDE, 0xF2,
395   0x40, 0x00, 0x00, 0x02, 0x4F, 0x7B, 0xDE, 0xF2,
396   0x40, 0x00, 0x00, 0x02, 0x4F, 0x7B, 0xDE, 0xF2,
397   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
398 };
399 
400 static Uint1  threedicon [] = {
401   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
402   0x40, 0x00, 0x00, 0x02, 0x4E, 0x0E, 0x00, 0x02,
403   0x41, 0x09, 0x00, 0x02, 0x40, 0x88, 0x80, 0x02,
404   0x47, 0x08, 0x80, 0x02, 0x40, 0x88, 0x80, 0x02,
405   0x41, 0x09, 0x00, 0x02, 0x4E, 0x0E, 0x00, 0x02,
406   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
407   0x40, 0x00, 0x00, 0x02, 0x47, 0xE0, 0x00, 0x02,
408   0x40, 0x07, 0xE0, 0x02, 0x40, 0x00, 0x07, 0xE2,
409   0x47, 0xE0, 0x00, 0x02, 0x40, 0x07, 0xE0, 0x02,
410   0x40, 0x00, 0x07, 0xE2, 0x47, 0xE0, 0x00, 0x02,
411   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
412 };
413 
414 static Uint1  genomeicon [] = {
415   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
416   0x40, 0xF0, 0xF0, 0x02, 0x41, 0x01, 0x08, 0x02,
417   0x41, 0x01, 0x00, 0x02, 0x41, 0x01, 0x00, 0x02,
418   0x41, 0x01, 0x38, 0x02, 0x41, 0x01, 0x10, 0x02,
419   0x40, 0xF0, 0xE0, 0x02, 0x40, 0x00, 0x00, 0x02,
420 #ifdef USE_CHROMOSOME_BANDS_IN_ICON
421 /* chromosome bands */
422   0x40, 0x00, 0x00, 0x02, 0x4F, 0xEF, 0xFF, 0xF2,
423   0x50, 0x10, 0xC4, 0xEA, 0x50, 0x10, 0xC4, 0xEA,
424   0x50, 0x10, 0xC4, 0xEA, 0x50, 0x10, 0xC4, 0xEA,
425   0x50, 0x10, 0xC4, 0xEA, 0x50, 0x10, 0xC4, 0xEA,
426   0x50, 0x10, 0xC4, 0xEA, 0x4F, 0xEF, 0xFF, 0xF2,
427   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
428 #else
429 /* show alignment */
430   0x40, 0x00, 0x00, 0x02, 0x4F, 0xFF, 0xFF, 0xF2,
431   0x48, 0x00, 0x00, 0x12, 0x4F, 0xFF, 0xFF, 0xF2,
432   0x40, 0x00, 0x00, 0x02, 0x40, 0xE0, 0xFF, 0x02,
433   0x40, 0x00, 0x00, 0x02, 0x4F, 0x0F, 0x80, 0x02,
434   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
435   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
436 #endif
437 };
438 
439 static Uint1  checkmark [] = {
440   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40,
441   0x00, 0x80, 0x01, 0x00, 0x22, 0x00, 0x14, 0x00,
442   0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
443 };
444 
445 static Uint1Ptr  iconLists [] = {
446   noabstract, hasabstract, proteinicon, proteinicon, dnaicon,
447   dnaicon, threedicon, threedicon, genomeicon, genomeicon
448 };
449 
450 static ParData docsumParFmt = {TRUE, FALSE, FALSE, FALSE, FALSE, 0, 0};
451 static ColData docsumColFmt [] = {
452   {0, 0, 15, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE},  /* caption  */
453   {0, 5, 65, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, TRUE}    /* term     */
454 };
455 static ColData textColFmt [] = {
456   {0, 0, 80, 0, NULL, 'l', FALSE, FALSE, FALSE, FALSE, TRUE}    /* text     */
457 };
458 
459 static void SetDocSumImportExportItems (SummFormPtr sfp);
460 
BioseqLockByGi(Int4 uid)461 static BioseqPtr BioseqLockByGi (Int4 uid)
462 
463 {
464   ValNode  vn;
465 
466   if (uid <= 0) return NULL;
467   vn.choice = SEQID_GI;
468   vn.data.intvalue = uid;
469   vn.next = NULL;
470   return BioseqLockById (&vn);
471 }
472 
BioseqUnlockByGi(Int4 uid)473 static Boolean BioseqUnlockByGi (Int4 uid)
474 
475 {
476   ValNode  vn;
477 
478   if (uid <= 0) return FALSE;
479   vn.choice = SEQID_GI;
480   vn.data.intvalue = uid;
481   vn.next = NULL;
482   return BioseqUnlockById (&vn);
483 }
484 
SeqEntryLockByGi(Int4 uid)485 static SeqEntryPtr SeqEntryLockByGi (Int4 uid)
486 
487 {
488   BioseqPtr    bsp;
489   Uint2        entityID;
490   SeqEntryPtr  sep;
491 
492   bsp = BioseqLockByGi (uid);
493   if (bsp == NULL) return NULL;
494   entityID = ObjMgrGetEntityIDForPointer (bsp);
495   if (entityID == 0) return NULL;
496   sep = GetTopSeqEntryForEntityID (entityID);
497   return sep;
498 }
499 
BioseqFindEntityByGi(Int4 uid,Uint4Ptr itemIDptr)500 static Uint2 BioseqFindEntityByGi (Int4 uid, Uint4Ptr itemIDptr)
501 
502 {
503   ValNode  vn;
504 
505   if (uid <= 0) return 0;
506   vn.choice = SEQID_GI;
507   vn.data.intvalue = uid;
508   vn.next = NULL;
509   return BioseqFindEntity (&vn, itemIDptr);
510 }
511 
DoDrawCheck(SummFormPtr sfp,RectPtr r,Int2 item,Int2 frst,Boolean docsum)512 static void DoDrawCheck (SummFormPtr sfp, RectPtr r, Int2 item, Int2 frst, Boolean docsum)
513 
514 {
515   Int2  checked;
516   RecT  rct;
517 
518   if (sfp == NULL || sfp->state == NULL) return;
519   if (item < 1) return;
520   if (item > sfp->numUids) return;
521   checked = sfp->state [item - 1].checked;
522   if (frst == 0) {
523     rct = *r;
524     rct.right = rct.left + sfp->lineHeight;
525     rct.bottom = rct.top + sfp->lineHeight;
526     if (RectInRgn (&rct, updateRgn)) {
527       FrameRect (&rct);
528       if (checked) {
529         MoveTo (rct.left, rct.top);
530         LineTo (rct.right - 1, rct.bottom - 1);
531         MoveTo (rct.left, rct.bottom - 1);
532         LineTo (rct.right - 1, rct.top);
533       }
534     }
535     if (item <= sfp->numParents) {
536       rct = *r;
537       if (docsum) {
538         rct.left += docsumColFmt [0].pixInset - 6;
539         rct.top += (sfp->lineHeight - 4) / 2;
540         rct.right = rct.left + 4;
541         rct.bottom = rct.top + 4;
542       } else {
543         rct.left += textColFmt [0].pixInset - 6;
544         rct.top += (sfp->lineHeight - 4) / 2;
545         rct.right = rct.left + 4;
546         rct.bottom = rct.top + 4;
547       }
548       if (RectInRgn (&rct, updateRgn)) {
549         PaintOval (&rct);
550       }
551     }
552   }
553 }
554 
DrawUidCheck(SummFormPtr sfp,RectPtr r,Int2 item,Int2 frst,Boolean docsum)555 static void DrawUidCheck (SummFormPtr sfp, RectPtr r, Int2 item, Int2 frst, Boolean docsum)
556 
557 {
558   Int4  uid;
559 
560   if (sfp == NULL || sfp->uids == NULL || sfp->state == NULL) return;
561   if (item < 1) return;
562   if (item > sfp->numUids) return;
563   uid = sfp->uids [item - 1];
564   if (uid < 1) return;
565   DoDrawCheck (sfp, r, item, frst, docsum);
566 }
567 
DrawLocalCheck(SummFormPtr sfp,RectPtr r,Int2 item,Int2 frst,Boolean docsum)568 static void DrawLocalCheck (SummFormPtr sfp, RectPtr r, Int2 item, Int2 frst, Boolean docsum)
569 
570 {
571   SimpleSeqPtr  ssp;
572 
573   if (sfp == NULL || sfp->simple == NULL || sfp->state == NULL) return;
574   if (item < 1) return;
575   if (item > sfp->numUids) return;
576   ssp = sfp->simple [item - 1];
577   if (ssp == NULL) return;
578   DoDrawCheck (sfp, r, item, frst, docsum);
579 }
580 
DrawIcon(SummFormPtr sfp,RectPtr r,Int2 item,Int2 frst)581 static void DrawIcon (SummFormPtr sfp, RectPtr r, Int2 item, Int2 frst)
582 
583 {
584   Int2      db;
585   Int2      hasAbstract;
586   Uint1Ptr  icon;
587   Int2      index;
588   RecT      rct;
589   Int4      uid;
590 
591   if (sfp == NULL || sfp->uids == NULL || sfp->state == NULL) return;
592   if (item < 1) return;
593   if (item > sfp->numUids) return;
594   db = sfp->currDb;
595   uid = sfp->uids [item - 1];
596   hasAbstract = sfp->state [item - 1].hasAbstract;
597   if (uid < 1) return;
598   if (frst < sfp->linesPerIcon) {
599     if (db >= 0 && db <= 4) {
600       index = db * 2;
601       if (hasAbstract) {
602         index++;
603       }
604       rct = *r;
605       /*
606       rct.left += sfp->lineHeight + 4;
607       */
608       rct.left += 3 * stdCharWidth - 8;
609       rct.right = rct.left + 32;
610       rct.bottom = MIN (rct.bottom, rct.top + 22 - frst * sfp->lineHeight);
611       if (RectInRgn (&rct, updateRgn)) {
612         icon = iconLists [index];
613         if (icon != NULL) {
614           CopyBits (&rct, icon + 4 * frst * sfp->lineHeight);
615         }
616       }
617     }
618   }
619 }
620 
DrawDocSum(DoC d,RectPtr r,Int2 item,Int2 frst)621 static void DrawDocSum (DoC d, RectPtr r, Int2 item, Int2 frst)
622 
623 {
624   SummFormPtr  sfp;
625 
626   sfp = (SummFormPtr) GetObjectExtra (d);
627   DrawUidCheck (sfp, r, item, frst, TRUE);
628   DrawIcon (sfp, r, item, frst);
629 }
630 
DrawTextSum(DoC d,RectPtr r,Int2 item,Int2 frst)631 static void DrawTextSum (DoC d, RectPtr r, Int2 item, Int2 frst)
632 
633 {
634   SummFormPtr  sfp;
635 
636   sfp = (SummFormPtr) GetObjectExtra (d);
637   DrawUidCheck (sfp, r, item, frst, FALSE);
638 }
639 
DrawLocalSum(DoC d,RectPtr r,Int2 item,Int2 frst)640 static void DrawLocalSum (DoC d, RectPtr r, Int2 item, Int2 frst)
641 
642 {
643   SummFormPtr  sfp;
644 
645   sfp = (SummFormPtr) GetObjectExtra (d);
646   DrawLocalCheck (sfp, r, item, frst, FALSE);
647 }
648 
SetDefaultFailureMessage(SummFormPtr sfp,Int2 item,CharPtr prefix)649 static CharPtr SetDefaultFailureMessage (SummFormPtr sfp, Int2 item, CharPtr prefix)
650 
651 {
652   Char          buf [40];
653   CharPtr       dbname = NULL;
654   SimpleSeqPtr  ssp;
655   Char          tmp [64];
656   Int4          uid;
657 
658   tmp [0] = '\0';
659   if (prefix == NULL) {
660     prefix = "";
661   }
662   if (sfp == NULL) return StringSave ("?");
663   if (sfp->currDb >= 0 && sfp->currDb < MAX_DBS) {
664     dbname = GetEnumName ((UIEnum) sfp->currDb, sfp->dbalist);
665   }
666   if (dbname == NULL) {
667     dbname = "[?]";
668   }
669   if (item < 1) {
670     sprintf (tmp, "%sItem < 1 for database %s", prefix, dbname);
671   } else if (sfp->uids != NULL && sfp->simple == NULL) {
672     uid = sfp->uids [item - 1];
673     if (uid < 1) {
674       sprintf (tmp, "%sID < 1 for database %s", prefix, dbname);
675     } else {
676       sprintf (tmp, "%sFailure for ID %ld in %s database", prefix, (long) uid, dbname);
677     }
678   } else if (sfp->simple != NULL && sfp->uids == NULL) {
679     ssp = sfp->simple [item - 1];
680     if (ssp == NULL) {
681       sprintf (tmp, "%sIncorrect seq-entry for database %s", prefix, dbname);
682     } else {
683       StringCpy (buf, "?");
684       if (ssp->numid > 0 && ssp->bestid < ssp->numid) {
685         StringNCpy_0 (buf, ssp->id [ssp->bestid], sizeof (buf));
686       }
687       sprintf (tmp, "%sProblem with sequence %s in %s database", prefix, buf, dbname);
688     }
689   } else {
690     sprintf (tmp, "%sInternal confusion for database %s", prefix, dbname);
691   }
692   return StringSave (tmp);
693 }
694 
FetchDocSum(DoC d,Int2 item,Pointer ptr)695 static CharPtr FetchDocSum (DoC d, Int2 item, Pointer ptr)
696 
697 {
698   DocSumPtr    dsp;
699   CharPtr      failed;
700   size_t       len;
701   Int2         j;
702   SummFormPtr  sfp;
703   CharPtr      str;
704   Int4         uid;
705 #ifdef OS_UNIX
706   Boolean      logtimes;
707   Int4         starttime;
708   Int4         stoptime;
709 #endif
710 
711   sfp = (SummFormPtr) GetObjectExtra (d);
712   failed = SetDefaultFailureMessage (sfp, item, "\r\t");
713   if (sfp == NULL || sfp->uids == NULL || sfp->state == NULL) return failed;
714   if (item < 1) return failed;
715   uid = sfp->uids [item - 1];
716 
717 #ifdef OS_UNIX
718   logtimes = (Boolean) ((getenv ("NCBI_LOG_SYNC_QUERY_TIMES")) != NULL);
719   if (logtimes) {
720     starttime = ComputerTime ();
721   }
722 #endif
723 
724   dsp = EntrezDocSum (sfp->currDb, uid);
725   if (dsp == NULL) return failed;
726 
727 #ifdef OS_UNIX
728   if (logtimes) {
729     stoptime = ComputerTime ();
730     printf ("EntrezDocSum %ld\n", (long) (stoptime - starttime));
731   }
732 #endif
733 
734   if (dsp->caption == NULL && dsp->title == NULL && dsp->extra == NULL) {
735     DocSumFree (dsp);
736     return failed;
737   }
738   MemFree (failed);
739   len = StringLen (dsp->caption) + StringLen (dsp->title) + StringLen (dsp->extra) + 20;
740   str = MemNew (sizeof (Char) * len);
741   if (str == NULL) return failed;
742   if (dsp->caption != NULL) {
743     StringCat (str, dsp->caption);
744   }
745   j = 0;
746   while (str [j] != '\0' && str [j] != ',') {
747     j++;
748   }
749   if (str [j] == ',' && str [j + 1] == ' ') {
750     str [j + 1] = '\r';
751   }
752   StringCat (str, "\r");
753   StringCat (str, "\t");
754   if (dsp->title != NULL || dsp->extra != NULL) {
755     if (dsp->title != NULL) {
756       j = 0;
757       while (dsp->title [j] != '\0') {
758         if (dsp->title [j] == '\n' || dsp->title [j] == '\r') {
759           dsp->title [j] = ' ';
760         }
761         j++;
762       }
763       StringCat (str, dsp->title);
764     }
765     if (dsp->extra != NULL) {
766       StringCat (str, "\r");
767       j = 0;
768       while (dsp->extra [j] != '\0') {
769         if (dsp->extra [j] == '\n' || dsp->extra [j] == '\r') {
770           dsp->extra [j] = ' ';
771         }
772         j++;
773       }
774         StringCat (str, dsp->extra);
775     }
776   } else {
777     StringCat (str, "?");
778   }
779   StringCat (str, "\n");
780   sfp->state [item - 1].hasAbstract = (Boolean) (! dsp->no_abstract);
781   DocSumFree (dsp);
782   return /* StringSave (str) */ str;
783 }
784 
FetchUid(DoC d,Int2 item,Pointer ptr)785 static CharPtr FetchUid (DoC d, Int2 item, Pointer ptr)
786 
787 {
788   CharPtr      failed;
789   SummFormPtr  sfp;
790   Char         str [64];
791   Int4         uid;
792 
793   sfp = (SummFormPtr) GetObjectExtra (d);
794   failed = SetDefaultFailureMessage (sfp, item, NULL);
795   if (sfp == NULL || sfp->uids == NULL || sfp->state == NULL) return failed;
796   if (item < 1) return failed;
797   uid = sfp->uids [item - 1];
798   if (uid < 1) return failed;
799   MemFree (failed);
800   sprintf (str, "%ld\n", (long) uid);
801   return StringSave (str);
802 }
803 
FileToString(CharPtr path)804 static CharPtr FileToString (CharPtr path)
805 
806 {
807   Int2     actual;
808   FILE     *fp;
809   Int8     len;
810   CharPtr  ptr;
811 
812   if (path == NULL) return NULL;
813   ptr = NULL;
814   len = FileLength (path);
815   if (len > 0 && len < MAXALLOC /* && len < 32760 */) {
816     fp = FileOpen (path, "r");
817     if (fp != NULL) {
818       ptr = MemNew (sizeof (Char) * (size_t) (len + 4));
819       if (ptr != NULL) {
820         actual = FileRead (ptr, 1, (size_t) len, fp);
821         if (actual > 0 && actual <= len) {
822           /*
823           ptr [actual] = '\n';
824           ptr [actual + 1] = '\0';
825           */
826           ptr [actual] = '\0';
827         }
828       }
829       FileClose (fp);
830     }
831   }
832   return ptr;
833 }
834 
FetchAbstract(DoC d,Int2 item,Pointer ptr)835 static CharPtr FetchAbstract (DoC d, Int2 item, Pointer ptr)
836 
837 {
838   CharPtr          failed;
839   FILE             *fp;
840   MedlineEntryPtr  mep;
841   Char             path [PATH_MAX];
842   SummFormPtr      sfp;
843   CharPtr          str;
844   Int4             uid;
845 
846   sfp = (SummFormPtr) GetObjectExtra (d);
847   failed = SetDefaultFailureMessage (sfp, item, NULL);
848   if (sfp == NULL || sfp->uids == NULL || sfp->state == NULL) return failed;
849   if (item < 1) return failed;
850   uid = sfp->uids [item - 1];
851   mep = EntrezMedlineEntryGet (uid);
852   if (mep == NULL) return failed;
853   str = NULL;
854   TmpNam (path);
855   fp = FileOpen (path, "w");
856   if (fp != NULL) {
857     if (MedlineEntryToAbsFile (mep, fp)) {
858       FileClose (fp);
859       str = FileToString (path);
860     } else {
861       FileClose (fp);
862     }
863   }
864   FileRemove (path);
865   MedlineEntryFree (mep);
866   if (str == NULL) return failed;
867   MemFree (failed);
868   return str;
869 }
870 
FetchCitation(DoC d,Int2 item,Pointer ptr)871 static CharPtr FetchCitation (DoC d, Int2 item, Pointer ptr)
872 
873 {
874   CharPtr          failed;
875   FILE             *fp;
876   MedlineEntryPtr  mep;
877   Char             path [PATH_MAX];
878   SummFormPtr      sfp;
879   CharPtr          str;
880   Int4             uid;
881 
882   sfp = (SummFormPtr) GetObjectExtra (d);
883   failed = SetDefaultFailureMessage (sfp, item, NULL);
884   if (sfp == NULL || sfp->uids == NULL || sfp->state == NULL) return failed;
885   if (item < 1) return failed;
886   uid = sfp->uids [item - 1];
887   mep = EntrezMedlineEntryGet (uid);
888   if (mep == NULL) return failed;
889   str = NULL;
890   TmpNam (path);
891   fp = FileOpen (path, "w");
892   if (fp != NULL) {
893     if (MedlineEntryToDocFile (mep, fp)) {
894       FileClose (fp);
895       str = FileToString (path);
896     } else {
897       FileClose (fp);
898     }
899   }
900   FileRemove (path);
901   MedlineEntryFree (mep);
902   if (str == NULL) return failed;
903   MemFree (failed);
904   return str;
905 }
906 
FetchMedline(DoC d,Int2 item,Pointer ptr)907 static CharPtr FetchMedline (DoC d, Int2 item, Pointer ptr)
908 
909 {
910   CharPtr          failed;
911   FILE             *fp;
912   MedlineEntryPtr  mep;
913   Char             path [PATH_MAX];
914   SummFormPtr      sfp;
915   CharPtr          str;
916   Int4             uid;
917 
918   sfp = (SummFormPtr) GetObjectExtra (d);
919   failed = SetDefaultFailureMessage (sfp, item, NULL);
920   if (sfp == NULL || sfp->uids == NULL || sfp->state == NULL) return failed;
921   if (item < 1) return failed;
922   uid = sfp->uids [item - 1];
923   mep = EntrezMedlineEntryGet (uid);
924   if (mep == NULL) return failed;
925   str = NULL;
926   TmpNam (path);
927   fp = FileOpen (path, "w");
928   if (fp != NULL) {
929     if (MedlineEntryToDataFile (mep, fp)) {
930       FileClose (fp);
931       str = FileToString (path);
932     } else {
933       FileClose (fp);
934     }
935   }
936   FileRemove (path);
937   MedlineEntryFree (mep);
938   if (str == NULL) return failed;
939   MemFree (failed);
940   return str;
941 }
942 
FetchGenBank(DoC d,Int2 item,Pointer ptr)943 static CharPtr FetchGenBank (DoC d, Int2 item, Pointer ptr)
944 
945 {
946   CharPtr      failed;
947   FILE         *fp;
948   ErrSev       level;
949   Char         path [PATH_MAX];
950   SeqEntryPtr  sep;
951   SummFormPtr  sfp;
952   CharPtr      str;
953   Int4         uid;
954 
955   sfp = (SummFormPtr) GetObjectExtra (d);
956   failed = SetDefaultFailureMessage (sfp, item, NULL);
957   if (sfp == NULL || sfp->uids == NULL || sfp->state == NULL) return failed;
958   if (item < 1) return failed;
959   uid = sfp->uids [item - 1];
960   /*
961   retcode = GetSequenceComplexity (sfp);
962   sep = EntrezSeqEntryGet (uid, retcode);
963   */
964   sep = SeqEntryLockByGi (uid);
965   if (sep == NULL) return failed;
966   str = NULL;
967   TmpNam (path);
968   fp = FileOpen (path, "w");
969   if (fp != NULL) {
970     level = ErrSetMessageLevel (SEV_MAX);
971     if (SeqEntryToFlat (sep, fp, GENBANK_FMT, RELEASE_MODE)) {
972       FileClose (fp);
973       str = FileToString (path);
974     } else {
975       FileClose (fp);
976     }
977     ErrSetMessageLevel (level);
978   }
979   FileRemove (path);
980   BioseqUnlockByGi (uid);
981   if (str == NULL) return failed;
982   MemFree (failed);
983   return str;
984 }
985 
FetchEmbl(DoC d,Int2 item,Pointer ptr)986 static CharPtr FetchEmbl (DoC d, Int2 item, Pointer ptr)
987 
988 {
989   CharPtr      failed;
990   FILE         *fp;
991   ErrSev       level;
992   Char         path [PATH_MAX];
993   SeqEntryPtr  sep;
994   SummFormPtr  sfp;
995   CharPtr      str;
996   Int4         uid;
997 
998   sfp = (SummFormPtr) GetObjectExtra (d);
999   failed = SetDefaultFailureMessage (sfp, item, NULL);
1000   if (sfp == NULL || sfp->uids == NULL || sfp->state == NULL) return failed;
1001   if (item < 1) return failed;
1002   uid = sfp->uids [item - 1];
1003   /*
1004   retcode = GetSequenceComplexity (sfp);
1005   sep = EntrezSeqEntryGet (uid, retcode);
1006   */
1007   sep = SeqEntryLockByGi (uid);
1008   if (sep == NULL) return failed;
1009   str = NULL;
1010   TmpNam (path);
1011   fp = FileOpen (path, "w");
1012   if (fp != NULL) {
1013     level = ErrSetMessageLevel (SEV_MAX);
1014     if (SeqEntryToFlat (sep, fp, EMBL_FMT, RELEASE_MODE)) {
1015       FileClose (fp);
1016       str = FileToString (path);
1017     } else {
1018       FileClose (fp);
1019     }
1020     ErrSetMessageLevel (level);
1021   }
1022   FileRemove (path);
1023   BioseqUnlockByGi (uid);
1024   if (str == NULL) return failed;
1025   MemFree (failed);
1026   return str;
1027 }
1028 
FetchGenPept(DoC d,Int2 item,Pointer ptr)1029 static CharPtr FetchGenPept (DoC d, Int2 item, Pointer ptr)
1030 
1031 {
1032   BioseqPtr    bsp;
1033   CharPtr      failed;
1034   FILE         *fp;
1035   ErrSev       level;
1036   Char         path [PATH_MAX];
1037   SeqEntryPtr  sep;
1038   SummFormPtr  sfp;
1039   CharPtr      str;
1040   Int4         uid;
1041 
1042   sfp = (SummFormPtr) GetObjectExtra (d);
1043   failed = SetDefaultFailureMessage (sfp, item, NULL);
1044   if (sfp == NULL || sfp->uids == NULL || sfp->state == NULL) return failed;
1045   if (item < 1) return failed;
1046   uid = sfp->uids [item - 1];
1047   /*
1048   retcode = GetSequenceComplexity (sfp);
1049   sep = EntrezSeqEntryGet (uid, retcode);
1050   */
1051   bsp = BioseqLockByGi (uid);
1052   if (bsp == NULL) return failed;
1053   sep = SeqMgrGetSeqEntryForData (bsp);
1054   if (sep == NULL) return failed;
1055   str = NULL;
1056   TmpNam (path);
1057   fp = FileOpen (path, "w");
1058   if (fp != NULL) {
1059     if (spop == NULL) {
1060       spop = StdPrintOptionsNew (NULL);
1061       if (spop != NULL) {
1062         spop->newline = "\r";
1063         spop->indent = "";
1064       } else {
1065         Message (MSG_ERROR, "StdPrintOptionsNew failed");
1066       }
1067     }
1068     level = ErrSetMessageLevel (SEV_MAX);
1069     if (SeqEntryToFlat (sep, fp, GENPEPT_FMT, RELEASE_MODE)) {
1070       FileClose (fp);
1071       str = FileToString (path);
1072     } else {
1073       FileClose (fp);
1074     }
1075     ErrSetMessageLevel (level);
1076   }
1077   FileRemove (path);
1078   BioseqUnlockByGi (uid);
1079   if (str == NULL) return failed;
1080   MemFree (failed);
1081   return str;
1082 }
1083 
FetchFasta(DoC d,Int2 item,Pointer ptr,Boolean is_na)1084 static CharPtr FetchFasta (DoC d, Int2 item, Pointer ptr, Boolean is_na)
1085 
1086 {
1087   BioseqPtr    bsp;
1088   CharPtr      failed;
1089   FILE         *fp;
1090   Uint1        group_segs = 0;
1091   Char         path [PATH_MAX];
1092   SeqEntryPtr  sep;
1093   SummFormPtr  sfp;
1094   CharPtr      str;
1095   Int4         uid;
1096 
1097   sfp = (SummFormPtr) GetObjectExtra (d);
1098   failed = SetDefaultFailureMessage (sfp, item, NULL);
1099   if (sfp == NULL || sfp->uids == NULL || sfp->state == NULL) return failed;
1100   if (item < 1) return failed;
1101   uid = sfp->uids [item - 1];
1102   /*
1103   retcode = GetSequenceComplexity (sfp);
1104   sep = EntrezSeqEntryGet (uid, retcode);
1105   */
1106   /*
1107   sep = SeqEntryLockByGi (uid);
1108   if (sep == NULL) return failed;
1109   */
1110   bsp = BioseqLockByGi (uid);
1111   if (bsp == NULL) return failed;
1112   sep = SeqMgrGetSeqEntryForData (bsp);
1113   str = NULL;
1114   TmpNam (path);
1115   fp = FileOpen (path, "w");
1116   if (fp != NULL) {
1117     if (bsp->repr == Seq_repr_seg) {
1118       group_segs = 1;
1119     } else if (bsp->repr == Seq_repr_delta) {
1120       group_segs = 3;
1121     }
1122     if (SeqEntrysToFasta (sep, fp, is_na, group_segs)) {
1123       FileClose (fp);
1124       str = FileToString (path);
1125     } else {
1126       FileClose (fp);
1127     }
1128   }
1129   FileRemove (path);
1130   BioseqUnlockByGi (uid);
1131   if (str == NULL) return failed;
1132   MemFree (failed);
1133   return str;
1134 }
1135 
FetchFastaNuc(DoC d,Int2 item,Pointer ptr)1136 static CharPtr FetchFastaNuc (DoC d, Int2 item, Pointer ptr)
1137 
1138 {
1139   return FetchFasta (d, item, ptr, TRUE);
1140 }
1141 
FetchFastaProt(DoC d,Int2 item,Pointer ptr)1142 static CharPtr FetchFastaProt (DoC d, Int2 item, Pointer ptr)
1143 
1144 {
1145   return FetchFasta (d, item, ptr, FALSE);
1146 }
1147 
FetchPDB(DoC d,Int2 item,Pointer ptr)1148 static CharPtr FetchPDB (DoC d, Int2 item, Pointer ptr)
1149 
1150 {
1151   BiostrucPtr  bsp;
1152   Int4         complexity;
1153   CharPtr      failed;
1154   FILE         *fp;
1155   Int2         maxModels;
1156   Char         path [PATH_MAX];
1157   PDNMS        pdnms;
1158   SummFormPtr  sfp;
1159   CharPtr      str;
1160   Int4         uid;
1161 
1162   if (! BiostrucAvail ()) {
1163     return StringSave ("Structure libraries are not linked in.");
1164   }
1165   sfp = (SummFormPtr) GetObjectExtra (d);
1166   failed = SetDefaultFailureMessage (sfp, item, NULL);
1167   if (sfp == NULL || sfp->uids == NULL || sfp->state == NULL) return failed;
1168   if (item < 1) return failed;
1169   uid = sfp->uids [item - 1];
1170   /* complexity = GetBiostrucComplexity (sfp); */
1171   complexity = VECMODEL;
1172   /* maxModels = GetBiostrucMaxModels (sfp); */
1173   maxModels = 1;
1174   bsp = EntrezBiostrucGet (uid, complexity, maxModels);
1175   if (bsp == NULL) return failed;
1176   ClearStructures ();
1177   pdnms = MakeAModelstruc (bsp);
1178   if (pdnms == NULL) return failed;
1179   str = NULL;
1180   TmpNam (path);
1181   fp = FileOpen (path, "w");
1182   if (fp != NULL) {
1183     WriteStructSummary (pdnms, fp);
1184     fprintf (fp, "\n\n\n");
1185     WritePDBRemarks (pdnms, fp);
1186     FileClose (fp);
1187     str = FileToString (path);
1188   }
1189   FileRemove (path);
1190   FreeAModelstruc (pdnms);
1191   if (str == NULL) return failed;
1192   MemFree (failed);
1193   return str;
1194 }
1195 
FetchLocalBioseq(DoC d,Int2 item,Pointer ptr)1196 static CharPtr FetchLocalBioseq (DoC d, Int2 item, Pointer ptr)
1197 
1198 {
1199   CharPtr       failed;
1200   FILE          *fp;
1201   Char          path [PATH_MAX];
1202   SummFormPtr   sfp;
1203   SimpleSeqPtr  ssp;
1204   CharPtr       str;
1205 
1206   sfp = (SummFormPtr) GetObjectExtra (d);
1207   failed = SetDefaultFailureMessage (sfp, item, NULL);
1208   if (sfp == NULL || sfp->simple == NULL || sfp->state == NULL) return failed;
1209   if (item < 1) return failed;
1210   ssp = sfp->simple [item - 1];
1211   if (ssp == NULL) return failed;
1212   TmpNam (path);
1213   fp = FileOpen (path, "w");
1214   if (fp != NULL) {
1215     if (SimpleSeqPrint (ssp, fp, TRUE)) {
1216       FileClose (fp);
1217       str = FileToString (path);
1218     } else {
1219       FileClose (fp);
1220     }
1221   }
1222   FileRemove (path);
1223   if (str == NULL) return failed;
1224   MemFree (failed);
1225   return str;
1226 }
1227 
1228 static DocPrntProc mlDocProcs [] = {FetchDocSum, FetchAbstract, FetchCitation, FetchMedline, FetchUid, NULL};
1229 static DocPrntProc aaDocProcs [] = {FetchDocSum, FetchGenPept, FetchFastaProt, FetchUid, NULL};
1230 static DocPrntProc ntDocProcs [] = {FetchDocSum, FetchGenBank, FetchEmbl, FetchFastaNuc, FetchUid, NULL};
1231 static DocPrntProc stDocProcs [] = {FetchDocSum, FetchPDB, FetchUid, NULL};
1232 static DocPrntProc chDocProcs [] = {FetchDocSum, FetchUid, NULL};
1233 
RepopulateDocSum(SummFormPtr sfp,Boolean needToReset)1234 static void RepopulateDocSum (SummFormPtr sfp, Boolean needToReset)
1235 
1236 {
1237   ColPtr               colFmt;
1238   DocDrawProc          ddp;
1239   Int2                 estLines;
1240   Int2                 firstLine;
1241   Int2                 firstShown;
1242   FonT                 font;
1243   MedlineViewProcsPtr  mvpp;
1244   DocPrntProc          proc;
1245   BaR                  sb;
1246   Int4                 startsAt;
1247   SeqViewProcsPtr      svpp;
1248   Int2                 typ_aa;
1249   Int2                 typ_ch;
1250   Int2                 typ_ml;
1251   Int2                 typ_nt;
1252   Int2                 typ_st;
1253   Int2                 val;
1254 
1255   if (sfp == NULL) return;
1256   WatchCursor ();
1257   SafeHide (sfp->docsum);
1258   Update ();
1259   if (! GetScrlParams4 (sfp->docsum, NULL, &firstShown, &firstLine)) {
1260     firstShown = 0;
1261     firstLine = 0;
1262   }
1263   sb = GetSlateVScrollBar ((SlatE) sfp->docsum);
1264   if (needToReset) {
1265     Reset (sfp->docsum);
1266     SetDocShade (sfp->docsum, NULL, NULL, NULL, NULL);
1267     SetDocCache (sfp->docsum, NULL, NULL, NULL);
1268   }
1269   /*
1270   for (i = 0; i < num; i++) {
1271     sprintf (str, "Item %d UID %ld\n", (int) (i + 1), (long) uids [i]);
1272     AppendText (sfp->docsum, str, &docsumParFmt, docsumColFmt, programFont);
1273   }
1274   */
1275   typ_ml = DatabaseFromName ("MEDLINE");
1276   typ_aa = DatabaseFromName ("Protein");
1277   typ_nt = DatabaseFromName ("Nucleotide");
1278   typ_st = DatabaseFromName ("Structure");
1279   typ_ch = DatabaseFromName ("Genome");
1280   proc = FetchDocSum;
1281   ddp = DrawDocSum;
1282   colFmt = docsumColFmt;
1283   estLines = 3;
1284   font = sfp->docsumFont;
1285   if (sfp->simple != NULL) {
1286     proc = FetchLocalBioseq;
1287     ddp = DrawLocalSum;
1288     colFmt = textColFmt;
1289     svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
1290     if (svpp != NULL && svpp->displayFont != NULL) {
1291       font = svpp->displayFont;
1292     }
1293   } else if (sfp->currDb >= 0 && sfp->currDb < MAX_DBS) {
1294     val = GetValue (sfp->formats [sfp->currDb]);
1295     if (val > 0) {
1296       if (val > 1) {
1297         ddp = DrawTextSum;
1298         colFmt = textColFmt;
1299         estLines = 30;
1300         if (sfp->currDb == typ_ml && val == 4) {
1301           mvpp = (MedlineViewProcsPtr) GetAppProperty ("MedlineDisplayForm");
1302           if (mvpp != NULL && mvpp->displayFont != NULL) {
1303             font = mvpp->displayFont;
1304           }
1305         } else if (sfp->currDb == typ_aa || sfp->currDb == typ_nt) {
1306           svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
1307           if (svpp != NULL && svpp->displayFont != NULL) {
1308             font = svpp->displayFont;
1309           }
1310         }
1311       }
1312       if (sfp->currDb == typ_ml) {
1313         proc = mlDocProcs [val - 1];
1314       } else if (sfp->currDb == typ_aa) {
1315         proc = aaDocProcs [val - 1];
1316       } else if (sfp->currDb == typ_nt) {
1317         proc = ntDocProcs [val - 1];
1318       } else if (sfp->currDb == typ_st) {
1319         proc = stDocProcs [val - 1];
1320       } else if (sfp->currDb == typ_ch) {
1321         proc = chDocProcs [val - 1];
1322       }
1323     }
1324   }
1325   BulkAppendItem (sfp->docsum, sfp->numUids, proc, estLines,
1326                   &docsumParFmt, colFmt, font);
1327   SetDocShade (sfp->docsum, ddp, NULL, NULL, NULL);
1328   SetDocCache (sfp->docsum, StdPutDocCache, StdGetDocCache, StdResetDocCache);
1329   /*
1330   InvalDocument (sfp->docsum);
1331   Update ();
1332   */
1333   AdjustDocScroll (sfp->docsum);
1334   GetItemParams4 (sfp->docsum, firstShown, &startsAt, NULL, NULL, NULL, NULL);
1335   CorrectBarValue (sb, startsAt + firstLine);
1336   ResetClip ();
1337   SafeShow (sfp->docsum);
1338   ArrowCursor ();
1339   Update ();
1340 }
1341 
SetPrevAndNextButtons(SummFormPtr sfp)1342 static void SetPrevAndNextButtons (SummFormPtr sfp)
1343 
1344 {
1345   if (sfp->present > 1) {
1346     SafeEnable (sfp->prevBtn);
1347   } else {
1348     SafeDisable (sfp->prevBtn);
1349   }
1350   if (sfp->present < sfp->generations) {
1351     SafeEnable (sfp->nextBtn);
1352   } else {
1353     SafeDisable (sfp->nextBtn);
1354   }
1355 }
1356 
RetrieveGeneration(SummFormPtr sfp,Int2 num,Int2 parents,Int4Ptr uids,Int2 db)1357 static void RetrieveGeneration (SummFormPtr sfp, Int2 num, Int2 parents, Int4Ptr uids, Int2 db)
1358 
1359 {
1360   Int2  i;
1361   Char  title [32];
1362 
1363   if (sfp == NULL || uids == NULL) return;
1364   Reset (sfp->docsum);
1365   SetDocShade (sfp->docsum, NULL, NULL, NULL, NULL);
1366   SetDocCache (sfp->docsum, NULL, NULL, NULL);
1367   sfp->uids = MemFree (sfp->uids);
1368   if (sfp->simple != NULL) {
1369     for (i = 0; i < sfp->numUids; i++) {
1370       SimpleSeqFree (sfp->simple [i]);
1371     }
1372     sfp->simple = MemFree (sfp->simple);
1373   }
1374   sfp->state = MemFree (sfp->state);
1375   sfp->numUids = 0;
1376   sfp->numParents = 0;
1377   sfp->neighbors = MemFree (sfp->neighbors);
1378   sfp->numNeighbors = 0;
1379   SafeSetTitle (sfp->retrieve, "Neighbor 0");
1380   SafeDisable (sfp->retrieve);
1381   sprintf (title, "Refine %d", (int) num);
1382   SafeSetTitle (sfp->refine, title);
1383   if (num > 0) {
1384     SafeEnable (sfp->refine);
1385   } else {
1386     SafeDisable (sfp->refine);
1387   }
1388   SetEnumPopup (sfp->target, sfp->dbalist, (UIEnum) db);
1389   SafeShow (sfp->target);
1390   SetPrevAndNextButtons (sfp);
1391   Update ();
1392   Hide (sfp->formats [MAX_DBS]);
1393   for (i = 0; i < MAX_DBS; i++) {
1394     if (i != db) {
1395       Hide (sfp->formats [i]);
1396     }
1397   }
1398   if (db < MAX_DBS) {
1399     Show (sfp->formats [db]);
1400   }
1401   if (num > 0) {
1402     sfp->uids = MemDup ((Pointer) uids, (size_t) (num * sizeof(DocUid)));
1403     if (sfp->uids == NULL) return;
1404     sfp->state = MemNew (sizeof (StateData) * (size_t) num);
1405     if (sfp->state == NULL) return;
1406     sfp->numUids = num;
1407     sfp->numParents = parents;
1408     sfp->currDb = db;
1409     Show (sfp->form);
1410     Select (sfp->form);
1411     RepopulateDocSum (sfp, FALSE);
1412     SetDocSumImportExportItems (sfp);
1413     SendMessageToForm (sfp->form, VIB_MSG_CHANGE);
1414 #ifdef WIN_MAC
1415     if (sfp->activate != NULL) {
1416       sfp->activate ((WindoW) sfp->form);
1417     }
1418 #endif
1419   } else {
1420     Show (sfp->form);
1421     Select (sfp->form);
1422 #ifdef WIN_MAC
1423     if (sfp->activate != NULL) {
1424       sfp->activate ((WindoW) sfp->form);
1425     }
1426 #endif
1427   }
1428   Update ();
1429 }
1430 
RetrieveDocuments(ForM f,Int2 num,Int2 parents,Int4Ptr uids,Int2 db)1431 extern void RetrieveDocuments (ForM f, Int2 num, Int2 parents, Int4Ptr uids, Int2 db)
1432 
1433 {
1434   FILE         *fp;
1435   Char         path [PATH_MAX];
1436   SummFormPtr  sfp;
1437   Int2         val;
1438 
1439   sfp = (SummFormPtr) GetObjectExtra (f);
1440   if (sfp == NULL) return;
1441   (sfp->generations)++;
1442   sfp->present = sfp->generations;
1443   if (sfp->historyFile == NULL) {
1444     TmpNam (path);
1445     sfp->historyFile = StringSave (path);
1446 #ifdef WIN_MAC
1447     if (sfp->historyFile != NULL) {
1448       FileCreate (sfp->historyFile, "????", "ENTZ");
1449     }
1450 #endif
1451   }
1452   if (sfp->historyOffsets == NULL) {
1453     sfp->historyOffsets = MemNew (100 * sizeof (Int4));
1454   }
1455   if (sfp->historyFile != NULL && sfp->historyOffsets != NULL) {
1456     fp = FileOpen (sfp->historyFile, "ab");
1457     if (fp != NULL) {
1458       fseek (fp, 0, SEEK_END);
1459       sfp->historyOffsets [(sfp->present) % 100] = ftell (fp);
1460       val = db;
1461       FileWrite (&val, sizeof (val), 1, fp);
1462       val = num;
1463       FileWrite (&val, sizeof (val), 1, fp);
1464       val = parents;
1465       FileWrite (&val, sizeof (val), 1, fp);
1466       FileWrite (uids, sizeof (Int4), (size_t) num, fp);
1467       FileClose (fp);
1468     } else {
1469       sfp->historyOffsets [sfp->present % 100] = 0;
1470     }
1471   }
1472   RetrieveGeneration (sfp, num, parents, uids, db);
1473 }
1474 
StripNewLine(CharPtr str)1475 static void StripNewLine (CharPtr str)
1476 
1477 {
1478   CharPtr  chptr;
1479 
1480   if (StringHasNoText (str)) return;
1481   chptr = StringRChr (str, '\n');
1482   if (chptr != NULL) {
1483     *chptr = '\0';
1484   }
1485   chptr = StringRChr (str, '\r');
1486   if (chptr != NULL) {
1487     *chptr = '\0';
1488   }
1489 }
1490 
DSLoadUidListProc(IteM i)1491 extern void DSLoadUidListProc (IteM i)
1492 
1493 {
1494   ByteStorePtr  bsp;
1495   Int2          db = -1;
1496   FILE          *fp;
1497   Int2          num;
1498   Char          path [PATH_MAX];
1499   SummFormPtr   sfp;
1500   Char          str [32];
1501   Int4          uid;
1502   Int4Ptr       uids;
1503 
1504 
1505 #ifdef WIN_MAC
1506   sfp = (SummFormPtr) currentFormDataPtr;
1507 #else
1508   sfp = (SummFormPtr) GetObjectExtra (i);
1509 #endif
1510   if (sfp == NULL) return;
1511   if (! GetInputFileName (path, sizeof (path), "", "TEXT")) return;
1512   fp = FileOpen (path, "r");
1513   if (fp == NULL) return;
1514   bsp = BSNew (128);
1515   if (bsp == NULL) {
1516     FileClose (fp);
1517     return;
1518   }
1519   if (FileGets (str, sizeof (str), fp)) {
1520     StripNewLine (str);
1521     if (StringStr (str, ">PubMed")) {
1522       db = 0;
1523     } else if (StringStr (str, ">Protein")) {
1524       db = 1;
1525     } else if (StringStr (str, ">Nucleotide")) {
1526       db = 2;
1527     } else if (StringStr (str, ">Structure")) {
1528       db = 3;
1529     } else if (StringStr (str, ">Genome")) {
1530       db = 4;
1531     }
1532     if (db != -1) {
1533       while (FileGets (str, sizeof (str), fp)) {
1534         StripNewLine (str);
1535         if (str [0] != '\0' && StrToLong (str, &uid)) {
1536           BSWrite (bsp, &uid, sizeof (DocUid));
1537         }
1538       }
1539       BSSeek (bsp, 0L, 0);
1540       num = (Int2) ((BSLen (bsp)) / sizeof (Int4));
1541       uids = (Int4Ptr) BSMerge (bsp, NULL);
1542       if (uids != NULL) {
1543         RetrieveDocuments (sfp->form, num, 0, uids, db);
1544       }
1545       MemFree (uids);
1546     } else {
1547       Message (MSG_POSTERR,
1548                "First line must be >PubMed, >Protein, >Nucleotide, >Structure, or >Genome");
1549     }
1550   }
1551   BSFree (bsp);
1552   FileClose (fp);
1553 }
1554 
DSSaveUidListProc(IteM i)1555 extern void DSSaveUidListProc (IteM i)
1556 
1557 {
1558   FILE         *fp;
1559   Int2         j;
1560   Char         path [PATH_MAX];
1561   SummFormPtr  sfp;
1562   Char         str [32];
1563 
1564 
1565 #ifdef WIN_MAC
1566   sfp = (SummFormPtr) currentFormDataPtr;
1567 #else
1568   sfp = (SummFormPtr) GetObjectExtra (i);
1569 #endif
1570   if (sfp == NULL || sfp->uids == NULL) return;
1571   if (! GetOutputFileName (path, sizeof (path), NULL)) return;
1572 #ifdef WIN_MAC
1573   FileCreate (path, "TEXT", "ttxt");
1574 #endif
1575   fp = FileOpen (path, "w");
1576   if (fp == NULL) return;
1577   WatchCursor ();
1578   switch (sfp->currDb) {
1579     case 0 :
1580       StringCpy (str, ">PubMed\n");
1581       break;
1582     case 1 :
1583       StringCpy (str, ">Protein\n");
1584       break;
1585     case 2 :
1586       StringCpy (str, ">Nucleotide\n");
1587       break;
1588     case 3 :
1589       StringCpy (str, ">Structure\n");
1590       break;
1591     case 4 :
1592       StringCpy (str, ">Genome\n");
1593       break;
1594     default :
1595       StringCpy (str, ">?\n");
1596       break;
1597   }
1598   FilePuts (str, fp);
1599   for (j = 0; j < sfp->numUids; j++) {
1600     sprintf (str, "%ld\n", (long) (sfp->uids [j]));
1601     FilePuts (str, fp);
1602   }
1603   FileClose (fp);
1604   ArrowCursor ();
1605 }
1606 
LoadPresentGeneration(SummFormPtr sfp)1607 static void LoadPresentGeneration (SummFormPtr sfp)
1608 
1609 {
1610   Int2     db;
1611   FILE     *fp;
1612   Int2     num;
1613   Int2     parents;
1614   Int4Ptr  uids;
1615 
1616   if (sfp == NULL) return;
1617   WatchCursor ();
1618   if (sfp->historyFile != NULL && sfp->historyOffsets != NULL) {
1619     fp = FileOpen (sfp->historyFile, "rb");
1620     if (fp != NULL) {
1621       fseek (fp, sfp->historyOffsets [(sfp->present) % 100], SEEK_SET);
1622       FileRead (&db, sizeof (db), 1, fp);
1623       FileRead (&num, sizeof (num), 1, fp);
1624       FileRead (&parents, sizeof (parents), 1, fp);
1625       uids = (Int4Ptr) MemNew ((size_t) num * sizeof (Int4) + 4);
1626       if (uids != NULL) {
1627         FileRead (uids, sizeof (Int4), (size_t) num, fp);
1628       }
1629       FileClose (fp);
1630       if (uids != NULL) {
1631         RetrieveGeneration (sfp, num, parents, uids, db);
1632         MemFree (uids);
1633       }
1634     }
1635   }
1636   ArrowCursor ();
1637 }
1638 
PrevProc(ButtoN b)1639 static void PrevProc (ButtoN b)
1640 
1641 {
1642   SummFormPtr  sfp;
1643 
1644   sfp = (SummFormPtr) GetObjectExtra (b);
1645   if (sfp == NULL) return;
1646   (sfp->present)--;
1647   if (sfp->present < 1) {
1648     sfp->present = 1;
1649   }
1650   SetPrevAndNextButtons (sfp);
1651   LoadPresentGeneration (sfp);
1652   SetDocSumImportExportItems (sfp);
1653 }
1654 
NextProc(ButtoN b)1655 static void NextProc (ButtoN b)
1656 
1657 {
1658   SummFormPtr  sfp;
1659 
1660   sfp = (SummFormPtr) GetObjectExtra (b);
1661   if (sfp == NULL) return;
1662   (sfp->present)++;
1663   if (sfp->present > sfp->generations) {
1664     sfp->present = sfp->generations;
1665   }
1666   SetPrevAndNextButtons (sfp);
1667   LoadPresentGeneration (sfp);
1668   SetDocSumImportExportItems (sfp);
1669 }
1670 
UsingDelayedNeighbor(ForM f)1671 extern Boolean UsingDelayedNeighbor (ForM f)
1672 
1673 {
1674   SummFormPtr  sfp;
1675 
1676   sfp = (SummFormPtr) GetObjectExtra (f);
1677   if (sfp == NULL) return FALSE;
1678   return sfp->usingDelay;
1679 }
1680 
UseDelayedNeighbor(ForM f,Boolean delayMode)1681 extern void UseDelayedNeighbor (ForM f, Boolean delayMode)
1682 
1683 {
1684   SummFormPtr  sfp;
1685 
1686   sfp = (SummFormPtr) GetObjectExtra (f);
1687   if (sfp == NULL) return;
1688   sfp->usingDelay = delayMode;
1689 }
1690 
NeighborDelayProc(ChoicE c)1691 static void NeighborDelayProc (ChoicE c)
1692 
1693 {
1694   SummFormPtr  sfp;
1695 
1696 #ifdef WIN_MAC
1697   sfp = (SummFormPtr) currentFormDataPtr;
1698 #else
1699   sfp = (SummFormPtr) GetObjectExtra (c);
1700 #endif
1701   if (sfp == NULL) return;
1702   if (GetValue (c) == 1) {
1703     sfp->usingDelay = FALSE;
1704   } else {
1705     sfp->usingDelay = TRUE;
1706   }
1707 }
1708 
CreateNeighborDelayChoice(MenU m,BaseFormPtr bfp)1709 extern ChoicE CreateNeighborDelayChoice (MenU m, BaseFormPtr bfp)
1710 
1711 {
1712   ChoicE  c;
1713 
1714   c = ChoiceGroup (m, NeighborDelayProc);
1715   SetObjectExtra (c, bfp, NULL);
1716   ChoiceItem (c, "Immediate");
1717   ChoiceItem (c, "Delayed");
1718   SetValue (c, 1);
1719   return c;
1720 }
1721 
RecalculateDocSum(SummFormPtr sfp)1722 static void RecalculateDocSum (SummFormPtr sfp)
1723 
1724 {
1725   Int2        i;
1726   LinkSetPtr  lsp;
1727   Int2        num;
1728   Int2        targetDb;
1729   Char        title [32];
1730   Int4Ptr     uids;
1731   UIEnum      val;
1732 
1733   if (sfp == NULL) return;
1734   if (GetEnumPopup (sfp->target, sfp->dbalist, &val)) {
1735     targetDb = (Int2) val;
1736   } else {
1737     targetDb = sfp->currDb;
1738   }
1739   if (sfp->uids == NULL || sfp->state == NULL) {
1740     if (targetDb == sfp->currDb) {
1741       SafeSetTitle (sfp->retrieve, "Neighbor 0");
1742     } else {
1743       SafeSetTitle (sfp->retrieve, "Lookup 0");
1744     }
1745     SafeDisable (sfp->retrieve);
1746     return;
1747   }
1748   sfp->neighbors = MemFree (sfp->neighbors);
1749   sfp->numNeighbors = 0;
1750   sfp->neighborDb = targetDb;
1751 
1752   uids = NULL;
1753   num = 0;
1754   for (i = 0; i < sfp->numUids; i++) {
1755     if (sfp->state [i].checked) {
1756       num++;
1757     }
1758   }
1759 
1760   if (sfp->retrieveMode == EVAL_MODE && sfp->usingDelay) {
1761     if (num == 0) {
1762       if (targetDb == sfp->currDb) {
1763         SafeSetTitle (sfp->retrieve,  "Neighbor 0");
1764        } else {
1765         SafeSetTitle (sfp->retrieve, "Lookup 0");
1766        }
1767        SafeDisable (sfp->retrieve);
1768     } else {
1769       SafeSetTitle (sfp->retrieve, "Evaluate");
1770       SafeEnable (sfp->retrieve);
1771     }
1772     if (num == 0) {
1773       num = sfp->numUids;
1774     }
1775     sprintf (title, "Refine %d", (int) num);
1776     SafeSetTitle (sfp->refine, title);
1777     if (num > 0) {
1778       SafeEnable (sfp->refine);
1779     } else {
1780       SafeDisable (sfp->refine);
1781     }
1782     return;
1783   }
1784 
1785   if (num > 0) {
1786     uids = MemNew ((size_t) (num + 1) * sizeof (DocUid));
1787     if (uids != NULL) {
1788       num = 0;
1789       for (i = 0; i < sfp->numUids; i++) {
1790         if (sfp->state [i].checked) {
1791           uids [num] = sfp->uids [i];
1792           num++;
1793         }
1794       }
1795       lsp = NULL;
1796       EntrezLinkUidList (&lsp, sfp->currDb, targetDb,
1797                          num, uids, FALSE);
1798       if (lsp != NULL) {
1799         sfp->numNeighbors = (Int2) lsp->num;
1800         sfp->neighbors = lsp->uids;
1801         lsp->uids = NULL;
1802         lsp->weights = MemFree (lsp->weights);
1803         LinkSetFree (lsp);
1804       }
1805     }
1806   }
1807   if (targetDb == sfp->currDb) {
1808     sprintf (title, "Neighbor %d", (int) sfp->numNeighbors);
1809   } else {
1810     sprintf (title, "Lookup %d", (int) sfp->numNeighbors);
1811   }
1812   SafeSetTitle (sfp->retrieve, title);
1813   if (sfp->numNeighbors > 0) {
1814     SafeEnable (sfp->retrieve);
1815   } else {
1816     SafeDisable (sfp->retrieve);
1817   }
1818   if (num == 0) {
1819     num = sfp->numUids;
1820   }
1821   sprintf (title, "Refine %d", (int) num);
1822   SafeSetTitle (sfp->refine, title);
1823   if (num > 0) {
1824     SafeEnable (sfp->refine);
1825   } else {
1826     SafeDisable (sfp->refine);
1827   }
1828   MemFree (uids);
1829 }
1830 
ChangeTarget(PopuP p)1831 static void ChangeTarget (PopuP p)
1832 
1833 {
1834   SummFormPtr  sfp;
1835 
1836   sfp = (SummFormPtr) GetObjectExtra (p);
1837   if (sfp == NULL) return;
1838   sfp->retrieveMode = EVAL_MODE;
1839   RecalculateDocSum (sfp);
1840 }
1841 
UidInList(Int4 uid,Int4Ptr sorted,Int2 num)1842 static Boolean UidInList (Int4 uid, Int4Ptr sorted, Int2 num)
1843 
1844 {
1845   Boolean  found;
1846   Int2     left;
1847   Int2     mid;
1848   Int2     right;
1849 
1850   found = FALSE;
1851   if (sorted != NULL && num > 0) {
1852     mid = 0;
1853     left = 0;
1854     right = num - 1;
1855     while (left <= right) {
1856       mid = (left + right) / 2;
1857       if (uid <= sorted [mid]) {
1858         right = mid - 1;
1859       }
1860       if (uid >= sorted [mid]) {
1861         left = mid + 1;
1862       }
1863     }
1864     if (left > right + 1) {
1865       found = TRUE;
1866     }
1867   }
1868   return found;
1869 }
1870 
RetrieveNeighbors(ButtoN b)1871 static void RetrieveNeighbors (ButtoN b)
1872 
1873 {
1874   EntrezGlobalsPtr  egp;
1875   Int2              i, j;
1876   Int2              num;
1877   Int2              parents;
1878   Boolean           persist;
1879   SummFormPtr       sfp;
1880   Int4Ptr           sorted;
1881   Int4              tmp;
1882   Int4Ptr           uids;
1883 
1884   sfp = (SummFormPtr) GetObjectExtra (b);
1885   if (sfp == NULL) return;
1886   if (sfp->retrieveMode == EVAL_MODE && sfp->usingDelay) {
1887     WatchCursor ();
1888     Update ();
1889     sfp->retrieveMode = FETCH_MODE;
1890     RecalculateDocSum (sfp);
1891     ArrowCursor ();
1892     Update ();
1893     return;
1894   }
1895   egp = (EntrezGlobalsPtr) GetAppProperty ("EntrezGlobals");
1896   if (egp == NULL || egp->retrieveDocsProc == NULL) return;
1897   persist = FALSE;
1898   if (sfp->currDb == sfp->neighborDb) {
1899     persist = GetStatus (egp->parentsPersist);
1900   }
1901   parents = 0;
1902   if (persist) {
1903     for (i = 0; i < sfp->numUids; i++) {
1904       if (sfp->state [i].checked) {
1905         parents++;
1906       }
1907     }
1908   }
1909   uids = NULL;
1910   sorted = NULL;
1911   num = parents + sfp->numNeighbors;
1912   if (num > 0) {
1913     uids = MemNew ((size_t) (num + 1) * sizeof (DocUid));
1914     sorted = MemNew ((size_t) (parents + 1) * sizeof (DocUid));
1915     if (uids != NULL && sorted != NULL) {
1916       num = 0;
1917       if (persist && sfp->uids != NULL) {
1918         for (i = 0; i < sfp->numUids; i++) {
1919           if (sfp->state [i].checked) {
1920             uids [num] = sfp->uids [i];
1921             sorted [num] = sfp->uids [i];
1922             num++;
1923           }
1924         }
1925         for (i = 1; i < parents; i++) {
1926           for (j = 0; j < i; j++) {
1927             if (sorted [j] > sorted [i]) {
1928               tmp = sorted [i];
1929               sorted [i] = sorted [j];
1930               sorted [j] = tmp;
1931             }
1932           }
1933         }
1934       }
1935       if (sfp->neighbors != NULL) {
1936         for (i = 0; i < sfp->numNeighbors; i++) {
1937           if (! UidInList (sfp->neighbors [i], sorted, parents)) {
1938             uids [num] = sfp->neighbors [i];
1939             num++;
1940           }
1941         }
1942       }
1943     }
1944   }
1945   sfp->neighbors = NULL;
1946   sfp->numNeighbors = 0;
1947   egp->retrieveDocsProc (sfp->form, num, parents, uids, sfp->neighborDb);
1948   MemFree (uids);
1949   MemFree (sorted);
1950 }
1951 
1952 static int refinement = 0; /* guarantees that each refinement has a unique name */
1953 
RefineProc(ButtoN b)1954 static void RefineProc (ButtoN b)
1955 
1956 {
1957   EntrezGlobalsPtr  egp;
1958   Int2              i;
1959   Int2              num;
1960   SummFormPtr       sfp;
1961   Char              str [64];
1962   Int4Ptr           uids;
1963 
1964   sfp = (SummFormPtr) GetObjectExtra (b);
1965   if (sfp == NULL) return;
1966   egp = (EntrezGlobalsPtr) GetAppProperty ("EntrezGlobals");
1967   if (egp == NULL || egp->loadNamedUidProc == NULL) return;
1968   num = 0;
1969   for (i = 0; i < sfp->numUids; i++) {
1970     if (sfp->state [i].checked) {
1971       num++;
1972     }
1973   }
1974   refinement++;
1975   sprintf (str, "*generation_%d_refinement_%d", (int) sfp->present, (int) refinement);
1976   if (num > 0) {
1977     uids = MemNew ((size_t) (num + 1) * sizeof (DocUid));
1978     if (uids != NULL) {
1979       num = 0;
1980       for (i = 0; i < sfp->numUids; i++) {
1981         if (sfp->state [i].checked) {
1982           uids [num] = sfp->uids [i];
1983           num++;
1984         }
1985       }
1986       egp->loadNamedUidProc (sfp->form, str, num, uids, sfp->currDb);
1987     }
1988     MemFree (uids);
1989   } else {
1990     egp->loadNamedUidProc (sfp->form, str, sfp->numUids, sfp->uids, sfp->currDb);
1991   }
1992 }
1993 
CopyDocsumToClipboard(BaseFormPtr bfp)1994 static void CopyDocsumToClipboard (BaseFormPtr bfp)
1995 
1996 {
1997   FILE         *fp;
1998   Int2         i;
1999   Boolean      newline;
2000   Int2         num;
2001   Char         path [PATH_MAX];
2002   SummFormPtr  sfp;
2003 
2004   sfp = (SummFormPtr) bfp;
2005   if (sfp == NULL) return;
2006   TmpNam (path);
2007   fp = FileOpen (path, "w");
2008   if (fp != NULL) {
2009     num = 0;
2010     for (i = 0; i < sfp->numUids; i++) {
2011       if (sfp->state [i].checked) {
2012         num++;
2013       }
2014     }
2015     if (num == 0) {
2016       SaveDocument (sfp->docsum, fp);
2017     } else {
2018       newline = FALSE;
2019       for (i = 0; i < sfp->numUids; i++) {
2020         if (sfp->state [i].checked) {
2021           if (newline) {
2022             fputc ('\n', fp);
2023           }
2024           SaveDocumentItem (sfp->docsum, fp, i + 1);
2025           newline = TRUE;
2026         }
2027       }
2028     }
2029     FileClose (fp);
2030     FileToClipboard (path);
2031   }
2032   FileRemove (path);
2033 }
2034 
ClickDocSum(DoC d,PoinT pt)2035 static void ClickDocSum (DoC d, PoinT pt)
2036 
2037 {
2038   Int2         col;
2039   Int2         item;
2040   Int2         row;
2041   SummFormPtr  sfp;
2042 
2043   sfp = (SummFormPtr) GetObjectExtra (d);
2044   if (sfp == NULL) return;
2045   MapDocPoint (d, pt, &item, &row, &col, NULL);
2046   sfp->dsClickItem = item;
2047   sfp->dsClickRow = row;
2048   sfp->dsClickCol = col;
2049   sfp->wasDoubleClick = dblClick;
2050 }
2051 
GetCheckedUids(SummFormPtr sfp,Int2Ptr nump)2052 static Int4Ptr GetCheckedUids (SummFormPtr sfp, Int2Ptr nump)
2053 
2054 {
2055   Int2     i;
2056   Int2     num;
2057   Int4Ptr  uids;
2058 
2059   if (sfp == NULL || nump == NULL) return NULL;
2060   uids = NULL;
2061   num = 0;
2062   for (i = 0; i < sfp->numUids; i++) {
2063     if (sfp->state [i].checked) {
2064       num++;
2065     }
2066   }
2067   if (num > 0) {
2068     uids = MemNew ((size_t) (num + 1) * sizeof (DocUid));
2069     if (uids != NULL) {
2070       num = 0;
2071       for (i = 0; i < sfp->numUids; i++) {
2072         if (sfp->state [i].checked) {
2073           uids [num] = sfp->uids [i];
2074           num++;
2075         }
2076       }
2077     }
2078   }
2079   if (nump != NULL) {
2080     *nump = num;
2081   }
2082   return uids;
2083 }
2084 
ReleaseDocSum(DoC d,PoinT pt)2085 static void ReleaseDocSum (DoC d, PoinT pt)
2086 
2087 {
2088   Int2              checked;
2089   Int2              col;
2090   Int2              db;
2091   EntrezGlobalsPtr  egp;
2092   Int2              item;
2093   Int2              num;
2094   RecT              r;
2095   Int2              row;
2096   SummFormPtr       sfp;
2097   Int4              uid;
2098   Int4Ptr           uids;
2099 
2100   sfp = (SummFormPtr) GetObjectExtra (d);
2101   if (sfp == NULL) return;
2102   egp = (EntrezGlobalsPtr) GetAppProperty ("EntrezGlobals");
2103   if (egp == NULL || egp->launchViewerProc == NULL) return;
2104   MapDocPoint (d, pt, &item, &row, &col, &r);
2105   if (item < 1 || item > sfp->numUids || row == 0 || col == 0) return;
2106   if (sfp->dsClickItem != item) return;
2107   if (row == 1 && col == 1 &&
2108       sfp->dsClickRow == 1 && sfp->dsClickCol == 1) {
2109     r.right = r.left + sfp->lineHeight;
2110     r.bottom = r.top + sfp->lineHeight;
2111     if (PtInRect (pt, &r)) {
2112       checked = sfp->state [item - 1].checked;
2113       sfp->state [item - 1].checked = (Boolean) (! checked);
2114       ObjectRect (d, &r);
2115       InsetRect (&r, 4, 4);
2116       r.right = r.left + sfp->lineHeight;
2117       InsetRect (&r, -1, -1);
2118       InvalRect (&r);
2119       ResetClip ();
2120       WatchCursor ();
2121       Update ();
2122       sfp->retrieveMode = EVAL_MODE;
2123       RecalculateDocSum (sfp);
2124       ArrowCursor ();
2125       Update ();
2126       return;
2127     }
2128   }
2129   if (sfp->wasDoubleClick && sfp->uids != NULL && sfp->simple == NULL) {
2130     db = sfp->currDb;
2131     uid = sfp->uids [item - 1];
2132     uids = GetCheckedUids (sfp, &num);
2133     egp->launchViewerProc (sfp->form, uid, num, uids, db);
2134     MemFree (uids);
2135   }
2136 }
2137 
RefreshAndRecalculateDocSum(SummFormPtr sfp)2138 static void RefreshAndRecalculateDocSum (SummFormPtr sfp)
2139 
2140 {
2141     RecT  r;
2142 
2143   if (sfp == NULL) return;
2144   Select (sfp->docsum);
2145   ObjectRect (sfp->docsum, &r);
2146   InsetRect (&r, 4, 4);
2147   r.right = r.left + sfp->lineHeight;
2148   InsetRect (&r, -1, -1);
2149   InvalRect (&r);
2150   ResetClip ();
2151   WatchCursor ();
2152   Update ();
2153   sfp->retrieveMode = EVAL_MODE;
2154   RecalculateDocSum (sfp);
2155   ArrowCursor ();
2156   Update ();
2157 }
2158 
SelectAllProc(ButtoN b)2159 static void SelectAllProc (ButtoN b)
2160 
2161 {
2162   Int2         i;
2163   SummFormPtr  sfp;
2164 
2165   sfp = (SummFormPtr) GetObjectExtra (b);
2166   if (sfp == NULL) return;
2167   for (i = 0; i < sfp->numUids; i++) {
2168     sfp->state [i].checked = TRUE;
2169   }
2170   RefreshAndRecalculateDocSum (sfp);
2171 }
2172 
SelectParentsProc(ButtoN b)2173 static void SelectParentsProc (ButtoN b)
2174 
2175 {
2176   Int2         i;
2177   SummFormPtr  sfp;
2178 
2179   sfp = (SummFormPtr) GetObjectExtra (b);
2180   if (sfp == NULL) return;
2181   for (i = 0; i < sfp->numUids; i++) {
2182     sfp->state [i].checked = (Boolean) (i < sfp->numParents);
2183   }
2184   RefreshAndRecalculateDocSum (sfp);
2185 }
2186 
ClearAllProc(ButtoN b)2187 static void ClearAllProc (ButtoN b)
2188 
2189 {
2190   Int2         i;
2191   SummFormPtr  sfp;
2192 
2193   sfp = (SummFormPtr) GetObjectExtra (b);
2194   if (sfp == NULL) return;
2195   for (i = 0; i < sfp->numUids; i++) {
2196     sfp->state [i].checked = FALSE;
2197   }
2198   RefreshAndRecalculateDocSum (sfp);
2199 }
2200 
ChangeFormat(GrouP g)2201 static void ChangeFormat (GrouP g)
2202 
2203 {
2204   SummFormPtr  sfp;
2205 
2206   sfp = (SummFormPtr) GetObjectExtra (g);
2207   if (sfp == NULL) return;
2208   RepopulateDocSum (sfp, TRUE);
2209   SetDocSumImportExportItems (sfp);
2210 }
2211 
2212 static CharPtr medRadios [] = {"Summary", "Abstract", "Citation", "MEDLINE", "PubMed ID", NULL};
2213 
2214 static CharPtr prtRadios [] = {"Summary", "GenPept", "FASTA", "Protein ID", NULL};
2215 
2216 static CharPtr nucRadios [] = {"Summary", "GenBank", "EMBL", "FASTA", "Nucleotide ID", NULL};
2217 
2218 static CharPtr strucRadios [] = {"Summary", "Report", "Structure ID", NULL};
2219 
2220 static CharPtr genRadios [] = {"Summary", "Genome ID", NULL};
2221 
2222 static CharPtr localBioseqRadios [] = {"FASTA", NULL};
2223 
2224 static CharPtr PNTR  radioLabels [] = {
2225   medRadios, prtRadios, nucRadios, strucRadios, genRadios, NULL
2226 };
2227 
ProcessProjectAsn(ProjectPtr proj)2228 static void ProcessProjectAsn (ProjectPtr proj)
2229 
2230 {
2231   Int2              db = -1;
2232   EntrezGlobalsPtr  egp;
2233   Int4              i;
2234   ValNodePtr        list;
2235   Int4              num;
2236   ValNodePtr        pip;
2237   Int4Ptr           uids;
2238   ValNodePtr        vnp;
2239 
2240   if (proj == NULL) return;
2241   egp = (EntrezGlobalsPtr) GetAppProperty ("EntrezGlobals");
2242   if (egp == NULL) return;
2243   pip = proj->data;
2244   if (pip == NULL) return;
2245   list = (ValNodePtr) pip->data.ptrvalue;
2246   if (list == NULL) return;
2247   if (pip->choice >= ProjectItem_protent && pip->choice <= ProjectItem_genomeent) {
2248     if (egp->retrieveProjectProc == NULL) return;
2249     egp->retrieveProjectProc (NULL, (Pointer) proj);
2250     Update ();
2251     return;
2252   }
2253   if (egp->retrieveDocsProc == NULL) return;
2254   switch (pip->choice) {
2255     case ProjectItem_pmuid :
2256       db = 0;
2257       break;
2258     case ProjectItem_protuid :
2259       db = 1;
2260       break;
2261     case ProjectItem_nucuid :
2262       db = 2;
2263       break;
2264     case ProjectItem_genomeuid :
2265       db = 4;
2266       break;
2267     case ProjectItem_structuid :
2268       db = 3;
2269       break;
2270     default :
2271       break;
2272   }
2273   if (db == -1) return;
2274   num = ValNodeLen (list);
2275   uids = MemNew ((size_t) (num * sizeof (Int4)));
2276   if (uids == NULL) return;
2277   for (i = 0, vnp = list; i < 32766 && vnp != NULL; i++, vnp = vnp->next) {
2278     uids [i] = vnp->data.intvalue;
2279   }
2280   if (egp->retrieveDocsProc != NULL) {
2281     egp->retrieveDocsProc (NULL, (Int2) num, 0, uids, db);
2282   }
2283   MemFree (uids);
2284   Update ();
2285 }
2286 
ImportDocSumForm(ForM f,CharPtr filename)2287 static Boolean ImportDocSumForm (ForM f, CharPtr filename)
2288 
2289 {
2290   Uint1             choice = 0;
2291   Pointer           dataptr;
2292   Uint2             datatype;
2293   EntrezGlobalsPtr  egp;
2294   FILE              *fp;
2295   ValNodePtr        head = NULL;
2296   Boolean           is_na = TRUE;
2297   Char              path [PATH_MAX];
2298   SeqEntryPtr       sephead = NULL;
2299   ValNodePtr        simples;
2300   SummFormPtr       sfp;
2301   ValNodePtr        vnp;
2302 
2303   path [0] = '\0';
2304   StringNCpy_0 (path, filename, sizeof (path));
2305   sfp = (SummFormPtr) GetObjectExtra (f);
2306   if (sfp != NULL) {
2307     if (path [0] != '\0' || GetInputFileName (path, sizeof (path), "", "TEXT")) {
2308       fp = FileOpen (path, "r");
2309       if (fp != NULL) {
2310         while ((dataptr = ReadAsnFastaOrFlatFile (fp, &datatype, NULL, FALSE,
2311                                                   FALSE, TRUE, TRUE)) != NULL) {
2312           ValNodeAddPointer (&head, datatype, dataptr);
2313         }
2314         FileClose (fp);
2315         simples = ValNodeExtractList (&head, OBJ_FASTA);
2316         if (simples != NULL) {
2317           egp = (EntrezGlobalsPtr) GetAppProperty ("EntrezGlobals");
2318           if (egp != NULL && egp->retrieveSimpleProc != NULL) {
2319             egp->retrieveSimpleProc (NULL, simples);
2320           }
2321         }
2322         ValNodeFree (simples);
2323         if (head != NULL) {
2324           for (vnp = head; vnp != NULL; vnp = vnp->next) {
2325             datatype = vnp->choice;
2326             dataptr = vnp->data.ptrvalue;
2327             if (datatype == OBJ_PROJECT) {
2328               ProcessProjectAsn ((ProjectPtr) dataptr);
2329             }
2330           }
2331         }
2332         ValNodeFree (head);
2333         return TRUE;
2334       }
2335     }
2336   }
2337   return FALSE;
2338 }
2339 
ExportDocSumForm(ForM f,CharPtr filename)2340 static Boolean ExportDocSumForm (ForM f, CharPtr filename)
2341 
2342 {
2343   FILE          *fp;
2344   Int2          i;
2345   CharPtr PNTR  labels;
2346   Boolean       lastChoiceIsUidList = FALSE;
2347   MonitorPtr    mon;
2348   Boolean       newline;
2349   Int2          num;
2350   Char          path [PATH_MAX];
2351   SummFormPtr   sfp;
2352   Char          str [32];
2353   Int2          val;
2354 
2355   path [0] = '\0';
2356   StringNCpy_0 (path, filename, sizeof (path));
2357   sfp = (SummFormPtr) GetObjectExtra (f);
2358   if (sfp != NULL) {
2359     if (path [0] != '\0' || GetOutputFileName (path, sizeof (path), NULL)) {
2360 #ifdef WIN_MAC
2361       fp = FileOpen (path, "r");
2362       if (fp != NULL) {
2363         FileClose (fp);
2364       } else {
2365         FileCreate (path, "TEXT", "ttxt");
2366       }
2367 #endif
2368       fp = FileOpen (path, "w");
2369       if (fp != NULL) {
2370         WatchCursor ();
2371         Update ();
2372         if (sfp->simple != NULL) {
2373         } else if (sfp->currDb >= 0 && sfp->currDb < MAX_DBS) {
2374           labels = radioLabels [sfp->currDb];
2375           val = GetValue (sfp->formats [sfp->currDb]);
2376           if (val > 0) {
2377             if (labels [val] == NULL) {
2378               lastChoiceIsUidList = TRUE;
2379             }
2380           }
2381         }
2382         if (lastChoiceIsUidList) {
2383           switch (sfp->currDb) {
2384             case 0 :
2385               fprintf (fp, ">PubMed\n");
2386               break;
2387             case 1 :
2388               fprintf (fp, ">Protein\n");
2389               break;
2390             case 2 :
2391               fprintf (fp, ">Nucleotide\n");
2392               break;
2393             case 3 :
2394               fprintf (fp, ">Structure\n");
2395               break;
2396             case 4 :
2397               fprintf (fp, ">Genome\n");
2398               break;
2399             default :
2400               fprintf (fp, ">?\n");
2401               break;
2402           }
2403         }
2404         num = 0;
2405         for (i = 0; i < sfp->numUids; i++) {
2406           if (sfp->state [i].checked) {
2407             num++;
2408           }
2409         }
2410         if (lastChoiceIsUidList) {
2411           if (num == 0) {
2412             for (i = 0; i < sfp->numUids; i++) {
2413               sprintf (str, "%ld\n", (long) (sfp->uids [i]));
2414               FilePuts (str, fp);
2415             }
2416           } else {
2417             for (i = 0; i < sfp->numUids; i++) {
2418               if (sfp->state [i].checked) {
2419                 sprintf (str, "%ld\n", (long) (sfp->uids [i]));
2420                 FilePuts (str, fp);
2421               }
2422             }
2423           }
2424         } else {
2425           mon = MonitorIntNewEx ("Saving Documents", 0, sfp->numUids, FALSE);
2426           newline = FALSE;
2427           for (i = 0; i < sfp->numUids; i++) {
2428             if (num == 0 || sfp->state [i].checked) {
2429               if (newline) {
2430                 fputc ('\n', fp);
2431               }
2432               SaveDocumentItem (sfp->docsum, fp, i + 1);
2433               MonitorIntValue (mon, i);
2434               newline = TRUE;
2435             }
2436           }
2437           MonitorFree (mon);
2438         }
2439         FileClose (fp);
2440         sfp->filepath = MemFree (sfp->filepath);
2441         sfp->filepath = StringSave (path);
2442         ArrowCursor ();
2443         Update ();
2444         return TRUE;
2445       } else {
2446         Message (MSG_ERROR, "Unable to write file.");
2447         return FALSE;
2448       }
2449     }
2450   }
2451   return FALSE;
2452 }
2453 
PrintDocsumProc(BaseFormPtr bfp)2454 static void PrintDocsumProc (BaseFormPtr bfp)
2455 
2456 {
2457   SummFormPtr  sfp;
2458 
2459   if (bfp == NULL) return;
2460   sfp = (SummFormPtr) bfp;
2461   WatchCursor ();
2462   Update ();
2463   PrintDocument (sfp->docsum);
2464   ArrowCursor ();
2465   Update ();
2466 }
2467 
LoadDocsumOptionsMenu(MenU m)2468 extern void LoadDocsumOptionsMenu (MenU m)
2469 
2470 {
2471   EntrezGlobalsPtr  egp;
2472   MenU              sub;
2473 
2474   egp = (EntrezGlobalsPtr) GetAppProperty ("EntrezGlobals");
2475   if (egp == NULL) return;
2476   egp->parentsPersist = StatusItem (m, "Parents Persist", NULL);
2477   SetStatus (egp->parentsPersist, egp->persistDefault);
2478   egp->alignWithChecked = StatusItem (m, "Align Checked Items", NULL);
2479   SetStatus (egp->alignWithChecked, egp->alignDefault);
2480   SeparatorItem (m);
2481   /*
2482   sub = SubMenu (m, "Sequence Complexity");
2483   egp->seqComplex = ChoiceGroup (sub, NULL);
2484   ChoiceItem (egp->seqComplex, "NucProt");
2485   ChoiceItem (egp->seqComplex, "SegSet");
2486   ChoiceItem (egp->seqComplex, "BioSeq");
2487   SetValue (egp->seqComplex, 2);
2488   SeparatorItem (m);
2489   */
2490   sub = SubMenu (m, "Structure Complexity");
2491   egp->strucComplex = ChoiceGroup (sub, NULL);
2492   ChoiceItem (egp->strucComplex, "NCBI one XYZ per atom model");
2493   ChoiceItem (egp->strucComplex, "NCBI backbone model");
2494   ChoiceItem (egp->strucComplex, "Original PDB models 1-n");
2495   ChoiceItem (egp->strucComplex, "NCBI vector model");
2496   ChoiceItem (egp->strucComplex, "Everything");
2497   SetValue (egp->strucComplex, 1);
2498   sub = SubMenu (m, "Number of Models");
2499   egp->strucModels = ChoiceGroup (sub, NULL);
2500   ChoiceItem (egp->strucModels, "1");
2501   ChoiceItem (egp->strucModels, "2");
2502   ChoiceItem (egp->strucModels, "5");
2503   ChoiceItem (egp->strucModels, "10");
2504   ChoiceItem (egp->strucModels, "15");
2505   ChoiceItem (egp->strucModels, "20");
2506   ChoiceItem (egp->strucModels, "maximum");
2507   SetValue (egp->strucModels, 7);
2508 }
2509 
DocSumFontChangeProc(IteM i)2510 extern void DocSumFontChangeProc (IteM i)
2511 
2512 {
2513   BaseFormPtr       bfp;
2514   EntrezGlobalsPtr  egp;
2515   Uint2             flags;
2516   FonT              fnt;
2517   FontSpec          fs;
2518   Char              str [FONT_NAME_SIZE + 10];
2519 
2520   egp = (EntrezGlobalsPtr) GetAppProperty ("EntrezGlobals");
2521 #ifdef WIN_MAC
2522   bfp = currentFormDataPtr;
2523 #else
2524   bfp = GetObjectExtra (i);
2525 #endif
2526   if (bfp != NULL) {
2527     MemSet ((Pointer) (&fs), 0, sizeof (FontSpec));
2528     fnt = programFont;
2529     if (egp != NULL && egp->docsumFont != NULL) {
2530       fnt = egp->docsumFont;
2531     }
2532     flags = 0;
2533     fs.name [0] = '\0';
2534     fs.size = 0;
2535     fs.style = 0;
2536     fs.charset = 0;
2537     fs.pitch = 0;
2538     fs.family = 0;
2539     if (GetFontSpec (fnt, &fs)) {
2540       flags = CFF_READ_FSP;
2541     }
2542     if (ChooseFont (&fs, flags, NULL)) {
2543       sprintf (str, "%s,%d", fs.name, (int) fs.size);
2544       if ((fs.style & STYLE_BOLD) != 0 ||
2545           (fs.style & STYLE_ITALIC) != 0 ||
2546           (fs.style & STYLE_UNDERLINE) != 0) {
2547         StringCat (str, ",");
2548         if ((fs.style & STYLE_BOLD) != 0) {
2549           StringCat (str, "b");
2550         }
2551         if ((fs.style & STYLE_ITALIC) != 0) {
2552           StringCat (str, "i");
2553         }
2554         if ((fs.style & STYLE_UNDERLINE) != 0) {
2555           StringCat (str, "u");
2556         }
2557       }
2558       /* SetEntrezAppParam ("FONTS", "FETCHED", str); */
2559       if (egp != NULL) {
2560         egp->docsumFont = CreateFont (&fs);
2561       }
2562       SendMessageToForm (bfp->form, VIB_MSG_REDRAW);
2563     }
2564   }
2565 }
2566 
DisplayFontChangeProc(IteM i)2567 extern void DisplayFontChangeProc (IteM i)
2568 
2569 {
2570   BaseFormPtr          bfp;
2571   Uint2                flags;
2572   FonT                 fnt;
2573   FontSpec             fs;
2574   MedlineViewProcsPtr  mvpp;
2575   Char                 str [FONT_NAME_SIZE + 10];
2576   SeqViewProcsPtr      svpp;
2577 
2578   svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
2579   mvpp = (MedlineViewProcsPtr) GetAppProperty ("MedlineDisplayForm");
2580 #ifdef WIN_MAC
2581   bfp = currentFormDataPtr;
2582 #else
2583   bfp = GetObjectExtra (i);
2584 #endif
2585   if (bfp != NULL) {
2586     MemSet ((Pointer) (&fs), 0, sizeof (FontSpec));
2587     fnt = programFont;
2588     if (svpp != NULL && svpp->displayFont != NULL) {
2589       fnt = svpp->displayFont;
2590     } else if (mvpp != NULL && mvpp->displayFont != NULL) {
2591       fnt = mvpp->displayFont;
2592     }
2593     flags = 0;
2594     fs.name [0] = '\0';
2595     fs.size = 0;
2596     fs.style = 0;
2597     fs.charset = 0;
2598     fs.pitch = 0;
2599     fs.family = 0;
2600     if (GetFontSpec (fnt, &fs)) {
2601       flags = CFF_READ_FSP | CFF_MONOSPACE;
2602     }
2603     if (ChooseFont (&fs, flags, NULL)) {
2604       sprintf (str, "%s,%d", fs.name, (int) fs.size);
2605       if ((fs.style & STYLE_BOLD) != 0 ||
2606           (fs.style & STYLE_ITALIC) != 0 ||
2607           (fs.style & STYLE_UNDERLINE) != 0) {
2608         StringCat (str, ",");
2609         if ((fs.style & STYLE_BOLD) != 0) {
2610           StringCat (str, "b");
2611         }
2612         if ((fs.style & STYLE_ITALIC) != 0) {
2613           StringCat (str, "i");
2614         }
2615         if ((fs.style & STYLE_UNDERLINE) != 0) {
2616           StringCat (str, "u");
2617         }
2618       }
2619       /* SetEntrezAppParam ("FONTS", "DISPLAY", str); */
2620       if (svpp != NULL) {
2621         svpp->displayFont = CreateFont (&fs);
2622       }
2623       if (mvpp != NULL) {
2624         mvpp->displayFont = CreateFont (&fs);
2625       }
2626       SendMessageToForm (bfp->form, VIB_MSG_REDRAW);
2627     }
2628   }
2629 }
2630 
DocSumCanSaveFasta(ForM f,Boolean nucs,Boolean prots)2631 extern Boolean DocSumCanSaveFasta (ForM f, Boolean nucs, Boolean prots)
2632 
2633 {
2634   Int2          i;
2635   SummFormPtr   sfp;
2636   SimpleSeqPtr  ssp;
2637 
2638   sfp = (SummFormPtr) GetObjectExtra (f);
2639   if (sfp == NULL) return FALSE;
2640   if (sfp->uids != NULL && sfp->simple == NULL) {
2641     switch (sfp->currDb) {
2642       case 1 :
2643         if (prots) return TRUE;
2644         break;
2645       case 2 :
2646       case 4 :
2647         if (nucs) return TRUE;
2648         break;
2649       default :
2650         break;
2651     }
2652   } else if (sfp->simple != NULL && sfp->uids == NULL) {
2653     for (i = 0; i < sfp->numUids; i++) {
2654       ssp = sfp->simple [i];
2655       if (ssp != NULL) {
2656         return TRUE;
2657       }
2658     }
2659     return FALSE;
2660   }
2661   return FALSE;
2662 }
2663 
ExportDocSumFasta(ForM f,CharPtr filename,Boolean nucs,Boolean prots)2664 extern Boolean ExportDocSumFasta (ForM f, CharPtr filename, Boolean nucs, Boolean prots)
2665 
2666 {
2667   BioseqPtr     bsp;
2668   Boolean       fastaOK = FALSE;
2669   Boolean       fastaNucOK;
2670   Boolean       fastaPrtOK;
2671   FILE          *fp;
2672   Uint1         group_segs;
2673   Int2          i;
2674   Int2          num;
2675   Char          path [PATH_MAX];
2676   SeqEntryPtr   sep;
2677   SummFormPtr   sfp;
2678   SimpleSeqPtr  ssp;
2679   Int4          uid;
2680 
2681   path [0] = '\0';
2682   StringNCpy_0 (path, filename, sizeof (path));
2683   sfp = (SummFormPtr) GetObjectExtra (f);
2684   if (sfp != NULL) {
2685     if (path [0] != '\0' || GetOutputFileName (path, sizeof (path), NULL)) {
2686 #ifdef WIN_MAC
2687       fp = FileOpen (path, "r");
2688       if (fp != NULL) {
2689         FileClose (fp);
2690       } else {
2691         FileCreate (path, "TEXT", "ttxt");
2692       }
2693 #endif
2694       fp = FileOpen (path, "w");
2695       if (fp != NULL) {
2696         WatchCursor ();
2697         Update ();
2698         num = 0;
2699         for (i = 0; i < sfp->numUids; i++) {
2700           if (sfp->state [i].checked) {
2701             num++;
2702           }
2703         }
2704         for (i = 0; i < sfp->numUids; i++) {
2705           fastaNucOK = FALSE;
2706           fastaPrtOK = FALSE;
2707           if (sfp->state [i].checked || num == 0) {
2708             if (sfp->uids != NULL && sfp->simple == NULL) {
2709               uid = sfp->uids [i];
2710               bsp = BioseqLockByGi (uid);
2711               if (bsp != NULL) {
2712                 sep = SeqMgrGetSeqEntryForData (bsp);
2713                 if (sep != NULL) {
2714                   if (ISA_na (bsp->mol) && nucs) {
2715                     group_segs = 0;
2716                     if (bsp->repr == Seq_repr_seg) {
2717                       group_segs = 1;
2718                     } else if (bsp->repr == Seq_repr_delta) {
2719                       group_segs = 3;
2720                     }
2721                     fastaNucOK = SeqnSeqEntrysToFasta (sep, fp, TRUE, group_segs);
2722                   }
2723                   if (ISA_aa (bsp->mol) && prots) {
2724                     fastaPrtOK = SeqnSeqEntrysToFasta (sep, fp, FALSE, 0);
2725                   }
2726                 }
2727               }
2728               BioseqUnlockByGi (uid);
2729             } else if (sfp->simple != NULL && sfp->uids == NULL) {
2730               ssp = sfp->simple [i];
2731               if (ssp != NULL) {
2732                 SimpleSeqPrint (ssp, fp, TRUE);
2733               }
2734             }
2735           }
2736           fastaOK |= fastaNucOK || fastaPrtOK;
2737         }
2738         FileClose (fp);
2739         ArrowCursor ();
2740         Update ();
2741         return fastaOK;
2742       }
2743     }
2744   }
2745   return FALSE;
2746 }
2747 
RetrieveSimpleSeqs(ForM f,ValNodePtr simpleSeqs)2748 extern void RetrieveSimpleSeqs (ForM f, ValNodePtr simpleSeqs)
2749 
2750 {
2751   Int4         i;
2752   Int4         num;
2753   SummFormPtr  sfp;
2754   ValNodePtr   vnp;
2755 
2756   sfp = (SummFormPtr) GetObjectExtra (f);
2757   if (sfp == NULL) return;
2758   Reset (sfp->docsum);
2759   SetDocShade (sfp->docsum, NULL, NULL, NULL, NULL);
2760   SetDocCache (sfp->docsum, NULL, NULL, NULL);
2761   sfp->uids = MemFree (sfp->uids);
2762   if (sfp->simple != NULL) {
2763     for (i = 0; i < sfp->numUids; i++) {
2764       SimpleSeqFree (sfp->simple [i]);
2765     }
2766     sfp->simple = MemFree (sfp->simple);
2767   }
2768   sfp->state = MemFree (sfp->state);
2769   sfp->numUids = 0;
2770   sfp->numParents = 0;
2771   sfp->neighbors = MemFree (sfp->neighbors);
2772   sfp->numNeighbors = 0;
2773   SafeSetTitle (sfp->retrieve, "Neighbor 0");
2774   SafeDisable (sfp->retrieve);
2775   SafeSetTitle (sfp->refine, "Refine 0");
2776   SafeDisable (sfp->refine);
2777   SafeHide (sfp->target);
2778   SetValue (sfp->target, 0);
2779   SetPrevAndNextButtons (sfp);
2780   Update ();
2781   for (i = 0; i < MAX_DBS; i++) {
2782     Hide (sfp->formats [i]);
2783   }
2784   Show (sfp->formats [MAX_DBS]);
2785   if (simpleSeqs == NULL) return;
2786   num = ValNodeLen (simpleSeqs);
2787   if (num > 0) {
2788     sfp->simple = MemNew ((size_t) (num * sizeof (SimpleSeqPtr)));
2789     if (sfp->simple == NULL) {
2790       Show (sfp->form);
2791       Select (sfp->form);
2792       SendMessageToForm (sfp->form, VIB_MSG_CHANGE);
2793 #ifdef WIN_MAC
2794       if (sfp->activate != NULL) {
2795         sfp->activate ((WindoW) sfp->form);
2796       }
2797 #endif
2798       return;
2799     }
2800     sfp->state = MemNew (sizeof (StateData) * (size_t) num);
2801     if (sfp->state == NULL) return;
2802     for (i = 0, vnp = simpleSeqs; i < 32766 && vnp != NULL; i++, vnp = vnp->next) {
2803       sfp->simple [i] = (SimpleSeqPtr) vnp->data.ptrvalue;
2804     }
2805     sfp->numUids = num;
2806     sfp->numParents = 0;
2807     sfp->currDb = -1;
2808     Show (sfp->form);
2809     Select (sfp->form);
2810     RepopulateDocSum (sfp, FALSE);
2811     SetDocSumImportExportItems (sfp);
2812     SendMessageToForm (sfp->form, VIB_MSG_CHANGE);
2813 #ifdef WIN_MAC
2814     if (sfp->activate != NULL) {
2815       sfp->activate ((WindoW) sfp->form);
2816     }
2817 #endif
2818   } else {
2819     Show (sfp->form);
2820     Select (sfp->form);
2821 #ifdef WIN_MAC
2822     if (sfp->activate != NULL) {
2823       sfp->activate ((WindoW) sfp->form);
2824     }
2825 #endif
2826   }
2827   Update ();
2828 }
2829 
ProjectPtrToDocSumForm(ForM f,Pointer data)2830 static void ProjectPtrToDocSumForm (ForM f, Pointer data)
2831 
2832 {
2833   /*
2834   Int4         i;
2835   ValNodePtr   list;
2836   Int4         num;
2837   ValNodePtr   pip;
2838   ProjectPtr   proj;
2839   SummFormPtr  sfp;
2840   ValNodePtr   vnp;
2841 
2842   sfp = (SummFormPtr) GetObjectExtra (f);
2843   if (sfp == NULL) return;
2844   Reset (sfp->docsum);
2845   SetDocShade (sfp->docsum, NULL, NULL, NULL, NULL);
2846   SetDocCache (sfp->docsum, NULL, NULL, NULL);
2847   sfp->uids = MemFree (sfp->uids);
2848   if (sfp->simple != NULL) {
2849     for (i = 0; i < sfp->numUids; i++) {
2850       SimpleSeqFree (sfp->simple [i]);
2851     }
2852     sfp->simple = MemFree (sfp->simple);
2853   }
2854   sfp->state = MemFree (sfp->state);
2855   sfp->numUids = 0;
2856   sfp->numParents = 0;
2857   sfp->neighbors = MemFree (sfp->neighbors);
2858   sfp->numNeighbors = 0;
2859   SafeSetTitle (sfp->retrieve, "Neighbor 0");
2860   SafeDisable (sfp->retrieve);
2861   SafeSetTitle (sfp->refine, "Refine 0");
2862   SafeDisable (sfp->refine);
2863   SafeHide (sfp->target);
2864   SetValue (sfp->target, 0);
2865   SetPrevAndNextButtons (sfp);
2866   Update ();
2867   for (i = 0; i < MAX_DBS; i++) {
2868     Hide (sfp->formats [i]);
2869   }
2870   Show (sfp->formats [MAX_DBS]);
2871   proj = (ProjectPtr) data;
2872   if (proj == NULL) return;
2873   pip = proj->data;
2874   if (pip == NULL) return;
2875   list = (ValNodePtr) pip->data.ptrvalue;
2876   if (list == NULL) return;
2877   num = ValNodeLen (list);
2878   if (num > 0) {
2879     if (pip->choice >= ProjectItem_protent && pip->choice <= ProjectItem_genomeent) {
2880       sfp->simple = MemNew ((size_t) (num * sizeof (SimpleSeqPtr)));
2881       if (sfp->seqentry == NULL) {
2882         Show (sfp->form);
2883         Select (sfp->form);
2884         SendMessageToForm (sfp->form, VIB_MSG_CHANGE);
2885 #ifdef WIN_MAC
2886         if (sfp->activate != NULL) {
2887           sfp->activate ((WindoW) sfp->form);
2888         }
2889 #endif
2890         return;
2891       }
2892       sfp->state = MemNew (sizeof (StateData) * (size_t) num);
2893       if (sfp->state == NULL) return;
2894       for (i = 0, vnp = list; i < 32766 && vnp != NULL; i++, vnp = vnp->next) {
2895         sfp->seqentry [i] = vnp;
2896       }
2897       sfp->numUids = num;
2898       sfp->numParents = 0;
2899       sfp->currDb = -1;
2900       Show (sfp->form);
2901       Select (sfp->form);
2902       RepopulateDocSum (sfp, FALSE);
2903       SetDocSumImportExportItems (sfp);
2904       SendMessageToForm (sfp->form, VIB_MSG_CHANGE);
2905 #ifdef WIN_MAC
2906       if (sfp->activate != NULL) {
2907         sfp->activate ((WindoW) sfp->form);
2908       }
2909 #endif
2910     } else {
2911       Show (sfp->form);
2912       Select (sfp->form);
2913 #ifdef WIN_MAC
2914       if (sfp->activate != NULL) {
2915         sfp->activate ((WindoW) sfp->form);
2916       }
2917 #endif
2918     }
2919   } else {
2920     Show (sfp->form);
2921     Select (sfp->form);
2922 #ifdef WIN_MAC
2923     if (sfp->activate != NULL) {
2924       sfp->activate ((WindoW) sfp->form);
2925     }
2926 #endif
2927   }
2928   Update ();
2929   */
2930 }
2931 
DocSumFormToProjectPtr(ForM f)2932 static Pointer DocSumFormToProjectPtr (ForM f)
2933 
2934 {
2935   /*
2936   BioseqPtr    bsp;
2937   Char         buf [40];
2938   Char         ch;
2939   Uint1        choice = 0;
2940   Boolean      is_na = TRUE;
2941   Int2         j;
2942   ObjectIdPtr  oid;
2943   ValNodePtr   pip;
2944   ProjectPtr   proj;
2945   CharPtr      ptr;
2946   SeqEntryPtr  sep;
2947   SummFormPtr  sfp;
2948   SeqIdPtr     sip;
2949   BioseqPtr    tmp;
2950   Int4         uid;
2951 
2952   sfp = (SummFormPtr) GetObjectExtra (f);
2953   if (sfp == NULL) return NULL;
2954   proj = ProjectNew ();
2955   if (proj == NULL) return NULL;
2956   pip = ValNodeNew (NULL);
2957   if (pip == NULL) return NULL;
2958   if (sfp->uids != NULL) {
2959     switch (sfp->currDb) {
2960       case 1 :
2961         is_na = FALSE;
2962         break;
2963       case 2 :
2964       case 4 :
2965         is_na = TRUE;
2966         break;
2967       default :
2968         return NULL;
2969     }
2970   } else if (sfp->seqentry != NULL) {
2971     sep = sfp->seqentry [0];
2972     if (sep == NULL || (! IS_Bioseq (sep))) return NULL;
2973     bsp = (BioseqPtr) sep->data.ptrvalue;
2974     if (bsp == NULL) return NULL;
2975     is_na = (Boolean) (ISA_na (bsp->mol));
2976   } else return NULL;
2977   if (is_na) {
2978     choice = ProjectItem_nucent;
2979   } else {
2980     choice = ProjectItem_protent;
2981   }
2982   pip->choice = choice;
2983   proj->data = pip;
2984   for (j = 0; j < sfp->numUids; j++) {
2985     sep = NULL;
2986     if (sfp->uids != NULL) {
2987       uid = sfp->uids [j];
2988       bsp = BioseqLockByGi (uid);
2989       if (bsp != NULL && bsp->repr == Seq_repr_raw) {
2990         tmp = BioseqNew ();
2991         if (tmp != NULL) {
2992           SeqIdWrite (bsp->id, buf, PRINTID_FASTA_LONG, sizeof (buf) - 1);
2993           ptr = buf;
2994           ch = *ptr;
2995           while (ch != '\0') {
2996             if (ch == '|') {
2997               *ptr = '/';
2998             }
2999             ptr++;
3000             ch = *ptr;
3001           }
3002           oid = ObjectIdNew ();
3003           oid->str = StringSave (buf);
3004           sip = ValNodeNew (NULL);
3005           sip->choice = SEQID_LOCAL;
3006           sip->data.ptrvalue = (Pointer) oid;
3007           tmp->id = sip;
3008           tmp->repr = bsp->repr;
3009           tmp->mol = bsp->mol;
3010           tmp->length = bsp->length;
3011           tmp->seq_data_type = bsp->seq_data_type;
3012           tmp->seq_data = BSDup (bsp->seq_data);
3013           sep = SeqEntryNew ();
3014           if (sep != NULL) {
3015             sep->choice = 1;
3016             sep->data.ptrvalue = (Pointer) tmp;
3017             SeqMgrSeqEntry (SM_BIOSEQ, (Pointer) tmp, sep);
3018           }
3019         }
3020       }
3021       BioseqUnlockByGi (uid);
3022     } else if (sfp->seqentry != NULL) {
3023       sep = AsnIoMemCopy ((Pointer) sfp->seqentry [j],
3024                           (AsnReadFunc) SeqEntryAsnRead,
3025                           (AsnWriteFunc) SeqEntryAsnWrite);
3026     }
3027     if (sep != NULL) {
3028       ValNodeLink ((ValNodePtr PNTR) (&(pip->data.ptrvalue)), sep);
3029     }
3030   }
3031   return (Pointer) proj;
3032   */
3033   return NULL;
3034 }
3035 
SaveDocsumProject(BaseFormPtr bfp,Boolean saveAs)3036 static Boolean SaveDocsumProject (BaseFormPtr bfp, Boolean saveAs)
3037 
3038 {
3039   AsnIoPtr     aop;
3040   Char         path [PATH_MAX];
3041   ProjectPtr   proj;
3042   SummFormPtr  sfp;
3043 #ifdef WIN_MAC
3044   FILE         *fp;
3045 #endif
3046 
3047   if (bfp != NULL) {
3048     sfp = (SummFormPtr) bfp;
3049     path [0] = '\0';
3050     StringNCpy_0 (path, bfp->filepath, sizeof (path));
3051     if (StringHasNoText (path) || saveAs) {
3052       if (! (GetOutputFileName (path, sizeof (path), ""))) return FALSE;
3053     }
3054 #ifdef WIN_MAC
3055     fp = FileOpen (path, "r");
3056     if (fp != NULL) {
3057       FileClose (fp);
3058     } else {
3059       FileCreate (path, "TEXT", "ttxt");
3060     }
3061 #endif
3062     WatchCursor ();
3063     Update ();
3064     proj = (ProjectPtr) FormToPointer (bfp->form);
3065     if (proj == NULL) {
3066       ArrowCursor ();
3067       Update ();
3068       Message (MSG_ERROR, "Unable to create project data.");
3069       return FALSE;
3070     }
3071     aop = AsnIoOpen (path, "w");
3072     if (aop != NULL) {
3073       ProjectAsnWrite (proj, aop, NULL);
3074       AsnIoFlush (aop);
3075       AsnIoClose (aop);
3076       bfp->filepath = MemFree (bfp->filepath);
3077       bfp->filepath = StringSave (path);
3078       ArrowCursor ();
3079       Update ();
3080       return TRUE;
3081     } else {
3082       ArrowCursor ();
3083       Update ();
3084       Message (MSG_ERROR, "Unable to write file.");
3085       return FALSE;
3086     }
3087   }
3088   return FALSE;
3089 }
3090 
EntrezDocSumFormMessage(ForM f,Int2 mssg)3091 static void EntrezDocSumFormMessage (ForM f, Int2 mssg)
3092 
3093 {
3094   BaseFormPtr       bfp;
3095   EntrezGlobalsPtr  egp;
3096   SummFormPtr       sfp;
3097 
3098   bfp = (BaseFormPtr) GetObjectExtra (f);
3099   if (bfp != NULL) {
3100     switch (mssg) {
3101       case VIB_MSG_REDRAW :
3102         egp = (EntrezGlobalsPtr) GetAppProperty ("EntrezGlobals");
3103         if (egp != NULL) {
3104           sfp = (SummFormPtr) bfp;
3105           sfp->docsumFont = egp->docsumFont;
3106           RepopulateDocSum (sfp, TRUE);
3107         }
3108         break;
3109       case VIB_MSG_COPY :
3110         CopyDocsumToClipboard (bfp);
3111         break;
3112       case VIB_MSG_IMPORT :
3113         ImportDocSumForm (f, NULL);
3114         break;
3115       case VIB_MSG_EXPORT :
3116         ExportDocSumForm (f, NULL);
3117         break;
3118       case VIB_MSG_PRINT :
3119         PrintDocsumProc (bfp);
3120         break;
3121       case VIB_MSG_SAVE_AS :
3122         SaveDocsumProject (bfp, TRUE);
3123         break;
3124       default :
3125         if (bfp->appmessage != NULL) {
3126           bfp->appmessage (f, mssg);
3127         }
3128         break;
3129     }
3130   }
3131 }
3132 
EntrezDocSumFormActivate(WindoW w)3133 static void EntrezDocSumFormActivate (WindoW w)
3134 
3135 {
3136   SummFormPtr  sfp;
3137 
3138   sfp = (SummFormPtr) GetObjectExtra (w);
3139   if (sfp != NULL) {
3140     if (sfp->activate != NULL) {
3141       sfp->activate (w);
3142     }
3143     SetDocSumImportExportItems (sfp);
3144   }
3145 }
3146 
CleanupEntrezDocSumForm(GraphiC g,VoidPtr data)3147 static void CleanupEntrezDocSumForm (GraphiC g, VoidPtr data)
3148 
3149 {
3150   Int2         j;
3151   SummFormPtr  sfp;
3152 
3153   sfp = (SummFormPtr) data;
3154   if (sfp != NULL) {
3155     MemFree (sfp->uids);
3156     if (sfp->simple != NULL) {
3157       for (j = 0; j < sfp->numUids; j++) {
3158         SimpleSeqFree (sfp->simple [j]);
3159       }
3160       sfp->simple = MemFree (sfp->simple);
3161     }
3162     MemFree (sfp->state);
3163     MemFree (sfp->neighbors);
3164     FileRemove (sfp->historyFile);
3165     MemFree (sfp->historyFile);
3166     MemFree (sfp->historyOffsets);
3167     if (sfp->dbalist != NULL) {
3168       for (j = 0; sfp->dbalist [j].name != NULL; j++) {
3169         MemFree (sfp->dbalist [j].name);
3170       }
3171     }
3172     MemFree (sfp->dbalist);
3173   }
3174   StdCleanupFormProc (g, data);
3175 }
3176 
ResizeDocSumForm(WindoW w)3177 static void ResizeDocSumForm (WindoW w)
3178 
3179 {
3180   Int2         diff;
3181   Int2         gap;
3182   Int2         height;
3183   Int2         quarter;
3184   RecT         r;
3185   Int2         remaining;
3186   RecT         s;
3187   SummFormPtr  sfp;
3188   RecT         t;
3189   Int2         width;
3190 
3191   sfp = (SummFormPtr) GetObjectExtra (w);
3192   if (sfp == NULL) return;
3193   WatchCursor ();
3194   ObjectRect (w, &r);
3195   width = r.right - r.left;
3196   height = r.bottom - r.top;
3197   GetPosition (sfp->docsum, &s);
3198   GetPosition (sfp->controls, &t);
3199   diff = t.bottom - t.top;
3200   gap = t.top - s.bottom;
3201   t.bottom = height - s.left;
3202   t.top = t.bottom - diff;
3203   s.right = width - s.left;
3204   /*
3205   s.bottom = height - s.left;
3206   */
3207   s.bottom = t.top - gap;
3208   SafeHide (sfp->controls);
3209   SetPosition (sfp->controls, &t);
3210   AdjustPrnt (sfp->controls, &t, FALSE);
3211   SetPosition (sfp->docsum, &s);
3212   AdjustPrnt (sfp->docsum, &s, FALSE);
3213   ObjectRect (sfp->docsum, &s);
3214   InsetRect (&s, 4, 4);
3215   docsumColFmt [0].pixInset = 6 * stdCharWidth;
3216   remaining = s.right - s.left - 6 * stdCharWidth;
3217   quarter = remaining / 4;
3218   docsumColFmt [0].pixWidth = quarter + 6 * stdCharWidth;
3219   docsumColFmt [1].pixWidth = remaining - quarter;
3220   /*
3221   if (Visible (sfp->docsum) && AllParentsVisible (sfp->docsum)) {
3222     UpdateDocument (sfp->docsum, 0, 0);
3223   }
3224   */
3225   SafeShow (sfp->controls);
3226   RepopulateDocSum (sfp, TRUE);
3227   ArrowCursor ();
3228   Update ();
3229 }
3230 
SetDocSumImportExportItems(SummFormPtr sfp)3231 static void SetDocSumImportExportItems (SummFormPtr sfp)
3232 
3233 {
3234   IteM          exportItm;
3235   IteM          importItm;
3236   CharPtr PNTR  labels;
3237   Boolean       lastChoiceIsUidList = FALSE;
3238   Char          tmp [64];
3239   Int2          val;
3240 
3241   if (sfp == NULL) return;
3242   importItm = FindFormMenuItem ((BaseFormPtr) sfp, VIB_MSG_IMPORT);
3243   if (importItm != NULL) {
3244     SafeSetTitle (importItm, "Import FASTA or Uid List...");
3245   }
3246   exportItm = FindFormMenuItem ((BaseFormPtr) sfp, VIB_MSG_EXPORT);
3247   if (exportItm == NULL) return;
3248   sfp->label = medRadios [0];
3249   if (sfp->simple != NULL) {
3250     sfp->label = localBioseqRadios [0];
3251   } else if (sfp->currDb >= 0 && sfp->currDb < MAX_DBS) {
3252     labels = radioLabels [sfp->currDb];
3253     val = GetValue (sfp->formats [sfp->currDb]);
3254     if (val > 0) {
3255       sfp->label = labels [val - 1];
3256       if (labels [val] == NULL) {
3257         lastChoiceIsUidList = TRUE;
3258       }
3259     }
3260   }
3261   StringCpy (tmp, "Export ");
3262   StringCat (tmp, sfp->label);
3263   if (lastChoiceIsUidList) {
3264     StringCat (tmp, " List");
3265   }
3266   StringCat (tmp, "...");
3267   SafeSetTitle (exportItm, tmp);
3268 }
3269 
CreateDocSumForm(Int2 left,Int2 top,CharPtr title,WndActnProc activate,FormMessageFunc messages)3270 extern ForM CreateDocSumForm (Int2 left, Int2 top, CharPtr title,
3271                               WndActnProc activate, FormMessageFunc messages)
3272 
3273 {
3274   ButtoN            b1, b2, b3;
3275   EntrezGlobalsPtr  egp;
3276   EntrezInfoPtr     eip;
3277   GrouP             g;
3278   GrouP             h;
3279   Int2              i;
3280   Int2              j;
3281   GrouP             k;
3282   CharPtr PNTR      labels;
3283   Boolean           macLike;
3284   PrompT            ppt, ppt1, ppt2;
3285   GrouP             q;
3286   Int2              quarter;
3287   RecT              r;
3288   Int2              remaining;
3289   SummFormPtr       sfp;
3290   Int2              typ_ml;
3291   WindoW            w;
3292   GrouP             x;
3293   GrouP             y;
3294 
3295   w = NULL;
3296   eip = EntrezGetInfo ();
3297   if (eip == NULL || eip->type_info == NULL ||
3298       eip->types == NULL || eip->field_info == NULL) return NULL;
3299   egp = (EntrezGlobalsPtr) GetAppProperty ("EntrezGlobals");
3300   if (egp == NULL) return NULL;
3301   macLike = egp->popdownBehavior;
3302   sfp = (SummFormPtr) MemNew (sizeof (SummFormData));
3303   if (sfp != NULL) {
3304     w = DocumentWindow (left, top, -10, -10, title,
3305                         StdSendCloseWindowMessageProc, ResizeDocSumForm);
3306     SetObjectExtra (w, sfp, CleanupEntrezDocSumForm);
3307     sfp->form = (ForM) w;
3308     sfp->toform = ProjectPtrToDocSumForm;
3309     sfp->fromform = DocSumFormToProjectPtr;
3310     sfp->formmessage = EntrezDocSumFormMessage;
3311     sfp->importform = ImportDocSumForm;
3312     sfp->exportform = ExportDocSumForm;
3313 
3314     sfp->appmessage = messages;
3315     sfp->activate = activate;
3316     SetActivate (w, EntrezDocSumFormActivate);
3317 
3318     sfp->docsumFont = egp->docsumFont;
3319     if (sfp->docsumFont == NULL) {
3320       sfp->docsumFont = programFont;
3321     }
3322 
3323     if (egp->createDocSumMenus != NULL) {
3324       egp->createDocSumMenus (w);
3325     }
3326 
3327     h = HiddenGroup (w, -1, 0, NULL);
3328 
3329     k = HiddenGroup (h, 2, 0, NULL);
3330     ppt = StaticPrompt (k, "Format:", 0, 0, programFont, 'l');
3331     q = HiddenGroup (k, 0, 0, NULL);
3332     for (i = 0; i < MAX_DBS && radioLabels [i] != NULL; i++) {
3333       sfp->formats [i] = HiddenGroup (q, 5, 0, ChangeFormat);
3334       SetObjectExtra (sfp->formats [i], sfp, NULL);
3335       labels = radioLabels [i];
3336       for (j = 0; labels [j] != NULL; j++) {
3337         RadioButton (sfp->formats [i], labels [j]);
3338       }
3339       SetValue (sfp->formats [i], 1);
3340       Hide (sfp->formats [i]);
3341     }
3342     sfp->formats [MAX_DBS] = HiddenGroup (q, 5, 0, NULL);
3343     SetObjectExtra (sfp->formats [MAX_DBS], sfp, NULL);
3344     labels = localBioseqRadios;
3345     for (j = 0; labels [j] != NULL; j++) {
3346        RadioButton (sfp->formats [MAX_DBS], labels [j]);
3347     }
3348     SetValue (sfp->formats [MAX_DBS], 1);
3349     Hide (sfp->formats [MAX_DBS]);
3350     sfp->label = medRadios [0];
3351     AlignObjects (ALIGN_MIDDLE, (HANDLE) ppt, (HANDLE) q, NULL);
3352 
3353     g = HiddenGroup (h, -1, 0, NULL);
3354     SetGroupSpacing (g, 5, 5);
3355 
3356     sfp->dbalist = MakeDatabaseAlist (eip->type_info, eip->type_count, FALSE);
3357 
3358     sfp->docsum = DocumentPanel (g, 32 * stdCharWidth, 20 * stdLineHeight);
3359     SetObjectExtra (sfp->docsum, sfp, NULL);
3360     SetDocProcs (sfp->docsum, ClickDocSum, NULL, ReleaseDocSum, NULL);
3361     SetDocCache (sfp->docsum, NULL, NULL, NULL);
3362     Hide (sfp->docsum);
3363 
3364     sfp->controls = HiddenGroup (g, 5, 0, NULL);
3365     SetGroupSpacing (sfp->controls, 10, 10);
3366 
3367     x = HiddenGroup (sfp->controls, 0, 2, NULL);
3368     sfp->retrieve = PushButton (x, "Neighbor 00000", RetrieveNeighbors);
3369     SetObjectExtra (sfp->retrieve, sfp, NULL);
3370     SetTitle (sfp->retrieve, "Neighbor 0");
3371     Disable (sfp->retrieve);
3372     sfp->refine = PushButton (x, "Refine 0000", RefineProc);
3373     SetObjectExtra (sfp->refine , sfp, NULL);
3374     SetTitle (sfp->refine, "Refine");
3375     Disable (sfp->refine);
3376     sfp->retrieveMode = FETCH_MODE;
3377     sfp->usingDelay = FALSE;
3378 
3379     sfp->neighbors = NULL;
3380     sfp->numNeighbors = 0;
3381 
3382     sfp->historyFile = NULL;
3383     sfp->historyOffsets = NULL;
3384     sfp->generations = 0;
3385     sfp->present = 0;
3386 
3387     x = HiddenGroup (sfp->controls, 0, -3, NULL);
3388     SetGroupMargins (x, 3, 0);
3389     SetGroupSpacing (x, 3, 5);
3390 
3391     y = HiddenGroup (x, 5, 0, NULL);
3392     ppt1 = StaticPrompt (y, "Target:", 0, popupMenuHeight, programFont, 'l');
3393     sfp->target = PopupList (y, macLike, ChangeTarget);
3394     SetObjectExtra (sfp->target, sfp, NULL);
3395     InitEnumPopup (sfp->target, sfp->dbalist, NULL);
3396     typ_ml = DatabaseFromName ("MEDLINE");
3397     SetEnumPopup (sfp->target, sfp->dbalist, (UIEnum) typ_ml);
3398 
3399     y = HiddenGroup (x, 4, 0, NULL);
3400     SetGroupSpacing (y, 8, 0);
3401     ppt2 = StaticPrompt  (y, "Select:", 0, 0, programFont, 'l');
3402     b1 = PushButton (y, "All", SelectAllProc);
3403     SetObjectExtra (b1, sfp, NULL);
3404     b2 = PushButton (y, "None", ClearAllProc);
3405     SetObjectExtra (b2, sfp, NULL);
3406     b3 = PushButton (y, "Parents", SelectParentsProc);
3407     SetObjectExtra (b3, sfp, NULL);
3408 
3409     x = HiddenGroup (sfp->controls, 0, 2, NULL);
3410     sfp->prevBtn = PushButton (x, "Prev", PrevProc);
3411     SetObjectExtra (sfp->prevBtn, sfp, NULL);
3412     Disable (sfp->prevBtn);
3413     sfp->nextBtn = PushButton (x, "Next", NextProc);
3414     SetObjectExtra (sfp->nextBtn, sfp, NULL);
3415     Disable (sfp->nextBtn);
3416 
3417     AlignObjects (ALIGN_MIDDLE, (HANDLE) sfp->retrieve, (HANDLE) ppt1,
3418                   (HANDLE) sfp->target, (HANDLE) sfp->prevBtn, NULL);
3419     AlignObjects (ALIGN_MIDDLE, (HANDLE) sfp->refine , (HANDLE) ppt2, (HANDLE) b1,
3420                   (HANDLE) b2, (HANDLE) b3, (HANDLE) sfp->nextBtn, NULL);
3421 
3422     RealizeWindow (w);
3423 
3424     SelectFont (programFont);
3425     sfp->lineHeight = LineHeight ();
3426     SelectFont (systemFont);
3427     sfp->linesPerIcon = (22 + sfp->lineHeight - 1) / sfp->lineHeight;
3428     docsumParFmt.minLines = sfp->linesPerIcon;
3429 
3430     ObjectRect (sfp->docsum, &r);
3431     InsetRect (&r, 4, 4);
3432     docsumColFmt [0].pixInset = 6 * stdCharWidth;
3433     remaining = r.right - r.left - 6 * stdCharWidth;
3434     quarter = remaining / 4;
3435     docsumColFmt [0].pixWidth = quarter + 6 * stdCharWidth;
3436     docsumColFmt [1].pixWidth = remaining - quarter;
3437     textColFmt [0].pixInset = 3 * stdCharWidth;
3438     textColFmt [0].pixWidth = screenRect.right - screenRect.left;
3439 
3440     SetDocAutoAdjust (sfp->docsum, FALSE);
3441   }
3442   return (ForM) w;
3443 }
3444 
3445 typedef struct linkgroup {
3446   DIALOG_MESSAGE_BLOCK
3447   BaseFormPtr        bfp;
3448   ButtoN             retrieve;
3449   PopuP              target;
3450   LinkSetPtr         lsp;
3451   Int2               currDb;
3452   Int2               targetDb;
3453   Int4               docuid;
3454   Uint2              align_type;
3455   ButtoN             onlyFromThis;
3456   EnumFieldAssocPtr  dbalist;
3457 } LinkGroup, PNTR LinkGroupPtr;
3458 
RetrieveViewerLinks(ButtoN b)3459 static void RetrieveViewerLinks (ButtoN b)
3460 
3461 {
3462   BaseFormPtr       bfp;
3463   BioseqPtr         bsp;
3464   EntrezGlobalsPtr  egp;
3465   ValNodePtr        head;
3466   Int2              i;
3467   LinkGroupPtr      lgp;
3468   LinkSetPtr        lsp;
3469   Int2              num;
3470   Int2              parents;
3471   Boolean           persist;
3472   SeqEntryPtr       sep;
3473   Int4Ptr           uids;
3474   ValNodePtr        vnp;
3475 
3476   lgp = (LinkGroupPtr) GetObjectExtra (b);
3477   if (lgp == NULL) return;
3478   bfp = (BaseFormPtr) GetObjectExtra (ParentWindow (b));
3479   if (bfp == NULL) return;
3480   egp = (EntrezGlobalsPtr) GetAppProperty ("EntrezGlobals");
3481   if (egp == NULL || egp->retrieveDocsProc == NULL) return;
3482   if (lgp->align_type != 0) {
3483     uids = NULL;
3484     sep = NULL;
3485     if (GetStatus (lgp->onlyFromThis)) {
3486       bsp =  GetBioseqGivenIDs (bfp->input_entityID, bfp->input_itemID, bfp->input_itemtype);
3487       if (bsp != NULL) {
3488         sep = SeqMgrGetSeqEntryForData (bsp);
3489       }
3490     } else {
3491       sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
3492     }
3493     head = GetUidsForSeqEntryAligns (sep);
3494     num = 0;
3495     for (vnp = head; vnp != NULL; vnp = vnp->next) {
3496       if (vnp->choice == lgp->align_type && vnp->data.intvalue != lgp->docuid) {
3497         num++;
3498       }
3499     }
3500     if (num > 0) {
3501       uids = MemNew ((size_t) (num + 1) * sizeof (DocUid));
3502       if (uids != NULL) {
3503         i = 0;
3504         for (vnp = head; i < num && vnp != NULL; vnp = vnp->next) {
3505           if (vnp->choice == lgp->align_type && vnp->data.intvalue != lgp->docuid) {
3506             uids [i] = vnp->data.intvalue;
3507             i++;
3508           }
3509         }
3510       }
3511       egp->retrieveDocsProc (bfp->form, num, 0, uids, lgp->targetDb);
3512       MemFree (uids);
3513     }
3514     ValNodeFree (head);
3515     return;
3516   }
3517   lsp = lgp->lsp;
3518   if (lsp == NULL) return;
3519   persist = FALSE;
3520   if (lgp->currDb == lgp->targetDb) {
3521     if (egp->parentsPersist != NULL) {
3522       persist = GetStatus (egp->parentsPersist);
3523     } else {
3524       persist = egp->persistDefault;
3525     }
3526   }
3527   parents = 0;
3528   if (persist) {
3529     parents++;
3530   }
3531   uids = NULL;
3532   num = lsp->num + parents;
3533   if (num > 0) {
3534     uids = MemNew ((size_t) (num + 1) * sizeof (DocUid));
3535     if (uids != NULL) {
3536       num = 0;
3537       if (persist) {
3538         uids [num] = lgp->docuid;
3539         num++;
3540       }
3541       for (i = 0; i < lsp->num; i++) {
3542         uids [num] = lsp->uids [i];
3543         num++;
3544       }
3545     }
3546   }
3547   egp->retrieveDocsProc (bfp->form, num, parents, uids, lgp->targetDb);
3548   MemFree (uids);
3549 }
3550 
ChangeViewerLinkData(LinkGroupPtr lgp,Int2 currDb,Int4 theuid)3551 static void ChangeViewerLinkData (LinkGroupPtr lgp, Int2 currDb, Int4 theuid)
3552 
3553 {
3554   BaseFormPtr  bfp;
3555   BioseqPtr    bsp;
3556   ValNodePtr   head = NULL;
3557   Int4         num;
3558   SeqEntryPtr  sep;
3559   SeqIdPtr     sip;
3560   Char         str [64];
3561   Char         title [32];
3562   Int4         uid;
3563   UIEnum       val;
3564   ValNode      vn;
3565   ValNodePtr   vnp;
3566 
3567   if (lgp == NULL) return;
3568   if (lgp->lsp != NULL) {
3569     lgp->lsp = LinkSetFree (lgp->lsp);
3570   }
3571   lgp->align_type = 0;
3572   if (GetEnumPopup (lgp->target, lgp->dbalist, &val)) {
3573     lgp->targetDb = (Int2) val;
3574     if (lgp->targetDb >= ALIST_BLASTN && lgp->targetDb <= ALIST_TBLASTX) {
3575       /* SafeShow (lgp->onlyFromThis); */
3576       lgp->docuid = theuid;
3577       lgp->currDb = currDb;
3578       num = 0;
3579       bfp = lgp->bfp;
3580       if (bfp != NULL) {
3581         sep = NULL;
3582         if (GetStatus (lgp->onlyFromThis)) {
3583           bsp =  GetBioseqGivenIDs (bfp->input_entityID, bfp->input_itemID, bfp->input_itemtype);
3584           if (bsp != NULL) {
3585             sep = SeqMgrGetSeqEntryForData (bsp);
3586           }
3587         } else {
3588           sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
3589         }
3590         head = GetIdStringsForSeqEntryAligns (sep);
3591         lgp->targetDb = TYP_NT;
3592         switch (val) {
3593           case ALIST_BLASTN :
3594             lgp->align_type = ALIGN_BLASTN;
3595             lgp->targetDb = TYP_NT;
3596             break;
3597           case ALIST_BLASTP :
3598             lgp->align_type = ALIGN_BLASTP;
3599             lgp->targetDb = TYP_AA;
3600             break;
3601           case ALIST_BLASTX :
3602             lgp->align_type = ALIGN_BLASTX;
3603             lgp->targetDb = TYP_AA;
3604             break;
3605           case ALIST_TBLASTN :
3606             lgp->align_type = ALIGN_TBLASTN;
3607             lgp->targetDb = TYP_NT;
3608             break;
3609           default :
3610             break;
3611         }
3612         vn.choice = SEQID_GI;
3613         vn.data.intvalue = theuid;
3614         sip = (SeqIdPtr) (&vn);
3615         SeqIdWrite (sip, str, PRINTID_REPORT, sizeof (str));
3616         for (vnp = head; vnp != NULL; vnp = vnp->next) {
3617           if (vnp->choice == lgp->align_type && StringICmp ((CharPtr) vnp->data.ptrvalue, str) != 0) {
3618             num++;
3619           }
3620         }
3621         ValNodeFreeData (head);
3622       }
3623       sprintf (title, "Retrieve %ld", (long) num);
3624       SafeSetTitle (lgp->retrieve, title);
3625       if (num > 0) {
3626         SafeEnable (lgp->retrieve);
3627       } else {
3628         SafeDisable (lgp->retrieve);
3629      }
3630       return;
3631     } else {
3632       /* SafeHide (lgp->onlyFromThis); */
3633     }
3634   } else {
3635     lgp->targetDb = currDb;
3636   }
3637   lgp->currDb = currDb;
3638   lgp->docuid = theuid;
3639   if (theuid > 0) {
3640     lgp->lsp = NULL;
3641     uid = theuid;
3642     EntrezLinkUidList (&(lgp->lsp), lgp->currDb, lgp->targetDb, 1, &uid, FALSE);
3643   }
3644   num = 0;
3645   if (lgp->lsp != NULL) {
3646     num = (Int4) lgp->lsp->num;
3647   }
3648   if (lgp->targetDb == lgp->currDb) {
3649     sprintf (title, "Neighbor %ld", (long) num);
3650   } else {
3651     sprintf (title, "Lookup %ld", (long) num);
3652   }
3653   SafeSetTitle (lgp->retrieve, title);
3654   if (num > 0) {
3655     SafeEnable (lgp->retrieve);
3656   } else {
3657     SafeDisable (lgp->retrieve);
3658   }
3659 }
3660 
UpdateViewerLinkTarget(GrouP g)3661 extern void UpdateViewerLinkTarget (GrouP g)
3662 
3663 {
3664   BaseFormPtr   bfp;
3665   Int2          currDb;
3666   LinkGroupPtr  lgp;
3667   Int4          uid = 0;
3668   UIEnum        val;
3669 
3670   lgp = (LinkGroupPtr) GetObjectExtra (g);
3671   if (lgp == NULL) return;
3672   bfp = lgp->bfp;
3673   if (bfp == NULL) return;
3674   currDb = bfp->doctype;
3675   uid = bfp->docuid;
3676   if (GetEnumPopup (lgp->target, lgp->dbalist, &val)) {
3677     if (! (val >= ALIST_BLASTN && val <= ALIST_TBLASTX)) {
3678       SetEnumPopup (lgp->target, lgp->dbalist, (UIEnum) currDb);
3679     }
3680   }
3681   ChangeViewerLinkData (lgp, currDb, uid);
3682 }
3683 
ChangeViewerLinkTarget(GraphiC g)3684 static void ChangeViewerLinkTarget (GraphiC g)
3685 
3686 {
3687   BaseFormPtr   bfp;
3688   Int2          currDb;
3689   LinkGroupPtr  lgp;
3690   Int4          uid = 0;
3691 
3692   lgp = (LinkGroupPtr) GetObjectExtra (g);
3693   if (lgp == NULL) return;
3694   bfp = lgp->bfp;
3695   if (bfp == NULL) return;
3696   currDb = bfp->doctype;
3697   uid = bfp->docuid;
3698   ChangeViewerLinkData (lgp, currDb, uid);
3699 }
3700 
CleanupLinkGroup(GraphiC g,VoidPtr data)3701 static void CleanupLinkGroup (GraphiC g, VoidPtr data)
3702 
3703 {
3704   Int2          j;
3705   LinkGroupPtr  lgp;
3706 
3707   lgp = (LinkGroupPtr) data;
3708   if (lgp != NULL) {
3709     LinkSetFree (lgp->lsp);
3710     if (lgp->dbalist != NULL) {
3711       for (j = 0; lgp->dbalist [j].name != NULL; j++) {
3712         MemFree (lgp->dbalist [j].name);
3713       }
3714     }
3715     MemFree (lgp->dbalist);
3716   }
3717   MemFree (data);
3718 }
3719 
MakeViewerLinkControls(GrouP prnt,BaseFormPtr bfp,Int2 doctype,Int4 uid,Boolean blast)3720 extern GrouP MakeViewerLinkControls (GrouP prnt, BaseFormPtr bfp, Int2 doctype, Int4 uid, Boolean blast)
3721 
3722 {
3723   EntrezGlobalsPtr  egp;
3724   EntrezInfoPtr     eip;
3725   LinkGroupPtr      lgp;
3726   Boolean           macLike;
3727   GrouP             p;
3728   PrompT            ppt;
3729 
3730   if (prnt == NULL || bfp == NULL) return NULL;
3731 
3732   eip = EntrezGetInfo ();
3733   if (eip == NULL || eip->type_info == NULL ||
3734       eip->types == NULL || eip->field_info == NULL) return NULL;
3735   egp = (EntrezGlobalsPtr) GetAppProperty ("EntrezGlobals");
3736   if (egp == NULL) return NULL;
3737   macLike = egp->popdownBehavior;
3738 
3739   p = HiddenGroup (prnt, 5, 0, NULL);
3740   SetGroupSpacing (p, 10, 10);
3741 
3742   lgp = (LinkGroupPtr) MemNew (sizeof (LinkGroup));
3743   if (lgp == NULL) return p;
3744 
3745   SetObjectExtra (p, lgp, CleanupLinkGroup);
3746   lgp->dialog = (DialoG) p;
3747 
3748   lgp->bfp = bfp;
3749   lgp->lsp = NULL;
3750   lgp->dbalist = MakeDatabaseAlist (eip->type_info, eip->type_count, blast);
3751 
3752   lgp->retrieve = PushButton (p, "Neighbor 00000", RetrieveViewerLinks);
3753   SetObjectExtra (lgp->retrieve, lgp, NULL);
3754   SetTitle (lgp->retrieve, "Neighbor 0");
3755   Disable (lgp->retrieve);
3756 
3757   ppt = StaticPrompt (p, "Target:", 0, popupMenuHeight, programFont, 'l');
3758   lgp->target = PopupList (p, macLike, (PupActnProc) ChangeViewerLinkTarget);
3759   SetObjectExtra (lgp->target, lgp, NULL);
3760   InitEnumPopup (lgp->target, lgp->dbalist, NULL);
3761   SetEnumPopup (lgp->target, lgp->dbalist, (UIEnum) doctype);
3762 
3763   lgp->onlyFromThis = CheckBox (p, "Just from this sequence", (BtnActnProc) ChangeViewerLinkTarget);
3764   SetObjectExtra (lgp->onlyFromThis, lgp, NULL);
3765   SetStatus (lgp->onlyFromThis, TRUE);
3766   SafeHide (lgp->onlyFromThis);
3767 
3768   AlignObjects (ALIGN_MIDDLE, (HANDLE) lgp->retrieve, (HANDLE) ppt,
3769                 (HANDLE) lgp->target, (HANDLE) lgp->onlyFromThis, NULL);
3770 
3771   ChangeViewerLinkData (lgp, doctype, uid);
3772 
3773   return p;
3774 }
3775 
LaunchMedlineViewer(Int4 uid,Int2 numAlign,Int4Ptr alignuids,Int2 db)3776 static void LaunchMedlineViewer (Int4 uid, Int2 numAlign, Int4Ptr alignuids, Int2 db)
3777 
3778 {
3779   Pointer          dataptr;
3780   Uint2            datatype;
3781   Uint2            entityID;
3782   Int2             handled;
3783   MedlineEntryPtr  mep;
3784 
3785   WatchCursor ();
3786   Update ();
3787   mep = EntrezMedlineEntryGet (uid);
3788   if (mep == NULL) {
3789     ArrowCursor ();
3790     Update ();
3791     Message (MSG_OK, "Unable to find this record in the database.");
3792     return;
3793   }
3794   datatype = OBJ_MEDLINE_ENTRY;
3795   dataptr = (Pointer) mep;
3796   entityID = ObjMgrRegister (datatype, dataptr);
3797   if (dataptr == NULL || entityID == 0) {
3798     ArrowCursor ();
3799     Update ();
3800     Message (MSG_OK, "Unable to find this record in the database.");
3801     return;
3802   }
3803   handled = GatherProcLaunch (OMPROC_VIEW, FALSE, entityID, 1,
3804                               OBJ_MEDLINE_ENTRY, 0, 0, OBJ_MEDLINE_ENTRY, 0);
3805   ArrowCursor ();
3806   if (handled != OM_MSG_RET_DONE || handled == OM_MSG_RET_NOPROC) {
3807     Message (MSG_FATAL, "Unable to launch viewer.");
3808     MedlineEntryFree (mep);
3809   } else {
3810     ObjMgrSetOptions (OM_OPT_FREE_IF_NO_VIEW, entityID);
3811   }
3812 }
3813 
AddBlastAlignment(Int4 uid,Int2 numAlign,Int4Ptr alignuids,Uint2 entityID,SeqEntryPtr sep,BioseqPtr subject)3814 static void AddBlastAlignment (Int4 uid, Int2 numAlign, Int4Ptr alignuids, Uint2 entityID, SeqEntryPtr sep, BioseqPtr subject)
3815 
3816 {
3817   Uint1                align_type = 0;
3818   BioseqPtr            bsp;
3819   BioseqSetPtr         bssp;
3820   SeqAnnotPtr          curr;
3821   Int2                 i;
3822   BLAST_OptionsBlkPtr  options = NULL;
3823   SeqAlignPtr          prev;
3824   BioseqPtr            query;
3825   SeqAlignPtr          salp;
3826   SeqAnnotPtr          sap;
3827   SeqAnnotPtr PNTR     sapp;
3828   BlastSearchBlkPtr    search;
3829 
3830   if (sep == NULL || numAlign == 0 || alignuids == NULL) return;
3831   sap = NULL;
3832   salp = NULL;
3833   if (subject == NULL) return;
3834   if (ISA_na (subject->mol)) {
3835     align_type = 1;
3836     options = BLASTOptionNew ("blastn", TRUE);
3837     if (options != NULL) {
3838       options->gapped_calculation = TRUE;
3839       options->db_length = 100000000;
3840 #ifdef WIN16
3841       options->wordsize = 10;
3842 #else
3843       options->wordsize = 12;
3844 #endif
3845     }
3846   } else if (ISA_aa (subject->mol)) {
3847     align_type = 2;
3848     options = BLASTOptionNew ("blastp", TRUE);
3849     if (options != NULL) {
3850       options->gapped_calculation = TRUE;
3851       options->db_length = 20000000;
3852       options->threshold_second = 12;
3853     }
3854   } else return;
3855   search = BLASTSetUpSearch (subject, options->program_name, 0, 0, NULL, options, NULL);
3856 
3857   for (i = 0; i < numAlign; i++) {
3858     if (alignuids [i] != uid) {
3859       query = BioseqLockByGi (alignuids [i]);
3860       if (query != NULL) {
3861         salp = BlastSequencesOnTheFly (search, query);
3862         BioseqUnlockByGi (alignuids [i]);
3863         if (salp != NULL) {
3864           if (sap == NULL) {
3865             sap = SeqAnnotNew ();
3866             if (sap != NULL) {
3867               sap->type = 2;
3868             }
3869           }
3870           if (sap != NULL) {
3871             if (sap->data != NULL) {
3872               prev = sap->data;
3873               while (prev->next != NULL) {
3874                 prev = prev->next;
3875               }
3876               prev->next = salp;
3877             } else {
3878               sap->data = (Pointer) salp;
3879             }
3880           }
3881         }
3882       }
3883     }
3884   }
3885   BLASTOptionDelete (options);
3886   BlastSearchBlkDestruct (search);
3887 
3888   if (sap == NULL) return;
3889 
3890   AddAlignInfoToSeqAnnot (sap, align_type);
3891   /*
3892   ObjMgrRegister (OBJ_SEQANNOT, (Pointer) sap);
3893   */
3894   sapp = NULL;
3895   if (IS_Bioseq (sep)) {
3896     bsp = (BioseqPtr) sep->data.ptrvalue;
3897     sapp = &(bsp->annot);
3898   } else if (IS_Bioseq_set (sep)) {
3899     bssp = (BioseqSetPtr) sep->data.ptrvalue;
3900     sapp = &(bssp->annot);
3901   }
3902   if (sapp != NULL) {
3903     if (*sapp != NULL) {
3904       curr = *sapp;
3905       while (curr->next != NULL) {
3906         curr = curr->next;
3907       }
3908       curr->next = sap;
3909     } else {
3910       *sapp = sap;
3911     }
3912   }
3913 }
3914 
3915 /*
3916 static Int2 GetSequenceComplexity (void)
3917 
3918 {
3919   Int2              retcode = 0;
3920   EntrezGlobalsPtr  egp;
3921   Int2              val;
3922 
3923   egp = (EntrezGlobalsPtr) GetAppProperty ("EntrezGlobals");
3924   if (egp == NULL || egp->seqComplex == NULL) return retcode;
3925   val = GetValue (egp->seqComplex);
3926   switch (val) {
3927     case 1 :
3928       retcode = -2;
3929       break;
3930     case 2 :
3931       retcode = SEQENTRY_READ_SEG_SET;
3932       break;
3933     case 3 :
3934       retcode = SEQENTRY_READ_BIOSEQ;
3935      break;
3936     default :
3937       retcode = 0;
3938       break;
3939   }
3940   return retcode;
3941 }
3942 */
3943 
LaunchSequenceViewer(Int4 uid,Int2 numAlign,Int4Ptr alignuids,Int2 db)3944 static void LaunchSequenceViewer (Int4 uid, Int2 numAlign, Int4Ptr alignuids, Int2 db)
3945 
3946 {
3947   BioseqPtr         bsp;
3948   EntrezGlobalsPtr  egp;
3949   Uint2             entityID;
3950   Int2              handled;
3951   Uint4             itemID;
3952   SeqEntryPtr       sep;
3953 
3954   WatchCursor ();
3955   Update ();
3956   SeqEntrySetScope (NULL);
3957   /* retcode = GetSequenceComplexity (); */
3958   bsp = BioseqLockByGi (uid);
3959   if (bsp == NULL) {
3960     ArrowCursor ();
3961     Update ();
3962     Message (MSG_OK, "Unable to find this record in the database.");
3963     return;
3964   }
3965   entityID = BioseqFindEntityByGi (uid, &itemID);
3966   if (entityID == 0 || itemID == 0) {
3967     BioseqUnlockByGi (uid);
3968     ArrowCursor ();
3969     Update ();
3970     Message (MSG_OK, "BioseqFindEntityByGi failed.");
3971     return;
3972   }
3973   egp = (EntrezGlobalsPtr) GetAppProperty ("EntrezGlobals");
3974   if (egp != NULL) {
3975     if (GetStatus (egp->alignWithChecked)) {
3976       sep = GetTopSeqEntryForEntityID (entityID);
3977       AddBlastAlignment (uid, numAlign, alignuids, entityID, sep, bsp);
3978     }
3979   }
3980   handled = GatherProcLaunch (OMPROC_VIEW, FALSE, entityID, itemID,
3981                               OBJ_BIOSEQ, 0, 0, OBJ_BIOSEQ, 0);
3982   ArrowCursor ();
3983   if (handled != OM_MSG_RET_DONE || handled == OM_MSG_RET_NOPROC) {
3984     Message (MSG_FATAL, "Unable to launch viewer.");
3985   } else {
3986     ObjMgrSetOptions (OM_OPT_FREE_IF_NO_VIEW, entityID);
3987   }
3988   BioseqUnlockByGi (uid);
3989 }
3990 
LaunchGenomeViewer(Int4 uid,Int2 numAlign,Int4Ptr alignuids,Int2 db)3991 static void LaunchGenomeViewer (Int4 uid, Int2 numAlign, Int4Ptr alignuids, Int2 db)
3992 
3993 {
3994   Pointer      dataptr;
3995   Uint2        datatype;
3996   Uint2        entityID;
3997   Int2         handled;
3998   Uint4        itemID;
3999   SeqEntryPtr  sep;
4000 
4001   WatchCursor ();
4002   Update ();
4003   sep = EntrezSeqEntryGet (uid, -1);
4004   if (sep == NULL) {
4005     ArrowCursor ();
4006     Update ();
4007     Message (MSG_OK, "Unable to find this record in the database.");
4008     return;
4009   }
4010   if (IS_Bioseq (sep)) {
4011     datatype = OBJ_BIOSEQ;
4012   } else if (IS_Bioseq_set (sep)) {
4013     datatype = OBJ_BIOSEQSET;
4014   } else {
4015     ArrowCursor ();
4016     Update ();
4017     Message (MSG_OK, "Unable to find this record in the database.");
4018     return;
4019   }
4020   dataptr = (Pointer) sep->data.ptrvalue;
4021   entityID = ObjMgrRegister (datatype, dataptr);
4022   if (dataptr == NULL || entityID == 0) {
4023     ArrowCursor ();
4024     Update ();
4025     Message (MSG_OK, "Unable to find this record in the database.");
4026     return;
4027   }
4028   itemID = 1;
4029   handled = GatherProcLaunch (OMPROC_VIEW, FALSE, entityID, itemID,
4030                               OBJ_BIOSEQ, 0, 0, OBJ_BIOSEQ, 0);
4031   ArrowCursor ();
4032   if (handled != OM_MSG_RET_DONE || handled == OM_MSG_RET_NOPROC) {
4033     Message (MSG_FATAL, "Unable to launch viewer.");
4034     SeqEntryFree (sep);
4035   } else {
4036     ObjMgrSetOptions (OM_OPT_FREE_IF_NO_VIEW, entityID);
4037   }
4038 }
4039 
GetBiostrucComplexity(void)4040 static Int4 GetBiostrucComplexity (void)
4041 
4042 {
4043   Int4              complexity = ALLMDL;
4044   EntrezGlobalsPtr  egp;
4045   Int2              val;
4046 
4047   egp = (EntrezGlobalsPtr) GetAppProperty ("EntrezGlobals");
4048   if (egp == NULL) return complexity;
4049   val = GetValue (egp->strucComplex);
4050   switch (val) {
4051     case 1 :
4052       complexity = ONECOORDATOM;
4053       break;
4054     case 2 :
4055       complexity = ONECOORDRES;
4056       break;
4057     case 3 :
4058       complexity = ALLMDL;
4059      break;
4060     case 4 :
4061       complexity = VECMODEL;
4062       break;
4063     case 5 :
4064       complexity = BSEVERYTHING;
4065       break;
4066     default :
4067       complexity = ONECOORDATOM;
4068       break;
4069   }
4070   return complexity;
4071 }
4072 
GetBiostrucMaxModels(void)4073 static Int2 GetBiostrucMaxModels (void)
4074 
4075 {
4076   EntrezGlobalsPtr  egp;
4077   Int2              maxModels = INT2_MAX;
4078   Int2              val;
4079 
4080   egp = (EntrezGlobalsPtr) GetAppProperty ("EntrezGlobals");
4081   if (egp == NULL) return maxModels;
4082   val = GetValue (egp->strucModels);
4083   switch (val) {
4084     case 1 :
4085       maxModels = 1;
4086       break;
4087     case 2 :
4088       maxModels = 2;
4089       break;
4090     case 3 :
4091       maxModels = 5;
4092       break;
4093     case 4 :
4094       maxModels = 10;
4095       break;
4096     case 5 :
4097       maxModels = 15;
4098       break;
4099     case 6 :
4100       maxModels = 20;
4101       break;
4102     case 7:
4103       maxModels = MAX_MDLNO;
4104       break;
4105     default :
4106       maxModels = 1;
4107       break;
4108   }
4109   return maxModels;
4110 }
4111 
LaunchStructureViewer(Int4 uid,Int2 numAlign,Int4Ptr alignuids,Int2 db)4112 static void LaunchStructureViewer (Int4 uid, Int2 numAlign, Int4Ptr alignuids, Int2 db)
4113 
4114 {
4115 #if defined(WIN16)
4116   Message (MSG_OK, "Structure views not supported on this platform.");
4117 #else
4118   AsnIoPtr         aip;
4119   BiostrucPtr      bsp;
4120   Int4             complexity;
4121   EntrezGeneral    eg;
4122   Int2             maxModels;
4123   NcbiMimeAsn1     mime;
4124   Char             path [PATH_MAX];
4125   ValNode          vn;
4126 #ifdef WIN_MOTIF
4127   Char             cmmd [PATH_MAX];
4128 #endif
4129 #ifdef WIN_MSWIN
4130   Char             prog [PATH_MAX];
4131 #endif
4132 
4133   if (! BiostrucAvail ()) {
4134     Message (MSG_OK, "Structure libraries are not linked in.");
4135     return;
4136   }
4137   WatchCursor ();
4138   Update ();
4139   complexity = GetBiostrucComplexity ();
4140   maxModels = GetBiostrucMaxModels ();
4141   bsp = EntrezBiostrucGet (uid, complexity, maxModels);
4142   if (bsp == NULL) {
4143     ArrowCursor ();
4144     Update ();
4145     Message (MSG_OK, "Unable to find this record in the database.");
4146     return;
4147   }
4148 
4149   TmpNam (path);
4150   aip = AsnIoOpen (path, "w");
4151 
4152   MemSet ((Pointer) &vn, 0, sizeof (ValNode));
4153   vn.choice = Data_data_structure;
4154   vn.data.ptrvalue = (Pointer) bsp;
4155   vn.next = NULL;
4156 
4157   MemSet ((Pointer) &eg, 0, sizeof (EntrezGeneral));
4158   eg.style = Entrez_style_asn1;
4159   eg.Data_data = &vn;
4160 
4161   MemSet ((Pointer) &mime, 0, sizeof (NcbiMimeAsn1));
4162   mime.choice = NcbiMimeAsn1_entrez;
4163   mime.data.ptrvalue = &eg;
4164   mime.next = NULL;
4165 
4166   NcbiMimeAsn1AsnWrite (&mime, aip, NULL);
4167   /*
4168   BiostrucAsnWrite (bsp, aip, NULL);
4169   */
4170   AsnIoClose (aip);
4171 
4172   BiostrucFree (bsp);
4173 
4174   /* Cn3D expects Ncbi-mime-asn1, not Biostruc */
4175 
4176 #ifdef WIN_MAC
4177   Nlm_SendOpenDocAppleEvent (path, "Cn3D");
4178 #endif
4179 #ifdef WIN_MSWIN
4180   Nlm_GetExecPath ("valfile", prog, sizeof (prog));
4181   Nlm_MSWin_OpenApplication (prog, path);
4182 #endif
4183 #ifdef WIN_MOTIF
4184   /*
4185   argv [0] = path;
4186   argv [1] = NULL;
4187   if (! Execv ("Cn3D", argv)) {
4188     Message (MSG_POST, "Unable to launch Cn3D");
4189   }
4190   */
4191   sprintf (cmmd, "Cn3D %s &", path);
4192   system (cmmd);
4193 #endif
4194 
4195   ArrowCursor ();
4196 #endif
4197 }
4198 
LaunchRecordViewer(Int4 uid,Int2 numAlign,Int4Ptr alignuids,Int2 db)4199 extern void LaunchRecordViewer (Int4 uid, Int2 numAlign, Int4Ptr alignuids, Int2 db)
4200 
4201 {
4202   Int2  typ_aa;
4203   Int2  typ_ch;
4204   Int2  typ_ml;
4205   Int2  typ_nt;
4206   Int2  typ_st;
4207 
4208   if (uid == 0) return;
4209   typ_ml = DatabaseFromName ("MEDLINE");
4210   typ_aa = DatabaseFromName ("Protein");
4211   typ_nt = DatabaseFromName ("Nucleotide");
4212   typ_st = DatabaseFromName ("Structure");
4213   typ_ch = DatabaseFromName ("Genome");
4214   if (db == typ_ml) {
4215     LaunchMedlineViewer (uid, numAlign, alignuids, db);
4216   } else if (db == typ_aa || db == typ_nt) {
4217     LaunchSequenceViewer (uid, numAlign, alignuids, db);
4218   } else if (db == typ_st) {
4219     LaunchStructureViewer (uid, numAlign, alignuids, db);
4220   } else if (db == typ_ch) {
4221     LaunchGenomeViewer (uid, numAlign, alignuids, db);
4222   }
4223 }
4224 
4225 typedef struct prefspage {
4226   DIALOG_MESSAGE_BLOCK
4227   ButtoN             persist;
4228   ButtoN             align;
4229   GrouP              lookup;
4230   ButtoN             showAsn;
4231   PopuP              initDb;
4232   PopuP              initFld;
4233   PopuP              initMode;
4234   PopuP              initMed;
4235   PopuP              initNuc;
4236   PopuP              initProt;
4237   PopuP              initGenome;
4238   TexT               minWidth;
4239   TexT               minHeight;
4240   EnumFieldAssocPtr  dbalist;
4241   EnumFieldAssocPtr  fldalist;
4242   EnumFieldAssocPtr  nucalist;
4243   EnumFieldAssocPtr  protalist;
4244   EnumFieldAssocPtr  gnomalist;
4245 } PrefsPage, PNTR PrefsPagePtr;
4246 
ENUM_ALIST(all_mode_alist)4247 static ENUM_ALIST(all_mode_alist)
4248   {"Automatic",   1},
4249   {"Lookup",      2},
4250   {"MeSH Tree",   3},
4251   {"Range",       4},
4252   {"Selection",   5},
4253   {"Taxonomy",    6},
4254   {"Truncation",  7},
4255 END_ENUM_ALIST
4256 
4257 static ENUM_ALIST(med_views_alist)
4258   {"Abstract",    1},
4259   {"Citation",    2},
4260   {"MEDLINE",     3},
4261   {"ASN.1",       4},
4262 END_ENUM_ALIST
4263 
4264 static void PrefsPtrToPrefsPage (DialoG d, Pointer data)
4265 
4266 {
4267   EntrezPrefsPtr  epp;
4268   PrefsPagePtr    ppp;
4269 
4270   ppp = (PrefsPagePtr) GetObjectExtra (d);
4271   if (ppp == NULL) return;
4272   epp = (EntrezPrefsPtr) data;
4273   if (epp != NULL) {
4274     SetStatus (ppp->persist, epp->persistDefault);
4275     SetStatus (ppp->align, epp->alignDefault);
4276     if (epp->lookupDirect) {
4277       SetValue (ppp->lookup, 2);
4278     } else {
4279       SetValue (ppp->lookup, 1);
4280     }
4281     SetStatus (ppp->showAsn, epp->showAsn);
4282     SetEnumPopupByName (ppp->initDb, ppp->dbalist, epp->initDatabase);
4283     SetEnumPopupByName (ppp->initFld, ppp->fldalist, epp->initField);
4284     SetEnumPopupByName (ppp->initMode, all_mode_alist, epp->initMode);
4285     SetEnumPopupByName (ppp->initMed, med_views_alist, epp->initMedLabel);
4286     SetEnumPopupByName (ppp->initNuc, ppp->nucalist, epp->initNucLabel);
4287     SetEnumPopupByName (ppp->initProt, ppp->protalist, epp->initProtLabel);
4288     SetEnumPopupByName (ppp->initGenome, ppp->gnomalist, epp->initGenomeLabel);
4289   } else {
4290     SetStatus (ppp->persist, TRUE);
4291     SetStatus (ppp->align, TRUE);
4292     SetValue (ppp->lookup, 1);
4293     SetStatus (ppp->showAsn, FALSE);
4294     SetEnumPopupByName (ppp->initDb, ppp->dbalist, "MEDLINE");
4295     SetEnumPopupByName (ppp->initFld, ppp->fldalist, "All Fields");
4296     SetEnumPopupByName (ppp->initMode, all_mode_alist, "Automatic");
4297     SetEnumPopupByName (ppp->initMed, med_views_alist, "Abstract");
4298     SetEnumPopupByName (ppp->initNuc, ppp->nucalist, "GenBank");
4299     SetEnumPopupByName (ppp->initProt, ppp->protalist, "GenPept");
4300     SetEnumPopupByName (ppp->initGenome, ppp->gnomalist, "Map");
4301   }
4302 }
4303 
PrefsPageToPrefsPtr(DialoG d)4304 static Pointer PrefsPageToPrefsPtr (DialoG d)
4305 
4306 {
4307   EntrezPrefsPtr  epp;
4308   PrefsPagePtr    ppp;
4309 
4310   ppp = (PrefsPagePtr) GetObjectExtra (d);
4311   if (ppp == NULL) return NULL;
4312   epp = (EntrezPrefsPtr) MemNew (sizeof (EntrezPrefs));
4313   if (epp == NULL) return NULL;
4314   epp->persistDefault = GetStatus (ppp->persist);
4315   epp->alignDefault = GetStatus (ppp->align);
4316   epp->lookupDirect = (GetValue (ppp->lookup) == 2);
4317   epp->showAsn = GetStatus (ppp->showAsn);
4318   epp->initDatabase = GetEnumPopupByName (ppp->initDb, ppp->dbalist);
4319   epp->initField = GetEnumPopupByName (ppp->initFld, ppp->fldalist);
4320   epp->initMode = GetEnumPopupByName (ppp->initMode, all_mode_alist);
4321   epp->initMedLabel = GetEnumPopupByName (ppp->initMed, med_views_alist);
4322   epp->initNucLabel = GetEnumPopupByName (ppp->initNuc, ppp->nucalist);
4323   epp->initProtLabel = GetEnumPopupByName (ppp->initProt, ppp->protalist);
4324   epp->initGenomeLabel = GetEnumPopupByName (ppp->initGenome, ppp->gnomalist);
4325   return (Pointer) epp;
4326 }
4327 
MakePageSpecAlist(SeqViewProcsPtr svpp,Boolean nucOK,Boolean protOK,Boolean genomeOK)4328 static EnumFieldAssocPtr MakePageSpecAlist (SeqViewProcsPtr svpp, Boolean nucOK,
4329                                             Boolean protOK, Boolean genomeOK)
4330 
4331 {
4332   EnumFieldAssocPtr  alist;
4333   EnumFieldAssocPtr  ap;
4334   BioseqPagePtr      bpp;
4335   Int2               i;
4336 
4337   if (svpp == NULL) return NULL;
4338   bpp = svpp->pageSpecs;
4339   i = 0;
4340   while (bpp != NULL) {
4341     i++;
4342     bpp = bpp->next;
4343   }
4344   alist = MemNew (sizeof (EnumFieldAssoc) * (i + 2));
4345   if (alist == NULL) return NULL;
4346   ap = alist;
4347   bpp = svpp->pageSpecs;
4348   i = 0;
4349   while (bpp != NULL) {
4350     if ((nucOK && bpp->nucOK) ||
4351         (protOK && bpp->protOK) ||
4352         (genomeOK && bpp->genomeOK)) {
4353       ap->name = StringSave (bpp->label);
4354       ap->value = i;
4355       ap++;
4356       i++;
4357     }
4358     bpp = bpp->next;
4359   }
4360   ap->name = NULL;
4361   return alist;
4362 }
4363 
EntrezPrefsNew(void)4364 extern EntrezPrefsPtr EntrezPrefsNew (void)
4365 
4366 {
4367   EntrezPrefsPtr  epp;
4368 
4369   epp = (EntrezPrefsPtr) MemNew (sizeof (EntrezPrefs));
4370   return epp;
4371 }
4372 
EntrezPrefsFree(EntrezPrefsPtr epp)4373 extern EntrezPrefsPtr EntrezPrefsFree (EntrezPrefsPtr epp)
4374 
4375 {
4376   if (epp == NULL) return NULL;
4377   epp->initDatabase = MemFree (epp->initDatabase);
4378   epp->initField = MemFree (epp->initField);
4379   epp->initMode = MemFree (epp->initMode);
4380   epp->initMedLabel = MemFree (epp->initMedLabel);
4381   epp->initNucLabel = MemFree (epp->initNucLabel);
4382   epp->initProtLabel = MemFree (epp->initProtLabel);
4383   epp->initGenomeLabel = MemFree (epp->initGenomeLabel);
4384   return NULL;
4385 }
4386 
CleanupEntrezPrefsProc(GraphiC g,VoidPtr data)4387 static void CleanupEntrezPrefsProc (GraphiC g, VoidPtr data)
4388 
4389 {
4390   PrefsPagePtr  ppp;
4391 
4392   ppp = (PrefsPagePtr) data;
4393   if (ppp != NULL) {
4394     ppp->dbalist = FreeEnumFieldAlist (ppp->dbalist);
4395     ppp->fldalist = FreeEnumFieldAlist (ppp->fldalist);
4396     ppp->nucalist = FreeEnumFieldAlist (ppp->nucalist);
4397     ppp->protalist = FreeEnumFieldAlist (ppp->protalist);
4398     ppp->gnomalist = FreeEnumFieldAlist (ppp->gnomalist);
4399   }
4400   StdCleanupExtraProc (g, data);
4401 }
4402 
CreateEntrezPrefsDialog(GrouP prnt,CharPtr title)4403 extern DialoG CreateEntrezPrefsDialog (GrouP prnt, CharPtr title)
4404 
4405 {
4406   EntrezGlobalsPtr  egp;
4407   EntrezInfoPtr     eip;
4408   GrouP             g1, g2, g3, g4, g5;
4409   Boolean           macLike;
4410   GrouP             p;
4411   PrefsPagePtr      ppp;
4412   GrouP             s;
4413   SeqViewProcsPtr   svpp;
4414 
4415   p = HiddenGroup (prnt, 1, 0, NULL);
4416   SetGroupSpacing (p, 10, 10);
4417 
4418   eip = EntrezGetInfo ();
4419   if (eip == NULL || eip->type_info == NULL ||
4420       eip->types == NULL || eip->field_info == NULL) return (DialoG) p;
4421 
4422   egp = (EntrezGlobalsPtr) GetAppProperty ("EntrezGlobals");
4423   if (egp == NULL) return (DialoG) p;
4424   macLike = egp->popdownBehavior;
4425 
4426   svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
4427   if (svpp == NULL) return (DialoG) p;
4428 
4429   ppp = (PrefsPagePtr) MemNew (sizeof (PrefsPage));
4430   if (ppp != NULL) {
4431 
4432     SetObjectExtra (p, ppp, CleanupEntrezPrefsProc);
4433     ppp->dialog = (DialoG) p;
4434     ppp->todialog = PrefsPtrToPrefsPage;
4435     ppp->fromdialog = PrefsPageToPrefsPtr;
4436 
4437     ppp->dbalist = MakeDatabaseAlist (eip->type_info, eip->type_count, FALSE);
4438     ppp->fldalist = MakeFieldAlist (eip->types, eip->field_info, eip->field_count, 0, TRUE);
4439 
4440     ppp->nucalist = MakePageSpecAlist (svpp, TRUE, FALSE, FALSE);
4441     ppp->protalist = MakePageSpecAlist (svpp, FALSE, TRUE, FALSE);
4442     ppp->gnomalist = MakePageSpecAlist (svpp, FALSE, FALSE, TRUE);
4443 
4444     if (title != NULL && title [0] != '\0') {
4445       s = NormalGroup (p, -1, 0, title, systemFont, NULL);
4446     } else {
4447       s = HiddenGroup (p, -1, 0, NULL);
4448     }
4449     SetGroupSpacing (s, 10, 10);
4450 
4451     g1 = HiddenGroup (s, -1, 0, NULL);
4452     g5 = HiddenGroup (g1, 3, 0, NULL);
4453     SetGroupSpacing (g5, 10, 3);
4454     ppp->persist = CheckBox (g5, "Parents Persist", NULL);
4455     ppp->align = CheckBox (g5, "Align Checked", NULL);
4456     ppp->showAsn = CheckBox (g5, "Show ASN.1 Report", NULL);
4457     g2 = HiddenGroup (g1, 2, 0, NULL);
4458     StaticPrompt (g2, "Lookup Mode Launches", 0, stdLineHeight, programFont, 'l');
4459     ppp->lookup = HiddenGroup (g2, 2, 0, NULL);
4460     RadioButton (ppp->lookup, "DocSum");
4461     RadioButton (ppp->lookup, "Record");
4462     AlignObjects (ALIGN_CENTER, (HANDLE) g2, (HANDLE) g5, NULL);
4463 
4464     g3 = HiddenGroup (s, 0, 2, NULL);
4465 
4466     StaticPrompt (g3, "Database", 0, 0, programFont, 'l');
4467     ppp->initDb = PopupList (g3, macLike, NULL);
4468     InitEnumPopup (ppp->initDb, ppp->dbalist, NULL);
4469     SetEnumPopupByName (ppp->initDb, ppp->dbalist, "MEDLINE");
4470 
4471     StaticPrompt (g3, "Field", 0, 0, programFont, 'l');
4472     ppp->initFld = PopupList (g3, macLike, NULL);
4473     InitEnumPopup (ppp->initFld, ppp->fldalist, NULL);
4474     SetEnumPopupByName (ppp->initFld, ppp->fldalist, "All Fields");
4475 
4476     StaticPrompt (g3, "Mode", 0, 0, programFont, 'l');
4477     ppp->initMode = PopupList (g3, macLike, NULL);
4478     InitEnumPopup (ppp->initMode, all_mode_alist, NULL);
4479     SetEnumPopupByName (ppp->initMode, all_mode_alist, "Automatic");
4480 
4481     g4 = HiddenGroup (s, 0, 2, NULL);
4482 
4483     StaticPrompt (g4, "MEDLINE", 0, 0, programFont, 'l');
4484     ppp->initMed = PopupList (g4, macLike, NULL);
4485     InitEnumPopup (ppp->initMed, med_views_alist, NULL);
4486     SetEnumPopupByName (ppp->initMed, med_views_alist, "Abstract");
4487 
4488     StaticPrompt (g4, "Nucleotide", 0, 0, programFont, 'l');
4489     ppp->initNuc = PopupList (g4, macLike, NULL);
4490     InitEnumPopup (ppp->initNuc, ppp->nucalist, NULL);
4491     SetEnumPopupByName (ppp->initNuc, ppp->nucalist, "GenBank");
4492 
4493     StaticPrompt (g4, "Protein", 0, 0, programFont, 'l');
4494     ppp->initProt = PopupList (g4, macLike, NULL);
4495     InitEnumPopup (ppp->initProt, ppp->protalist, NULL);
4496     SetEnumPopupByName (ppp->initProt, ppp->protalist, "GenPept");
4497 
4498     StaticPrompt (g4, "Genome", 0, 0, programFont, 'l');
4499     ppp->initGenome = PopupList (g4, macLike, NULL);
4500     InitEnumPopup (ppp->initGenome, ppp->gnomalist, NULL);
4501     SetEnumPopupByName (ppp->initGenome, ppp->gnomalist, "Map");
4502 
4503     AlignObjects (ALIGN_CENTER, (HANDLE) g1, (HANDLE) g3, (HANDLE) g4, NULL);
4504   }
4505 
4506   return (DialoG) p;
4507 }
4508 
4509