File: udvopen.c

package info (click to toggle)
ncbi-tools6 6.1.20120620-8
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 241,628 kB
  • ctags: 101,236
  • sloc: ansic: 1,431,713; cpp: 6,248; pascal: 3,949; xml: 3,390; sh: 3,090; perl: 1,077; csh: 488; makefile: 449; ruby: 93; lisp: 81
file content (1436 lines) | stat: -rw-r--r-- 36,868 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
/*   udvopen.c
* ===========================================================================
*
*                            PUBLIC DOMAIN NOTICE
*            National Center for Biotechnology Information (NCBI)
*
*  This software/database is a "United States Government Work" under the
*  terms of the United States Copyright Act.  It was written as part of
*  the author's official duties as a United States Government employee and
*  thus cannot be copyrighted.  This software/database is freely available
*  to the public for use. The National Library of Medicine and the U.S.
*  Government do not place any restriction on its use or reproduction.
*  We would, however, appreciate having the NCBI and the author cited in
*  any work or product based on this material
*
*  Although all reasonable efforts have been taken to ensure the accuracy
*  and reliability of the software and data, the NLM and the U.S.
*  Government do not and cannot warrant the performance or results that
*  may be obtained by using this software or data. The NLM and the U.S.
*  Government disclaim all warranties, express or implied, including
*  warranties of performance, merchantability or fitness for any particular
*  purpose.
*
* ===========================================================================
*
* File Name:  udvopen.c
*
* Author:  Patrick Durand
*
* Version Creation Date:   5/3/99
*
* $Revision: 6.21 $
*
* File Description: open/close/choose sequence/file from disk/network
*
* Modifications:
* --------------------------------------------------------------------------
* $Log: udvopen.c,v $
* Revision 6.21  2006/07/13 17:13:18  bollin
* use Uint4 instead of Uint2 for itemID values
*
* Revision 6.20  2000/07/26 17:26:26  lewisg
* fix code for c++ inclusion
*
* Revision 6.19  2000/06/16 14:57:02  lewisg
* move entrez calls out of desktop
*
* Revision 6.18  2000/05/01 21:21:13  lewisg
* make features dialogs modal
*
* Revision 6.17  2000/04/27 22:21:58  lewisg
* misc bugs/features
*
* Revision 6.16  2000/04/13 13:58:03  durand
* allowed udv to display reverse complement sequence
*
* Revision 6.15  2000/04/10 20:33:40  lewisg
* fix show/hide for blast multiple, make blast multiple API generic
*
* Revision 6.14  2000/03/15 19:32:20  lewisg
* launch only single udv window
*
* Revision 6.13  2000/03/06 19:54:40  durand
* updated the function AccessionToGi_Entrez
*
* Revision 6.12  2000/03/02 15:47:51  durand
* use MovableModalWindow for dialog boxes
*
* Revision 6.11  2000/02/16 14:49:39  durand
* replace GatherProcLaunch by GatherSpecificProcLaunch
*
* Revision 6.10  2000/01/11 15:03:19  durand
* remove network stuff
*
* Revision 6.9  2000/01/10 15:18:40  durand
* use Entrez instead of ID1
*
* Revision 6.8  1999/11/29 15:17:55  durand
* designed a new GUI; fixed problems under Win95 and Linux
*
* Revision 6.7  1999/11/19 15:01:48  durand
* speed up mouse selection ; avoid sequence flashing during selection ; update menu functionalities
*
* Revision 6.6  1999/11/09 21:06:59  durand
* add sequence selection manager
*
* Revision 6.5  1999/10/02 15:11:16  durand
* update the code to be used by wwwudv
*
* Revision 6.4  1999/09/07 15:32:39  durand
* add BBS and RefSeq to databases list
*
* Revision 6.3  1999/06/07 15:39:44  durand
* add LOG line to keep track of the history
*
*
*
* ==========================================================================
*/

#include <udviewer.h>
#if 0
#include <blast.h>
#include <netblap3.h>
#endif


	typedef struct dlgfileopendata {/*use to manage the FileOpen dialog box*/
		WindoW 		parent;			/*main window of the application*/
		TexT		FNameEditCtrl;	/*handle of the file text control*/
		ButtoN		Ok;				/*handle of the Ok button*/
		GrouP		ReadMode;		/*handle of the file type control*/
	} DlgFileOpenData, PNTR DlgFileOpenDataPtr;


/*local struct used only by the Download sequence dialog box*/
	typedef struct udvnetopen {
		WindoW 			hWndMain;	/*main window*/
		TexT			Entry;		/*Entrez entry*/
		PopuP			AccessType;	/*database type*/
		ButtoN  		ok;			/*ok button*/
		UDVMainMenuPtr 	mmp;		/*main menu*/
	} UDVNetOpen, PNTR UDVNetOpenPtr;

/*local struct used only by the Choose sequence dialog box*/
	typedef struct udvchooseseq {
		WindoW 	hWndMain;		/*main window*/
		LisT	bsp_list;		/*listbox of bsps*/
	} UDVChooseSeq, PNTR UDVChooseSeqPtr;

	static Char szAppName[]="OneD-Viewer";

	static Uint1 UDV_DataBaseID[]={
				SEQID_GENBANK,
				SEQID_EMBL,
				SEQID_PIR,
				SEQID_SWISSPROT,
				SEQID_GI,
				SEQID_DDBJ,
				SEQID_PRF,
				SEQID_PDB,
				SEQID_OTHER,/*RefSeq*/
				SEQID_GIBBSQ};


/*******************************************************************************

  Function : UDV_Init_vdp_struct()
  
  Purpose : free memory of a bsp
  
  Parameters : vdp; contains data to delete
  				EraseParaG; TRUE means delete vdp->ParaG
				EraseMainTitle; TRUE means restore default viewer window name
				EraseInfoPanel; TRUE means delete content of InfoPanel
  
  Return value : none 

*******************************************************************************/
NLM_EXTERN void  UDV_Init_vdp_struct(PaneL p,ViewerDialogDataPtr vdp, 
	Boolean EraseParaG,Boolean EraseMainTitle,Boolean EraseInfoPanel)
{
BaR 	vsb;

	if (!vdp) return;
	
	if (EraseParaG) UDV_FreeListParaG(&vdp->ParaG);

	MemSet(&vdp->bsp_i,0,sizeof(BspInfo));

	/*invalid Item selection identifier*/
	vdp->Item_select.eIDsel=(Uint2)-1;
	vdp->Item_select.iIDsel=(Uint2)-1;
	vdp->Item_select.iTypeSel=(Uint2)-1;
	vdp->Old_Item_select=vdp->Item_select;

	/*reinit scrollbar*/
	vsb = GetSlateVScrollBar ((SlatE)p);
	CorrectBarMax(vsb,0);
	CorrectBarValue(vsb,0);
	CorrectBarPage(vsb,0,0);
	
	/*reset winmain title*/
	if (EraseMainTitle){
		if (vdp->Parent) 
			SetTitle(vdp->Parent,szAppName);
	}
	
	/*reset infopanel title*/
	if (EraseInfoPanel && vdp->InfoPanel) 
		SetTitle(vdp->InfoPanel,"Ready !");
}

/*******************************************************************************

  Function : SearchBioseq()
  
  Purpose : store bsps of a SeqEntry 
  
  Parameters : see Toolbox doc !
  
  Return value : none 

*******************************************************************************/
NLM_EXTERN Boolean LIBCALLBACK SearchBioseq (BioseqPtr bsp, 
			SeqMgrBioseqContextPtr context)
{
ValNodePtr PNTR	BspTable;
	
	BspTable=(ValNodePtr PNTR)context->userdata;

	if (bsp) {
		ValNodeAddInt(BspTable,1,
				UDV_EncodeIdxFeat(context->entityID,context->itemID));
	}

	return(TRUE);
}


/*******************************************************************************

  Function : UDV_analyze_SEP_for_open()
  
  Purpose : analyse a SEP coming form a local SeqEntry file or from Entrez,
  			and find the BSPs. 
  
  Parameters : the_set; SeqEntry to analyze
  				vmp; general data software
				w; window which has called this function
				mon; monitor
  
  Return value : If error, return FALSE.  

*******************************************************************************/
NLM_EXTERN Boolean  UDV_analyze_SEP_for_open(FILE *fp,SeqEntryPtr the_set,
	ViewerMainPtr vmp,WindoW w)
{
BioseqPtr 	bsp;
Boolean 	bRet=TRUE,bReadOk=FALSE;
Pointer     dataptr;
Uint2       datatype,entityID,eID;
Uint4       iID;
MonitorPtr  mon;
RecT        rcP;
WindoW      temport;
	
	if (vmp->hFeatDlg){/*Features List Dlg Box*/
		SetStatus(vmp->MainMenu.ShowFeatureList,FALSE);
		Remove(vmp->hFeatDlg);
		vmp->hFeatDlg=NULL;
	}
	/*free data, remove viewer*/
	if (vmp->vdp){
		UDV_FreeVDPstruct(vmp->vdp,FALSE);

		SetValue(vmp->MainMenu.ScalePosChoice,3);
		SetStatus(vmp->MainMenu.ShowFeature,TRUE);
		UDV_set_MainMenus(&vmp->MainMenu,FALSE);
		UDV_set_MainControls(vmp,FALSE);
	}
	if (vmp->BspTable){
		ValNodeFree(vmp->BspTable);
		vmp->BspTable=NULL;
		vmp->BspChoice=0;
	}
	if (vmp->dataptr && vmp->datatype){
		ObjMgrFree(vmp->datatype,vmp->dataptr);
		vmp->datatype=0;
		vmp->dataptr=NULL;
	}

	mon = MonitorStrNewEx (szAppName, 30, FALSE);
	WatchCursor();
	
	if (fp!=NULL){/*open a file*/
		/*Read the file*/
		MonitorStrValue (mon, "Reading ASN.1 file");
		Update ();
		dataptr = ReadAsnFastaOrFlatFile (fp, &datatype, NULL, 
			FALSE, FALSE, FALSE, FALSE);
		/*register for ObjMgr*/
		entityID = ObjMgrRegister (datatype, dataptr);
		if(datatype == OBJ_SEQSUB || datatype == OBJ_SEQENTRY ||
        	datatype == OBJ_BIOSEQ || datatype == OBJ_BIOSEQSET){
			bReadOk=TRUE;
		}
	}
	else if (the_set!=NULL){/*retrieve a Network Entry*/
		/*a complete verification of sep is done elsewhere; here
		sep can be only Bioseq or BioseqSet*/
		if (IS_Bioseq (the_set)) datatype = OBJ_BIOSEQ;
		else datatype = OBJ_BIOSEQSET;

		dataptr=(Pointer)the_set->data.ptrvalue;
		/*register for ObjMgr*/
		entityID = ObjMgrRegister (datatype, dataptr);
		bReadOk=TRUE;
		
	}
	
	if (bReadOk){
		Boolean bReverse;
		/*compute the global Feature Index*/
		MonitorStrValue (mon, "Building Feature index...");
		Update ();
		if (vmp->vdp)
			bReverse=vmp->vdp->bDisplayRevComp;
		else
			bReverse=FALSE;
		UDV_CreateOneFeatureIndex(entityID,NULL,bReverse);						
		/*scan the BSPs*/
		SeqMgrExploreBioseqs (entityID, NULL, (Pointer) &vmp->BspTable, 
			SearchBioseq, TRUE, TRUE, TRUE);
	}

	if (vmp->BspTable==NULL){
		MonitorFree (mon);
		ArrowCursor();
		Message (MSG_ERROR, "No sequence found in your entry.");
		bRet=FALSE;
		goto error;
	}

	vmp->entityID=entityID;
	vmp->datatype=datatype;
	vmp->dataptr=dataptr;
	
	/*choose the first sequence by default*/
	UDV_DecodeIdxFeat ((Uint4)vmp->BspTable->data.intvalue,&eID,&iID);
	bsp=GetBioseqGivenIDs (eID, iID, OBJ_BIOSEQ);
	if (bsp){
		vmp->BspChoice=1;
		ArrowCursor();
		MonitorFree (mon);
		vmp->Show_logo=FALSE;	
		if (vmp->UDVprocid!=0){
			GatherSpecificProcLaunch(vmp->UDVprocid, "OneD-Viewer", 
				OMPROC_VIEW, FALSE, eID, iID, OBJ_BIOSEQ);
		}
		else{
			GatherProcLaunch(OMPROC_VIEW, FALSE, eID, iID, OBJ_BIOSEQ, 
				OBJ_BIOSEQ, 0, OBJ_BIOSEQ, 0);
		}

		temport=SavePort(vmp->hWndMain);
		Select(vmp->vdp->UnDViewer);
		ObjectRect(vmp->vdp->UnDViewer,&rcP);
		InvalRect(&rcP);
		Update();
		RestorePort(temport);
	}
	else {
		MonitorFree (mon);
		ArrowCursor();
		Message (MSG_ERROR, "No sequence found in your file.");
		bRet=FALSE;
	}

error:
	if (!bRet){/*show the logo in case of error*/
		vmp->Show_logo=TRUE;	
		UDV_set_MainMenus(&vmp->MainMenu,FALSE);
		UDV_set_MainControls(vmp,FALSE);
	}
	return (bRet);
}

/*******************************************************************************

  Function : AccessionToGi_Entrez()
  
  Purpose : given s string, retrieve the UID 
  
  Parameters : string, either a name or an accession number	
  				type; entry choosen by the nice user in the dataBase type
					popup list
  
  Return value : none 

*******************************************************************************/
static Int4 AccessionToGi_Entrez (CharPtr string,Int2 type)
{
SeqIdPtr 	sip;
Int4 		uid=0;
Uint1 		Choice;

	sip=(SeqIdPtr)ValNodeNew(NULL);
	if (!sip) return(0);

	Choice=UDV_DataBaseID[type-1];

	switch(Choice){
		case SEQID_GENBANK:
		case SEQID_EMBL:
		case SEQID_PIR:
		case SEQID_DDBJ:
		case SEQID_PRF:
		case SEQID_SWISSPROT:
		case SEQID_OTHER:{
			TextSeqIdPtr tsip;
			
			tsip=TextSeqIdNew();
			if (!tsip) break;
			sip->data.ptrvalue=(VoidPtr)tsip;
			sip->choice = Choice;
			/*try to retrieve an uid; to avoid the user to know whether string
			is an accession or a name, this function tests both*/
			tsip->name=StringSave(string);
			uid=GetGIForSeqId(sip);
			if (uid==0){
				*tsip->name='\0';
				tsip->accession=StringSave(string);
			}
			TextSeqIdFree(tsip);
			break;
		}
		case SEQID_GIBBSQ:
			sip->data.intvalue=(Int4)atoi(string);
			sip->choice = Choice;
			uid=GetGIForSeqId(sip);
			break;
		case SEQID_GI:
			if (!StrToLong(string,&uid)) uid=0;
			break;
		case SEQID_PDB:{
			PDBSeqIdPtr psip;
			
			psip=PDBSeqIdNew();
			if (!psip) break;
			sip->data.ptrvalue=(VoidPtr)psip;
			/*type is one of the SEQID_... reported in objloc.h*/
			sip->choice = Choice;
			/*try to retrieve an uid; to avoid the user to know whether string
			is an accession or a name, this function tests both*/
			psip->mol=StringSave(string);
			psip->chain=0;        /* 0 = no chain set.  default = 32 */
        	psip->rel=NULL;
			uid=GetGIForSeqId(sip);
			PDBSeqIdFree(psip);
			break;
		}
	}

	ValNodeFree(sip);
	return(uid);
}


/*******************************************************************************

  Function : UDV_NetOpen_okProc()
  
  Purpose : manage ok button of the Network open dialog box 
  
  Parameters : g; button
  
  Return value : none 

*******************************************************************************/
static void UDV_NetOpen_okProc(ButtoN g)
{
WindoW			hOpenDlg;
UDVNetOpenPtr 	unop;
Char 			szAccess[50]={""};
Int2			AccessType;
Int4			uid=0;
ViewerMainPtr 	vmp;
MonitorPtr  	mon;
SeqEntryPtr		sep=NULL;
Boolean			bReadok=FALSE;
UdvGlobalsPtr   ugp=NULL;

	hOpenDlg=(WindoW)ParentWindow(g);

	if (!hOpenDlg) return;
	
	unop = (UDVNetOpenPtr) GetObjectExtra (hOpenDlg);	

	if (unop==NULL) return;

	vmp = (ViewerMainPtr) GetObjectExtra (unop->hWndMain);
	if (vmp==NULL) return;

	Hide(hOpenDlg);
	
	/*retrieve and analyze Accession or Gi*/
	GetTitle(unop->Entry, szAccess, sizeof(szAccess));

	if (StringHasNoText (szAccess)) {
		Message (MSG_OK, "Please enter an accession number or an entry name");
		Show (hOpenDlg);
		Select (hOpenDlg);
		Select (unop->Entry);
		return;
	}

	AccessType=GetValue(unop->AccessType);
	WatchCursor();
	uid=AccessionToGi_Entrez(szAccess,AccessType);	
	/*Connect ID1 with a valid UID*/
	if (uid==0){
		ArrowCursor();
		Message (MSG_OK, "Unable to find your record in the database.");
		Show (hOpenDlg);
		Select (hOpenDlg);
		Select (unop->Entry);
		return;
	}
	else{
		mon = MonitorStrNewEx (szAppName, 30, FALSE);
		MonitorStrValue (mon, "Retrieving your record...");
		Update ();
	
		ugp=(UdvGlobalsPtr)GetAppProperty("UdvGlobals");
		if (ugp && ugp->fetchSepProc) {
				sep=ugp->fetchSepProc(uid, 0);
		}
				
		ArrowCursor();
		MonitorFree (mon);
		if (sep){
			if (IS_Bioseq (sep) || IS_Bioseq_set (sep))	bReadok=TRUE;
			else bReadok=FALSE;
		}
		else bReadok=FALSE;
		
		if (bReadok){
			UDV_analyze_SEP_for_open(NULL,sep,vmp,unop->hWndMain);
		}
		else{
			Message (MSG_OK, "Unable to retrieve your record in the database.");
		}
	}

	/*enable main menus and delete Download dlg box*/
	UDV_set_PullMenus(unop->mmp,TRUE);
	Remove(hOpenDlg);
}

/*******************************************************************************

  Function : UDV_NetOpen_cancelProc()
  
  Purpose : manage ok button of the Network open dialog box 
  
  Parameters : g; button
  
  Return value : none 

*******************************************************************************/
static void UDV_NetOpen_cancelProc(ButtoN g)
{
WindoW			hOpenDlg;
UDVNetOpenPtr 	unop;

	hOpenDlg=(WindoW)ParentWindow(g);

	if (!hOpenDlg) return;
	
	unop = (UDVNetOpenPtr) GetObjectExtra (hOpenDlg);

	if (unop==NULL) return;

	/*enable main menus and delete Download dlg box*/
	UDV_set_PullMenus(unop->mmp,TRUE);
	Remove(hOpenDlg);
}

/*******************************************************************************

  Function : UDV_NetOpen_access()
  
  Purpose : manage Accession edit control of the Download dialog box 
  
  Parameters : t; edit control
  
  Return value : none 

*******************************************************************************/
static void UDV_NetOpen_access(TexT t)
{
Char 			szAccess[50]={""};
WindoW			hOpenDlg;
UDVNetOpenPtr 	unop;

	hOpenDlg=(WindoW)ParentWindow(t);

	if (!hOpenDlg) return;
	
	unop = (UDVNetOpenPtr) GetObjectExtra (hOpenDlg);

	if (unop==NULL) return;
	
	GetTitle(t, szAccess, sizeof(szAccess));

	if (StringLen(szAccess) == 0)
		Disable(unop->ok);
	else Enable(unop->ok);

	return;
}

/*******************************************************************************

  Function : UDV_NetOpen()
  
  Purpose : retrieve a file from Download dialog box 
  
  Parameters : g; button
  
  Return value : none 

*******************************************************************************/
NLM_EXTERN void UDV_NetOpen (IteM i)
{
GrouP			c,g;
WindoW			w,hWinMain;
UDVNetOpenPtr 	unop;
ViewerMainPtr 	vmp;
UdvGlobalsPtr ugp;

	hWinMain=(WindoW)ParentWindow(i);

	if (!hWinMain) return;
	
	vmp = (ViewerMainPtr) GetObjectExtra (hWinMain);
	if (vmp==NULL) return;

	/*init the Network, if needed*/
	ugp=(UdvGlobalsPtr)GetAppProperty("UdvGlobals");
	if (ugp && ugp->NetStartProc){
		if (!ugp->NetStartProc(vmp->UseNetwork)) return;
	}

	w = MovableModalWindow (-50, -33, -10, -10, "Download From NCBI", NULL);

	if (w==NULL) return;

	unop=(UDVNetOpenPtr)MemNew(sizeof(UDVNetOpen));
	if (unop==NULL) {
		Remove(w);
		return;
	}
	unop->hWndMain=hWinMain;
	
	SetGroupSpacing (w, 10, 10);

	/*accesion*/
	g = NormalGroup (w, 3, 0, "Entry", systemFont,NULL);

#ifdef WIN_MAC
	unop->AccessType = PopupList (g, TRUE, NULL);
#endif

#ifndef WIN_MAC
	unop->AccessType = PopupList (g, FALSE, NULL);
#endif

	PopupItem(unop->AccessType,"GENBANK");
	PopupItem(unop->AccessType,"EMBL");
	PopupItem(unop->AccessType,"PIR");
	PopupItem(unop->AccessType,"SWISSPROT");
	PopupItem(unop->AccessType,"GI number");
	PopupItem(unop->AccessType,"DDBJ");
	PopupItem(unop->AccessType,"PRF");
	PopupItem(unop->AccessType,"PDB");
	PopupItem(unop->AccessType,"RefSeq");
	PopupItem(unop->AccessType,"BBS");
	
	SetValue (unop->AccessType, 6);

	unop->Entry = DialogText (g, "", 10, UDV_NetOpen_access);

	/*retrieve - cancel*/
	c = HiddenGroup (w, 4, 0, NULL);
	SetGroupSpacing (c, 10, 2);
	unop->ok=DefaultButton (c, "Retrieve", UDV_NetOpen_okProc);
	Disable (unop->ok);
	PushButton (c, "Cancel", UDV_NetOpen_cancelProc);
	
	SetObjectExtra (w, (Pointer) unop, StdCleanupExtraProc);

	/*display*/
	AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) c, NULL);
	RealizeWindow (w);
	Show (w);
	Select (w);
	Update ();
	
	/*disable all menus*/
	unop->mmp=&vmp->MainMenu;
	UDV_set_PullMenus(unop->mmp,FALSE);
}

/*******************************************************************************

  Function : UDV_FOpenTextProc()
  
  Purpose : manage File name edit control of the FileOpen dialog box 
  
  Parameters : t; edit control
  
  Return value : none 

*******************************************************************************/
static void UDV_FOpenTextProc(TexT t)
{
Char 				szFName[PATH_MAX]={""};
WindoW				hOpenDlg;
DlgFileOpenDataPtr  dfodp;

	hOpenDlg=(WindoW)ParentWindow(t);

	if (!hOpenDlg) return;
	
	dfodp = (DlgFileOpenDataPtr) GetObjectExtra (hOpenDlg);

	if (dfodp==NULL) return;
	
	GetTitle(t, szFName, sizeof(szFName)-1);

	if (StringLen(szFName) == 0)
		Disable(dfodp->Ok);
	else Enable(dfodp->Ok);

	return;
}

/*******************************************************************************

  Function : UDV_FOpenBrowseProc()
  
  Purpose : manage browse button of the FileOpen dialog box 
  
  Parameters : g; button
  
  Return value : none 

*******************************************************************************/
static void UDV_FOpenBrowseProc(ButtoN g)
{
DlgFileOpenDataPtr  dfodp;
WindoW				hOpenDlg;
Char 				path[PATH_MAX]={""};

	hOpenDlg=(WindoW)ParentWindow(g);

	if (!hOpenDlg) return;

	dfodp = (DlgFileOpenDataPtr) GetObjectExtra (hOpenDlg);

	if (dfodp==NULL) return;
	if (!dfodp->FNameEditCtrl) return;

	if (GetInputFileName (path, sizeof(path), NULL, NULL)){ 
		SetTitle(dfodp->FNameEditCtrl, path);
		UDV_FOpenTextProc(dfodp->FNameEditCtrl);
	}

	return;   
}

/*******************************************************************************

  Function : UDV_FOpenCancelProc()
  
  Purpose : manage cancel button of the FileOpen dialog box 
  
  Parameters : g; button
  
  Return value : none 

*******************************************************************************/
static void UDV_FOpenCancelProc(ButtoN g)
{
WindoW				hOpenDlg;
DlgFileOpenDataPtr  dfodp;
ViewerMainPtr 		vmp;

	hOpenDlg=(WindoW)ParentWindow(g);

	if (!hOpenDlg) return;
	dfodp = (DlgFileOpenDataPtr) GetObjectExtra (hOpenDlg);
	
	if (dfodp){
		vmp = (ViewerMainPtr) GetObjectExtra (dfodp->parent);
		Enable(vmp->MainMenu.FileOpen);
	}
	
	Remove(hOpenDlg);
    UDV_set_PullMenus(&vmp->MainMenu,TRUE);
}


/*******************************************************************************

  Function : UDV_FOpenAcceptProc()
  
  Purpose : manage ok button of the FileOpen dialog box 
  
  Parameters : g; button
  
  Return value : none 

*******************************************************************************/
static void UDV_FOpenAcceptProc(ButtoN g)
{
WindoW				hOpenDlg,w;
DlgFileOpenDataPtr  dfodp;
ViewerMainPtr 		vmp;
Char 				szFName[PATH_MAX]={""};
Boolean				isBinary;
FILE				*fp;
UdvGlobalsPtr       ugp;

	hOpenDlg=(WindoW)ParentWindow(g);

	if (!hOpenDlg) return;
	dfodp = (DlgFileOpenDataPtr) GetObjectExtra (hOpenDlg);
	
	if (dfodp){
		w=dfodp->parent;
		vmp = (ViewerMainPtr) GetObjectExtra (w);
		if (vmp!=NULL){
			/*try to connect Entrez; if failure, still ok : the user can
			use DDV with a local file. Otherwise he/she will be in trouble ;-)*/
			ugp=(UdvGlobalsPtr)GetAppProperty("UdvGlobals");
			if (ugp && ugp->NetStartProc){
				if (!ugp->NetStartProc(vmp->UseNetwork)) return;
			}

			Enable(vmp->MainMenu.FileOpen);
			/*file name*/
			GetTitle(dfodp->FNameEditCtrl, szFName, sizeof(szFName));

			/*file reading mode*/
			if (GetValue(dfodp->ReadMode)==2) isBinary=TRUE;
			else isBinary=FALSE;
	
			Remove(hOpenDlg);

			/* open the i/o files in the correct mode */
			if ((fp = FileOpen (szFName, isBinary?"rb":"r")) == NULL){
				Message (MSG_ERROR, "Unable to open your file.");
				goto error;
			}
			
			UDV_analyze_SEP_for_open(fp,NULL,vmp,w);
			FileClose(fp);
		}
	}
	
error:	
    UDV_set_PullMenus(&vmp->MainMenu,TRUE);
}

/*******************************************************************************

  Function : UDV_FileOpen()
  
  Purpose : callback of the File|Open command 
  
  Parameters : i; command item
  
  Return value : none 

*******************************************************************************/
NLM_EXTERN void UDV_FileOpen(IteM i)
{
DlgFileOpenDataPtr  dfodp;
ViewerMainPtr 		vmp;
WindoW				hWinMain,hOpenDlg;
GrouP				g,g4;
ButtoN				b,b1,b2;
TexT				t1;    

	hWinMain=(WindoW)ParentWindow(i);

	if (!hWinMain) return;
	
	vmp = (ViewerMainPtr) GetObjectExtra (hWinMain);

	if (vmp==NULL) return;
		
	dfodp=(DlgFileOpenDataPtr)MemNew(sizeof(DlgFileOpenData));
	if (!dfodp) return;
	MemSet(dfodp,0,sizeof(DlgFileOpenData));

    hOpenDlg = MovableModalWindow(-30, -20,  -10,  -10, 
				"OneD-Viewer - Open a local file",  NULL);
    g = NormalGroup(hOpenDlg, 2, 1, "File name:",  systemFont, NULL);
    SetGroupMargins(g, 10, 10);
    SetGroupSpacing(g, 10, 20);  
    t1 = DialogText(g,"",25, UDV_FOpenTextProc);
    b = PushButton(g, " browse...", UDV_FOpenBrowseProc);
   
    g = HiddenGroup(hOpenDlg, 3, 1, NULL);
    SetGroupMargins(g, 10, 10);
    SetGroupSpacing(g, 30, 30);
 
    g4 = NormalGroup(g, 2, 1, "File type", systemFont,  NULL);
    SetGroupMargins(g4, 10, 10);
    RadioButton(g4, "Ascii");
    RadioButton(g4, "Binary");
    SetValue(g4, 1);

    b1 = DefaultButton(g, "OK",  UDV_FOpenAcceptProc);
    b2 = PushButton(g, "Cancel",  UDV_FOpenCancelProc);
   
    Disable(b1);

	dfodp->parent=hWinMain;	
	dfodp->FNameEditCtrl=t1;
	dfodp->Ok=b1;
	dfodp->ReadMode=g4;

	SetObjectExtra (hOpenDlg, (Pointer) dfodp, StdCleanupExtraProc);
	
    Select(hOpenDlg);
    Show(hOpenDlg);

	/*allow only one FOpen dlg at a time*/
    UDV_set_PullMenus(&vmp->MainMenu,FALSE);
}

/*******************************************************************************

  Function : UDV_FileClose()
  
  Purpose : callback of the File|Close command 
  
  Parameters : i; command item
  
  Return value : none 

*******************************************************************************/
NLM_EXTERN void UDV_FileClose(IteM i)
{
ViewerMainPtr 		vmp;
WindoW				hWinMain;
RecT				rcP;

	hWinMain=(WindoW)ParentWindow(i);

	if (!hWinMain) return;
	
	vmp = (ViewerMainPtr) GetObjectExtra (hWinMain);

	if (vmp==NULL) return;
	
	if (vmp->vdp==NULL) return;
		
	if (vmp->hFeatDlg){/*Features List Dlg Box*/
		SetStatus(vmp->MainMenu.ShowFeatureList,FALSE);
		Remove(vmp->hFeatDlg);
		vmp->hFeatDlg=NULL;
	}

	UDV_FreeVDPstruct(vmp->vdp,FALSE);

	if (vmp->BspTable){
		ValNodeFree(vmp->BspTable);
		vmp->BspTable=NULL;
		vmp->BspChoice=0;
	}
	if (vmp->dataptr && vmp->datatype){
		ObjMgrFree(vmp->datatype,vmp->dataptr);
		vmp->datatype=0;
		vmp->dataptr=NULL;
		vmp->entityID=0;
	}

	/*Update main window title and menus*/
	SetValue(vmp->MainMenu.ScalePosChoice,3);
	SetStatus(vmp->MainMenu.ShowFeature,TRUE);
	UDV_set_MainMenus(&vmp->MainMenu,FALSE);
	UDV_set_MainControls(vmp,FALSE);
	SetTitle(hWinMain,szAppName);	
	SetTitle(vmp->vdp->InfoPanel,"Ready !");
	
	vmp->Show_logo=TRUE;	
	Select(vmp->vdp->UnDViewer);
	Select(vmp->vdp->UnDViewer);
	ObjectRect(vmp->vdp->UnDViewer,&rcP);
	InvalRect(&rcP);
	Update();
}

/*******************************************************************************

  Function : UDV_CSeq_okProc()
  
  Purpose : manage ok button of the Choose sequence dialog box 
  
  Parameters : g; button
  
  Return value : none 

*******************************************************************************/
static void UDV_CSeq_okProc(ButtoN g)
{
ViewerDialogDataPtr vdp;
UDVChooseSeqPtr 	ucsp;
ViewerMainPtr 		vmp;
Int2 				value;
WindoW				hOpenDlg,temport;
ValNodePtr			vnp;
Uint2				nCompt=1,eID;
Uint4               iID;
BioseqPtr			bsp=NULL;
RecT                rcP;
Char 				szBuf[255]={""};

	hOpenDlg=(WindoW)ParentWindow(g);
	if (!hOpenDlg) return;
	
	ucsp=(UDVChooseSeqPtr)GetObjectExtra (hOpenDlg);
	if (ucsp==NULL) goto error;
	
	vmp = (ViewerMainPtr) GetObjectExtra (ucsp->hWndMain);
	if (vmp==NULL) goto error;
	
	UDV_set_PullMenus(&vmp->MainMenu,TRUE);
	
	vdp = vmp->vdp;
	if (vdp == NULL) return;
	
	value=GetValue(ucsp->bsp_list);/*one-base value*/
	if (vmp->BspChoice==value) goto error;

	/*look for a new bsp*/
	for (vnp=vmp->BspTable ; vnp!=NULL ;vnp=vnp->next){
		if (nCompt==value){
			UDV_DecodeIdxFeat ((Uint4)vnp->data.intvalue,&eID,&iID);
			bsp=GetBioseqGivenIDs (eID, iID, OBJ_BIOSEQ);
			vmp->BspChoice=value;
			break;
		}
		nCompt++;
	}
	
	if (bsp){
		if (vmp->hFeatDlg){/*Features List Dlg Box*/
			SetStatus(vmp->MainMenu.ShowFeatureList,FALSE);
			Remove(vmp->hFeatDlg);
			vmp->hFeatDlg=NULL;
		}
		/*free data, remove viewer*/
		UDV_FreeVDPstruct(vmp->vdp,FALSE);

		SetValue(vmp->MainMenu.ScalePosChoice,3);
		SetStatus(vmp->MainMenu.ShowFeature,TRUE);
		UDV_set_MainMenus(&vmp->MainMenu,FALSE);
		UDV_set_MainControls(vmp,FALSE);
		
		if (vmp->UDVprocid!=0){
			GatherSpecificProcLaunch(vmp->UDVprocid, "OneD-Viewer", 
				OMPROC_VIEW, FALSE, eID, iID, OBJ_BIOSEQ);
		}
        else if (vmp->GVprocid==0){
            SetAppProperty("nonautonomous",(void *)vmp);
			GatherSpecificProcLaunch(vmp->UDVprocid, "OneD-Viewer", 
				OMPROC_VIEW, FALSE, eID, iID, OBJ_BIOSEQ);
            RemoveAppProperty("nonautonomous");
		}
		else{
			GatherProcLaunch(OMPROC_VIEW, FALSE, eID, iID, OBJ_BIOSEQ, 
				OBJ_BIOSEQ, 0, OBJ_BIOSEQ, 0);
		}
	
		temport=SavePort(ucsp->hWndMain);
		Select(vdp->UnDViewer);
		ObjectRect(vdp->UnDViewer,&rcP);
		sprintf(szBuf,"%s - [%s - %d letters]",szAppName,
					vdp->bsp_i.bspAccNum,
					vdp->bsp_i.bspLength);
		SetTitle(ucsp->hWndMain,szBuf);
		InvalRect(&rcP);
		Update();
		RestorePort(temport);
	}
error:

	Remove(hOpenDlg);
}


/*******************************************************************************

  Function : UDV_CSeq_cancelProc()
  
  Purpose : manage cancel button of the Choose sequence dialog box 
  
  Parameters : g; button
  
  Return value : none 

*******************************************************************************/
static void UDV_CSeq_cancelProc(ButtoN g)
{	
WindoW				hOpenDlg;
UDVChooseSeqPtr 	ucsp;
ViewerMainPtr 		vmp;

	hOpenDlg=(WindoW)ParentWindow(g);
	if (!hOpenDlg) return;
	
	ucsp=(UDVChooseSeqPtr)GetObjectExtra (hOpenDlg);
	if (ucsp==NULL) goto error;
	
	vmp = (ViewerMainPtr) GetObjectExtra (ucsp->hWndMain);
	if (vmp==NULL) goto error;
	
	UDV_set_PullMenus(&vmp->MainMenu,TRUE);

error:

	Remove(hOpenDlg);
}

/*******************************************************************************

  Function : UDV_CreateListBioseqDlg()
  
  Purpose : let the user choose between various bsp 
  
  Parameters : i; menu
  
  Return value : none 

*******************************************************************************/
NLM_EXTERN void UDV_CreateListBioseqDlg(IteM i)
{
GrouP 			g1,h,h1;
LisT 			lBox;
WindoW 			d,hWinMain;
ValNodePtr 		vnp;
BioseqPtr 		bsp;
Char 			szName[21]={""};
Char 			szBuf[50]={""};
ViewerMainPtr 	vmp;
UDVChooseSeqPtr ucsp;
Uint2			eID;
Uint4           iID;

	ucsp=(UDVChooseSeqPtr)MemNew(sizeof(UDVChooseSeq));
	if (ucsp==NULL) return;
	
	hWinMain=(WindoW)ParentWindow(i);

	if (!hWinMain) return;
	
	vmp = (ViewerMainPtr) GetObjectExtra (hWinMain);

	if (vmp==NULL) return;

	if (vmp->BspTable==NULL) return;
	
	d=/*DocumentWindow*/Nlm_MovableModalWindow(-50, -33 ,-10, -10, szAppName, NULL/*,NULL*/);
	if (d!=NULL){
		UDV_set_PullMenus(&vmp->MainMenu,FALSE);
		/*create some controls*/
		h=HiddenGroup(d, 3, 0,  NULL);
		h1=HiddenGroup(h, 0, 2,  NULL);
		StaticPrompt(h1,"Choose a sequence :",0,0,systemFont,'l');

		lBox=SingleList(h1,20,6,NULL);

		g1=HiddenGroup(h, 0, 2, NULL);
		PushButton(g1, "Ok",UDV_CSeq_okProc);
		PushButton(g1, "Cancel",UDV_CSeq_cancelProc);
		/*fill in the list box*/
		for (vnp=vmp->BspTable ; vnp!=NULL ;vnp=vnp->next){
			UDV_DecodeIdxFeat ((Uint4)vnp->data.intvalue,&eID,&iID);
			bsp=GetBioseqGivenIDs (eID, iID, OBJ_BIOSEQ);
			if (bsp){
				SeqIdWrite(bsp->id,szName,
						PRINTID_TEXTID_ACCESSION,20);
				if (szName){
					sprintf(szBuf,"%s (%s)",
						szName,
						(ISA_na(bsp->mol) ? "nucleic seq.":"protein"));
				}else{
					sprintf(szBuf,"Unknown name (%s)",
						(ISA_na(bsp->mol) ? "nucleic seq.":"protein"));
				}
				ListItem(lBox,szBuf);
			}
		}
		SetValue(lBox,vmp->BspChoice);

		ucsp->bsp_list=lBox;
		ucsp->hWndMain=hWinMain;
		SetObjectExtra (d, (Pointer) ucsp, StdCleanupExtraProc);
		RealizeWindow(d);
		Show(d);
	}
}


#if 0 

static CharPtr udvprotdbs [] = {
  "swissprot", "nr", "pdb", "month", "kabat", "yeast", NULL
};


static MonitorPtr blastmon = NULL; /* ugh.  used below */

/*****************************************************************************

Function: UDV_BlastCallback

Purpose: creates, updates and deletes blast status dialog

*****************************************************************************/
static Boolean LIBCALLBACK UDV_BlastCallback (BlastResponse *brp,
                                               Boolean *cancel)
{
    BlastProgressPtr bpp;
    Int4 completed = 0;
    Boolean retval;
    
    *cancel=FALSE;
    switch (brp->choice) {
    case BlastResponse_start:
        if (blastmon != NULL) {
            MonitorFree (blastmon);
            blastmon = NULL;
        }
        bpp = (BlastProgressPtr) brp->data.ptrvalue;
        if (bpp != NULL) {
            completed = bpp->completed;
        }
        if (completed == 0) {
            completed = 100;
        }
        blastmon = MonitorIntNew ("BLAST", 0, completed);
        return TRUE;
    case BlastResponse_progress:
        if (blastmon != NULL) {
            bpp = (BlastProgressPtr) brp->data.ptrvalue;
            if (bpp != NULL) {
                completed = bpp->completed;
            }
            retval = MonitorIntValue (blastmon, completed);
            if (retval == FALSE) {
                *cancel = TRUE;
                MonitorFree (blastmon);
                blastmon = NULL;
                return FALSE;
            }
        }
        return TRUE;
    case BlastResponse_queued:
        return TRUE;
    case BlastResponse_done:
        if (blastmon != NULL) {
            MonitorFree (blastmon);
            blastmon = NULL;
        }
        return TRUE;
    default:
        break;
    }
    return FALSE;
}

/*****************************************************************************

Function: UDV_BlastDlgOK

Purpose: OK button for UDV_BlastDlg

*****************************************************************************/
static void UDV_BlastDlgOK(ButtoN g)
{
    UDV_BlastDlgData *bddp;
    Int2 value;
    WindoW hOpenDlg;
    BLAST_OptionsBlkPtr options;
    Int4 i;
    ValNode *pvn;
    Bioseq* bsp;
    BlastNet3Hptr bl3hp;
    BlastResponsePtr bl3rp;
    Char str[32], *program;

    hOpenDlg=(WindoW)ParentWindow(g);
    if (!hOpenDlg) return;
    
    bddp=(UDV_BlastDlgData *)GetObjectExtra (hOpenDlg);
    if (bddp == NULL) {
        ValNodeFree(bddp->pvnSips);
        Remove(hOpenDlg);
        return;
    }
    

    BlastInit("udv 1.0", &bl3hp, &bl3rp);
    value = GetValue(bddp->bsp_list); /*one-base value*/

    for(pvn = bddp->pvnSips, i = 1; i != value && pvn != NULL;
        i++, pvn = pvn->next);

    if(pvn == NULL) {
        ValNodeFree(bddp->pvnSips);
        Remove(hOpenDlg);
        return;
    }

    bsp = BioseqLockById((SeqId *)pvn->data.ptrvalue);

    if(bsp == NULL) {
        ValNodeFree(bddp->pvnSips);
        Remove(hOpenDlg);
        return;
    }

    if(ISA_aa(bsp->mol)) program = "blastp";
    else program = "blastn";

    options = BLASTOptionNew (program, GetStatus(bddp->bGap));
    GetTitle(bddp->tMax, str, sizeof(str));
    options->hitlist_size = atoi(str);
    if (options->hitlist_size == 0) options->hitlist_size = 20;
/*    GetTitle(bddp->tExpect, str, sizeof(str));
    options->expect_value = atof(str);
    if (options->expect_value == 0.0) options->expect_value = 0.001;*/
    
    Remove(hOpenDlg);

    value = GetValue(bddp->db_list); /*one-base value*/

    bddp->salp = BlastBioseqNet(bl3hp, bsp, program, udvprotdbs[value-1],
        options, NULL, NULL, UDV_BlastCallback);
    BLASTOptionDelete(options);
    BioseqUnlock(bsp);
    ValNodeFree(bddp->pvnSips);
    if(bddp->salp == NULL) return;

    if(bddp->callback) bddp->callback(bddp);   
}

/*****************************************************************************

Function: UDV_BlastDlgCancel

Purpose: cancel button for UDV_BlastDlg
  
*****************************************************************************/
static void UDV_BlastDlgCancel(ButtoN g)
{	
    WindoW hOpenDlg;
    UDV_BlastDlgData *bddp;
    
    hOpenDlg=(WindoW)ParentWindow(g);
    if (!hOpenDlg) return;
    
    bddp = (UDV_BlastDlgData *)GetObjectExtra (hOpenDlg);
    if (bddp != NULL) ValNodeFree(bddp->pvnSips);
    
    Remove(hOpenDlg);
}

/*****************************************************************************

Function: UDV_BlastDlg

Purpose: Creates blast many dialog
  
*****************************************************************************/
NLM_EXTERN void UDV_BlastDlg(UDV_BlastDlgData *bddp)
{
    GrouP h2,h,h1, h3, h4, h5;
    WindoW d;
    Char szName[21]={""};
    ValNode *pvn;
    Int4 i;

    if(bddp == NULL) return;

    d = MovableModalWindow(-50, -33 ,-10, -10, "Blast", NULL);
    if (d != NULL){
        /*create some controls*/
        h = HiddenGroup(d, 1, 5,  NULL);
        h1 = HiddenGroup(h, 1, 2,  NULL);
        StaticPrompt(h1,"Choose a sequence :",0,0,systemFont,'l');
        
        bddp->bsp_list = SingleList(h1,20,6,NULL);

        h3 = HiddenGroup(h, 1, 1, NULL);
        bddp->bGap = CheckBox(h3, "Gapped", NULL);
        SetStatus(bddp->bGap, TRUE);

        h4 = HiddenGroup(h, 2, 1, NULL);
/*        StaticPrompt(h4,"Expectation value:",0,0,systemFont,'l');
        bddp->tExpect = DialogText(h4, "0.01", 8, (TxtActnProc) NULL); */
        StaticPrompt(h4,"Maximum # of hits:",0,0,systemFont,'l');
        bddp->tMax = DialogText(h4, "20", 5, (TxtActnProc) NULL);

        h4 = HiddenGroup (h, 2, 1, NULL);
        StaticPrompt (h4, "Choose Database:", 0, 0, programFont, 'c');
        
#ifdef WIN_MAC
        bddp->db_list = PopupList(h4, TRUE, NULL);
#else 
        bddp->db_list = PopupList(h4, FALSE, NULL);
#endif
        for (i = 0; udvprotdbs [i] != NULL; i++)
            PopupItem(bddp->db_list, udvprotdbs [i]);
        SetValue(bddp->db_list,1);

        h2 = HiddenGroup(h, 2, 1, NULL);
        PushButton(h2, "Ok", UDV_BlastDlgOK);
        PushButton(h2, "Cancel", UDV_BlastDlgCancel);

        h5 = HiddenGroup(h, 1, 1, NULL);
        StaticPrompt(h5,"Warning: may take several minutes!",0,0,systemFont,'l');

        /*fill in the list box*/
        for(pvn = bddp->pvnSips; pvn != NULL; pvn = pvn->next) {
            SeqIdWrite((SeqId *)pvn->data.ptrvalue,szName,
                PRINTID_TEXTID_ACCESSION,20);
            ListItem(bddp->bsp_list, szName);
        }
        SetValue(bddp->bsp_list,1);
        
        SetObjectExtra (d, (Pointer) bddp, StdCleanupExtraProc);
        RealizeWindow(d);
        Show(d);
    }
}

#endif /* 0 */