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
|
/* $Id: elecpcr.c,v 6.9 2002/07/25 14:15:09 beloslyu Exp $
* ===========================================================================
*
* PUBLIC DOMAIN NOTICE
* National Center for Biotechnology Information
*
* 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 have not placed any restriction on its use or reproduction.
*
* 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.
*
* Please cite the author in any work or product based on this material.
*
* ===========================================================================
*
* File Name: $RCSfile: elecpcr.c,v $
*
* Author: Sergei Shavirin
*
* Version Creation Date: 12/19/1996
*
* $Revision: 6.9 $
*
* File Description:
* Main program for WWW and Command-Line Electronic PCR
*
* $Log: elecpcr.c,v $
* Revision 6.9 2002/07/25 14:15:09 beloslyu
* change www3 to www
*
* Revision 6.8 1999/07/27 18:43:04 shavirin
* Fixed problems found on PC NT computer.
*
* Revision 6.7 1999/02/24 16:49:23 kans
* use accutils copy of IS_ntdb_accession and IS_protdb_accession
*
* Revision 6.6 1999/02/23 17:28:11 shavirin
* Replaced IS_ accession verification functions by it's "relaxed"
* version
*
* Revision 6.5 1998/05/22 19:19:28 shavirin
* Updated for porting to sunweb. Fixed bug with filtering of
* organisms.
*
* Revision 6.4 1998/05/01 19:22:29 shavirin
* Improved WWW page formating
*
* Revision 6.3 1998/05/01 18:22:58 shavirin
* Next revision
*
* Revision 6.2 1998/04/28 19:32:13 shavirin
* Fixed minor bugs detected by purify
*
* Revision 6.1 1997/09/03 17:19:45 shavirin
* Added some debug information and sequence prevented from freeing
*
* Revision 6.0 1997/08/25 18:19:31 madden
* Revision changed to 6.0
*
* Revision 1.3 1997/05/23 15:32:18 shavirin
* Added ability to use local database files (for remote users)
*
* Revision 1.2 1997/05/14 19:12:41 shavirin
* Added define LF 10
*
* Revision 1.1 1996/12/19 20:54:35 shavirin
* Initial revision
*
*
* ==========================================================================
*/
#include <ncbi.h>
#include <ncbiwww.h>
#include <accentr.h>
#include <accutils.h>
#include <stsutil.h>
/****************************************************************************/
/* DEFINES */
/****************************************************************************/
#define BG_COLOR "#FDF5E6"
#define PRIMER1_COLOR "#00BF00"
#define PRIMER2_COLOR "red"
#define LogFile "wwwsts.log"
#define FASTA_IN 1
#define ACC_IN 2
#define MINSEQLEN 10
#define LF 10
/****************************************************************************/
/* TYPEDEFS */
/****************************************************************************/
typedef struct AccList {
CharPtr acc;
struct AccList *next;
} AccList, PNTR AccListPtr;
typedef struct StsPar {
CharPtr sequence;
Boolean html;
Int4 organism;
CharPtr orgname;
Int4 intype;
Boolean detailed;
CharPtr sts_db_name;
CharPtr org_db_name;
CharPtr map_db_name;
} StsPar, PNTR StsParPtr;
/****************************************************************************/
/* STATIC FINCTIONS */
/****************************************************************************/
static Boolean GetSTSEntry(StsResultPtr result,
FILE *fd, Boolean detailed);
static StsResultPtr PrintSTSHeader(StsResultPtr result, CharPtr label,
Boolean detailed, Boolean html);
static Boolean PrintSTSDetailes(StsResultPtr result, Boolean html);
static AccListPtr GetAccList(CharPtr buffer, Int4Ptr TotalItems);
static void WWWSendSTSPage(CharPtr WWWSequence,
Boolean NetscapeOK);
static StsParPtr GetStsSearchParam(void);
static FastaSeqPtr NextFastaFromBuff(CharPtr p, CharPtr PNTR next);
static Int4 FilterNucSequence(CharPtr p);
static StsParPtr StsParNew(void);
static void StsParFree(StsParPtr param);
static StsParPtr STSReadCommandLine(void);
#define STS_WWW_DATABASE "/web/public/htdocs/STS/DB/sts.db"
#define ORG_WWW_DATABASE "/web/public/htdocs/STS/DB/org.db"
#define MAP_WWW_DATABASE "/web/public/htdocs/STS/DB/sts.map"
static Boolean IS_NOT_accession (CharPtr word)
{
Int4 len, i;
if(word == NULL)
return TRUE;
if((len = StringLen(word)) == 0)
return TRUE;
/* Testing, that this is 6 length accession */
if(len == 6 && isalpha(word[0])) {
for(i = 1; i < len; i++) {
if(!isdigit(word[i]))
break;
}
if (i == len) return FALSE; /* This is accession */
}
if(len == 8 && isalpha(word[0]) && isalpha(word[1])) {
for(i = 2; i < len; i++) {
if(!isdigit(word[i])) {
break;
}
}
if (i == len) return FALSE; /* This is accession */
}
return TRUE;
}
Int2 Main(void)
{
StsParPtr stsp;
Int4 NumBadChar, StsCount;
CharPtr inbuff;
FastaSeqPtr fseq;
CharPtr NextChar;
StsResultPtr result= NULL, newresult= NULL, tmpresult=NULL;
Int4 NumAcc;
AccListPtr MainAccList, AccTmp;
STSDataPtr sts_data;
STSDbNamesPtr db_name = NULL;
putenv("USER=STSSearch");
if((stsp = GetStsSearchParam()) == NULL) {
printf("Error getting Search data. Exiting ...\n");
exit(1);
}
if(stsp->html) {
printf("Content-type: text/html\r\n\r\n");
printf("<HTML>"
"<BODY bgcolor=\"%s\" link=\"blue\" vlink=#4500A0>"
"<TITLE> STS Match Program </TITLE>"
"<map name=TitleMap>"
"<area shape=rect coords=3,1,43,21 "
"href=http://www.ncbi.nlm.nih.gov>"
"<area shape=rect coords=381,1,426,21 "
"href=http://www.ncbi.nlm.nih.gov/dbSTS/> "
"<area shape=rect coords=431,1,476,21 "
"href=http://www.ncbi.nlm.nih.gov/Entrez> "
"<area shape=rect coords=481,1,500,21 "
"href=/STS/About_ePCR.html>"
"</map>"
"<IMG SRC=\"/STS/pcr_res.gif\" BORDER=0 USEMAP=#TitleMap "
"HEIGHT=22 WIDTH=500><BR> <BR>\n", BG_COLOR);
fflush(stdout);
}
#ifdef WWW_VERSION
db_name = MemNew(sizeof(STSDbNames));
db_name->sts_db_name = StringSave(STS_WWW_DATABASE);
db_name->sts_map_name = StringSave(MAP_WWW_DATABASE);
db_name->sts_org_name = StringSave(ORG_WWW_DATABASE);
#else
if(stsp->sts_db_name != NULL ||
stsp->map_db_name != NULL || stsp->org_db_name) {
db_name = MemNew(sizeof(STSDbNames));
db_name->sts_db_name = StringSave(stsp->sts_db_name);
db_name->sts_map_name = StringSave(stsp->map_db_name);
db_name->sts_org_name = StringSave(stsp->org_db_name);
}
#endif
if((StsCount = InitSTSSearch_r(db_name, &sts_data)) < 0) {
printf("Cannot initiate STS Search ... Exiting ...\n");
exit(1);
} else if(stsp->html) {
printf("<b>STS database initialized with %d sequences, "
"please wait for results ...</b><BR><HR><PRE>", StsCount
);
fflush(stdout);
}
stsp->organism = STSGetOrganismIndex(sts_data, stsp->orgname);
if(db_name != NULL) {
MemFree(db_name->sts_db_name);
MemFree(db_name->sts_map_name);
MemFree(db_name);
}
if(stsp->intype != FASTA_IN) {
if (! EntrezInit("STSSearch", FALSE, NULL)) {
printf("Cannot initialize Entrez<BR>");
}
EntrezBioseqFetchEnable("STSSearch", TRUE);
}
printf(
"Location of STS GenBank\n"
"within query accession\n"
"sequence dbSTS id number Chromosome STS marker name\n"
"================ ======== ========= ========== ==============================\n\n");
fflush(stdout);
if(stsp->intype == FASTA_IN) {
if(stsp->sequence[0] == NULLB) {
printf("No sequence present in the search query.\n");
exit(1);
} else if(StringLen(inbuff = stsp->sequence) < MINSEQLEN) {
printf("Length of entered sequence too small to start search\n");
exit(1);
}
while(inbuff != NULL) {
fseq = NextFastaFromBuff(inbuff, &NextChar);
inbuff = NextChar;
if((NumBadChar = FilterNucSequence(fseq->seq)) < 0) {
printf("Error filtering nucleotide sequence\n");
exit(1);
} else if (NumBadChar >0 ) {
printf("<b>WARNING!!!</b> %d bad characters found "
"in the input sequence\n\n",
NumBadChar);
}
if(!STSSearch_r(sts_data, fseq->seq, stsp->organism, &newresult)) {
printf("Error in STS Search. Exiting ...\n");
return 1;
}
if(newresult != NULL) {
tmpresult = newresult;
newresult = PrintSTSHeader(newresult, fseq->label,
stsp->detailed, stsp->html);
newresult->next = result;
result = tmpresult;
} else {
printf("%s\n Did not return any hits ...\n\n",
fseq->label);
fflush(stdout);
}
MemFree(fseq->label);
MemFree(fseq->seq);
MemFree(fseq);
} /* while (inbuff != NULL) */
} else { /* Type = Accession or GI */
/* Here first we will fetch sequence from Entrez */
MainAccList = GetAccList(stsp->sequence, &NumAcc);
if(NumAcc == 0) {
printf("<b>ERROR:</b> No valid gi/accessions found in input.<HR>");
exit(1);
}
/* printf("Retrieved %d valid accessions/gis\n", NumAcc); */
for (AccTmp = MainAccList; AccTmp != NULL; AccTmp = AccTmp->next) {
if((fseq = AccessionToFasta(AccTmp->acc)) == NULL) {
printf("<b>ERROR:</b> No record was found "
"for %s - skipping..</b>",
AccTmp->acc);
continue;
}
if(!STSSearch_r(sts_data, fseq->seq, stsp->organism, &newresult)) {
printf("Error in STS Search. Exiting ...\n");
return 1;
}
if(newresult != NULL) {
tmpresult = newresult;
newresult = PrintSTSHeader(newresult, fseq->label,
stsp->detailed, stsp->html);
newresult->next = result;
result = tmpresult;
} else {
printf("%s\n Did not return any hits ...\n\n",
fseq->label);
fflush(stdout);
}
MemFree(fseq->seq);
MemFree(fseq->label);
MemFree(fseq);
}
}
if(stsp->html)
printf("<HR>\n");
/* If detailed output requested */
if(result && stsp->detailed)
PrintSTSDetailes(result, stsp->html);
if(stsp->detailed || stsp->intype != FASTA_IN) {
EntrezBioseqFetchDisable();
EntrezFini();
}
StsResultFree(result);
STSDataFree(sts_data);
StsParFree(stsp);
return 0;
}
static StsResultPtr PrintSTSHeader(StsResultPtr result, CharPtr label,
Boolean detailed, Boolean html)
{
Char TmpBuff[1024];
Int4 tmplen;
register Int4 i;
printf("%s\n", label);
while (TRUE) {
/* Now printing short header information line */
if(detailed && html) {
sprintf(TmpBuff, " <a href=#%08s>%d..%d</a> ",
result->acc,
result->pos, result->pos+result->real_len-1
);
} else {
sprintf(TmpBuff, " %d..%d ",
result->pos, result->pos+result->real_len-1
);
}
printf("%s", TmpBuff);
if(detailed && html)
tmplen = 41 - StringLen(TmpBuff);
else
tmplen = 19 - StringLen(TmpBuff);
for(i =0; i < tmplen; i++)
printf(" ");
if(html) {
sprintf(TmpBuff, "<a href=\"http://www2.ncbi.nlm.nih.gov/cgi-bin/"
"birx_by_acc?dbsts+%d\">%d</a>",
result->id_sts, result->id_sts);
} else {
sprintf(TmpBuff, "%d", result->id_sts);
}
printf("%s", TmpBuff);
if(html)
tmplen = 86 - StringLen(TmpBuff);
else
tmplen = 10 - StringLen(TmpBuff);
for(i =0; i < tmplen; i++)
printf(" ");
if(html) {
sprintf(TmpBuff, "<a href=\"http://www.ncbi.nlm.nih.gov/"
"htbin-post/Entrez/query?form=6&dopt=g&db=n&"
"uid=%s\">%s</a>",
result->acc, result->acc);
} else {
sprintf(TmpBuff, "%s", result->acc);
}
printf("%s", TmpBuff);
if(html)
tmplen = 112 - StringLen(TmpBuff);
else
tmplen = 14 - StringLen(TmpBuff);
for(i =0; i < tmplen; i++)
printf(" ");
sprintf(TmpBuff, "%s",
StringCmp(result->chrom, "0") ? result->chrom : " ");
printf("%s", TmpBuff);
tmplen = 9 - StringLen(TmpBuff);
for(i =0; i < tmplen; i++)
printf(" ");
printf("%s\n", result->sts_name);
fflush(stdout);
if(result->next == NULL)
break;
result = result->next;
}
printf("\n");
fflush(stdout);
return result;
}
static Boolean PrintSTSDetailes(StsResultPtr result, Boolean html)
{
register Int4 i;
Int4 len1, len2, len_tot, len_end;
Boolean ColorSet;
printf("\n%sDetailed information...%s",
html? "<b>" : "",
html? "</b>\n\n" : ""
);
fflush(stdout);
while(result) {
if(html) {
printf("<HR><a name=%08s>\n<h3>%s</h3>\n\n</a>",
result->acc, result->sts_name);
printf("dbSTS id: <a href=\"http://www2.ncbi.nlm.nih.gov/cgi-bin/"
"birx_by_acc?dbsts+%d\">%d</a>, "
"GenBank Accession: "
"<a href=\"http://www.ncbi.nlm.nih.gov/"
"htbin-post/Entrez/query?form=6&dopt=g&db=n&"
"uid=%s\">%s</a><BR>Organism: %s\n"
"Primer1: <FONT color=\"%s\">%s</FONT>\n"
"Primer2: <FONT color=\"%s\">%s</FONT>\n"
"STS location: %d..%d Chromosome: %s\n"
"Expected amplicon size: %d, Observed amplicon size: %d\n",
result->id_sts, result->id_sts,
result->acc, result->acc,
result->org,
PRIMER1_COLOR, result->pr1,
PRIMER2_COLOR, result->pr2,
result->pos, result->pos+result->real_len,
StringCmp(result->chrom, "0") ? result->chrom : " ",
labs(result->exp_len), result->real_len
);
} else {
printf("\n\n\n-------+= %s =+-------\n\n",
result->acc, result->sts_name);
printf("dbSTS id: %d, GenBank Accession: %s\n"
"Organism: %s\n"
"Primer1: %s\n"
"Primer2: %s\n"
"STS location: %d..%d Chromosome: %s\n"
"Expected amplicon size: %d, Observed amplicon size: %d\n",
result->id_sts,
result->acc,
result->org,
result->pr1,
result->pr2,
result->pos, result->pos+result->real_len-1,
StringCmp(result->chrom, "0") ? result->chrom : " ",
labs(result->exp_len), result->real_len
);
}
fflush(stdout);
printf("Primers match in %s orientation\n",
result->exp_len > 0 ? "forward" : "backward");
printf("\n%sQuery sequence:%s\n\n",
html? "<b>" : "",
html? "</b>" : ""
);
fflush(stdout);
len1 = StringLen(result->pr1) + result->start;
len2 = result->real_len - StringLen(result->pr2) + result->start;
len_tot = StringLen(result->sequence);
len_end = result->real_len + result->start;
printf("%6d ", result->pos - result->start);
fflush(stdout);
ColorSet = FALSE;
for(i = 0; i < len_tot; i++) {
if(!(i%10) && i)
printf(" ");
if(i==result->start && html) {
printf("<FONT color=\"%s\">",
result->exp_len > 0 ? PRIMER1_COLOR : PRIMER2_COLOR);
ColorSet = (result->exp_len > 0 ? 1 : 2);
}
if(i == len_end && html) {
printf("</FONT>");
ColorSet = FALSE;
}
if(i == len1 && html) {
printf("</FONT>");
ColorSet = FALSE;
}
if(i == len2 && html) {
printf("<FONT color=\"%s\">",
result->exp_len > 0 ? PRIMER2_COLOR : PRIMER1_COLOR);
ColorSet = (result->exp_len > 0 ? 2 : 1);
}
if(!(i%60) && i) {
if(ColorSet > 0 && html)
printf("</FONT>\n%6d <FONT color=\"%s\">",
result->pos - result->start + i,
ColorSet == 1 ? PRIMER1_COLOR : PRIMER2_COLOR );
else
printf("\n%6d ", result->pos - result->start + i );
}
printf("%c", result->sequence[i]);
}
fflush(stdout);
result=result->next;
fflush(stdout);
}
if(html) {
printf("</PRE>");
for(i=0; i<25; i++)
printf("<BR>");
} else {
printf("\n\n\n");
}
fflush(stdout);
return TRUE;
}
static AccListPtr GetAccList(CharPtr buffer, Int4Ptr TotalItems)
{
Char TmpBuff[256];
register Int4 i, j, k;
Int4 FileLen = 0;
AccListPtr acclist = NULL;
AccListPtr acclistTmp, acclistlast;
Int4 NumInvalid = 0;
*TotalItems = 0;
if(buffer == NULL || buffer[0] == NULLB)
return NULL;
MemSet(TmpBuff, '\0', sizeof(TmpBuff));
FileLen = StringLen(buffer);
for(i = 0; i < FileLen; i++) {
if(NumInvalid > 10) {
printf("<b>ERROR :</b> Too many invalid Gi/Accession numbers <BR>");
return NULL;
}
if(isspace(buffer[i])) /* Rolling spaces */
continue;
j= 0;
while (!isspace(buffer[i]) && j < 10 && i < FileLen) {
TmpBuff[j] = buffer[i];
j++; i++;
}
TmpBuff[j] = NULLB;
/* Now validating accession/gi */
for(k =0; k < j; k++) {
if(!isdigit(TmpBuff[k])) {
break;
}
}
if(k != j) {
if(IS_NOT_accession(TmpBuff)){
printf("<b>WARNING:</b> Gi/Accession \"%s\" "
"is not valid<BR>",
TmpBuff);
NumInvalid++;
continue;
}
}
/* It we come here - we got valid text ID */
if(acclist == NULL) { /* first element */
acclist = (AccListPtr) MemNew(sizeof(AccList));
acclistTmp = acclist;
acclistTmp->acc = StringSave(TmpBuff);
acclistTmp->next = NULL;
acclistlast=acclistTmp;
*TotalItems = *TotalItems +1;
} else {
acclistTmp = (AccListPtr) MemNew(sizeof(AccList));
acclistlast->next = acclistTmp;
acclistTmp->acc = StringSave(TmpBuff);
acclistTmp->next = NULL;
acclistlast = acclistTmp;
*TotalItems = *TotalItems +1;
}
}
return acclist;
}
static void WWWSendSTSPage(CharPtr WWWSequence,
Boolean NetscapeOK)
{
Int4 i;
STSOrgPtr PNTR OrgTable;
printf("Content-type: text/html\r\n\r\n");
printf("<HTML>"
"<BODY bgcolor=\"%s\">"
"<TITLE> STS Match Program </TITLE>\n"
"<map name=TitleMap>\n"
"<area shape=rect coords=3,1,43,21 "
"href=http://www.ncbi.nlm.nih.gov>\n"
"<area shape=rect coords=381,1,426,21 "
"href=http://www.ncbi.nlm.nih.gov:%s/dbSTS/> "
"<area shape=rect coords=431,1,476,21 "
"href=http://www.ncbi.nlm.nih.gov/Entrez> "
"<area shape=rect coords=481,1,500,21 "
"href=/STS/About_ePCR.html>"
"</map>\n"
"<IMG SRC=\"/STS/pcr.gif\" BORDER=0 USEMAP=#TitleMap "
"HEIGHT=22 WIDTH=500>\n", BG_COLOR, getenv("SERVER_PORT"));
if((OrgTable = STSGetOrgTable()) == NULL) {
printf("ERROR: Cannot initiate Organism index "
"Exiting...\n");
exit(1);
}
printf("<FORM ACTION=\"%s/result \" METHOD=\"POST\" "
"NAME=\"STSTOOL\" %s>\n",
getenv("SCRIPT_NAME") != NULL ? getenv("SCRIPT_NAME") : "NOT_SET",
NetscapeOK? "ENCTYPE=\"multipart/form-data\"" : "");
printf("PCR-based sequence tagged sites (STSs) "
"have been used as landmarks for "
"construction of various types of genomic maps. "
"Using \"electronic PCR\" (e-PCR), "
"these sites can be detected in DNA sequences, "
"potentially allowing their map "
"locations to be determined. <BR><BR>\n");
printf("Enter here your input data as \n"
"<select name = \"INPUT_TYPE\"> \n"
"<option> Sequence in FASTA format \n"
"<option> Accession or GI \n"
"</select><BR><BR> \n"
"<textarea name=\"SEQUENCE\" rows=6 cols=60>%s</textarea> \n",
WWWSequence == NULL ? "" : WWWSequence);
if(NetscapeOK)
printf("<BR>Or load your input data from file: "
"<INPUT TYPE=\"file\" NAME=\"SEQFILE\"> \n");
printf("<BR><BR>\n");
printf("Retrieve STS from "
"<select name = \"ORGANISM\"> \n");
printf(" <option> All Organisms ");
for (i=0; i < MAXORGNUM && OrgTable[i] != NULL; i++) {
printf(" <option> %s (%d) \n",
OrgTable[i]->string, OrgTable[i]->num);
}
printf("</select><BR><BR>\n");
printf("Print detailed information "
"<INPUT TYPE=\"checkbox\" NAME=\"DETAILED\" CHECKED><BR><BR>\n");
printf("<INPUT TYPE=\"submit\"> \n"
"<INPUT TYPE=\"reset\" VALUE=\"Clear input\"> \n"
"<HR></FORM>\n"
);
printf("%c<ADDRESS>\n", LF);
printf("Comments and suggestions to:"
"< \n<a href=\"mailto:info@ncbi.nlm.nih.gov\">"
"info@ncbi.nlm.nih.gov\n"
"</a> > <BR> Credits to: \n"
"<a href=\"mailto:shavirin@ncbi.nlm.nih.gov\">"
"Sergei B. Shavirin</a>, \n"
"<!-- <a href=\"http://www.ncbi.nlm.nih.gov/STS/shavirin.html\">"
"Sergei B. Shavirin</a> -->\n"
"<a href=\"mailto:schuler@ncbi.nlm.nih.gov\">"
"Greg Schuler</a> and \n"
"<a href=\"mailto:carolyn@ncbi.nlm.nih.gov\">"
"Carolyn Tolstoshev</a>\n");
printf("</ADDRESS>\n");
}
#define NUMARGS 9
Args pcr_args[NUMARGS] = {
{"Input type\n"
" 0 - FASTA file \n"
" 1 - List of Gi/Accession numbers",
NULL, NULL,NULL,FALSE,'t',ARG_INT,0.0,0,NULL},
{"Format of output \n"
" 0 - Text \n"
" 1 - HTML ",
"0", NULL,NULL,FALSE,'f',ARG_INT, 0.0,0,NULL},
{ "File with FASTA entries or GI/Accession numbers",
"stdin", NULL, NULL, TRUE, 'i', ARG_FILE_IN, 0.0, 0, NULL},
{"Print detailed information \n"
" 0 - Short \n"
" 1 - Detailed ",
"0", NULL,NULL,TRUE,'d',ARG_INT, 0.0,0,NULL},
{ "GI/Accession number for quick look",
NULL, NULL, NULL, TRUE, 'u', ARG_STRING, 0.0, 0, NULL},
{"STS database file name:",
NULL, NULL,NULL,TRUE,'s',ARG_FILE_IN, 0.0,0,NULL},
{"ORG database file name:",
NULL, NULL,NULL,TRUE,'o',ARG_FILE_IN, 0.0,0,NULL},
{"MAP database file name:",
NULL, NULL,NULL,TRUE,'m',ARG_FILE_IN, 0.0,0,NULL},
{"Logfile name:",
"elecpcr.log", NULL,NULL,TRUE,'l',ARG_FILE_OUT, 0.0,0,NULL}
};
static StsParPtr STSReadCommandLine(void)
{
StsParPtr stsp;
FILE *fd;
if((stsp = StsParNew()) == NULL)
return NULL;
if ( !GetArgs ("elecpcr", NUMARGS, pcr_args) ) {
exit(1);
}
if (!ErrSetLog (pcr_args[8].strvalue)) {
ErrShow();
} else {
ErrSetOpts (ERR_CONTINUE, ERR_LOG_ON);
}
stsp->sts_db_name = StringSave(pcr_args[5].strvalue);
stsp->org_db_name = StringSave(pcr_args[6].strvalue);
stsp->map_db_name = StringSave(pcr_args[7].strvalue);
if(pcr_args[1].intvalue == 1)
stsp->html = TRUE;
else
stsp->html = FALSE;
if(pcr_args[3].intvalue == 1)
stsp->detailed = TRUE;
else
stsp->detailed = FALSE;
if(pcr_args[0].intvalue == 1)
stsp->intype = ACC_IN;
else
stsp->intype = FASTA_IN;
if(pcr_args[4].strvalue != NULL) { /* Quick look ? */
stsp->sequence = pcr_args[4].strvalue;
} else { /* Reading from file by default */
if((fd = FileOpen(pcr_args[2].strvalue, "rb")) == NULL)
return NULL;
if((stsp->sequence = WWWReadFileInMemory(fd, 0, TRUE)) == NULL)
return NULL;
}
return stsp;
}
static StsParPtr GetStsSearchParam(void)
{
WWWInfoPtr info;
CharPtr chptr;
StsParPtr stsp;
FILE *fd;
time_t time_now;
CharPtr TimeNowStr;
WWWErrorCode error;
Boolean SequenceOK = FALSE;
if((fd = FileOpen(LogFile, "a")) == NULL) {
if((fd = FileOpen("/tmp/wwwsts.log", "a")) == NULL) {
printf("Cannot open logfile. Exiting...\n ");
exit(1);
}
}
if((error = WWWReadPosting(&info)) != WWWErrOk)
return NULL;
/* First check type of call to the program */
if(WWWGetMethod(info) == COMMAND_LINE) {
/* Reading command line and create StsPar structure */
WWWInfoFree(info);
return(STSReadCommandLine());
}
if(WWWGetMethod(info) == WWW_GET) {
if(WWWGetNumEntries(info) == 0) {
time_now = time(NULL);
TimeNowStr = ctime(&time_now);
TimeNowStr[24] = '\0';
fprintf(fd, "\n%s|%s|%s|%s|%d",
TimeNowStr, WWWGetAddress(info),
WWWGetHost(info), WWWGetAgent(info),
0);
fclose(fd);
WWWSendSTSPage(NULL, (Boolean)(WWWGetBrowser(info) == NETSCAPE));
exit(1);
} else { /* Here is processing of link to Electronic PCR */
if((stsp = StsParNew()) == NULL)
return NULL;
/* Sequence Accession or GI */
stsp->intype = ACC_IN;
if((chptr = WWWGetValueByName(info, "ID")) != NULL) {
stsp->sequence = StringSave(chptr);
} else {
time_now = time(NULL);
TimeNowStr = ctime(&time_now);
TimeNowStr[24] = '\0';
fprintf(fd, "\n%s|%s|%s|%s|%d",
TimeNowStr, WWWGetAddress(info),
WWWGetHost(info), WWWGetAgent(info),
0);
fclose(fd);
WWWSendSTSPage(NULL, (Boolean)(WWWGetBrowser(info) == NETSCAPE));
exit(1);
}
/* Detailed or short */
if((chptr = WWWGetValueByName(info, "D")) != NULL) {
if(!StringICmp(chptr, "0") ||
!StringICmp(chptr, "FALSE") ||
!StringICmp(chptr, "OFF") ||
!StringICmp(chptr, "NO") )
stsp->detailed = FALSE;
} else {
stsp->detailed = TRUE;
}
/* Text or HTML */
if((chptr = WWWGetValueByName(info, "F")) != NULL) {
if(!StringICmp(chptr, "0") ||
!StringICmp(chptr, "FALSE") ||
!StringICmp(chptr, "OFF") ||
!StringICmp(chptr, "TEXT") ||
!StringICmp(chptr, "NO") ) {
stsp->html = FALSE;
printf("Content-type: text/html\r\n\r\n");
printf("<BODY bgcolor=\"%s\"><PRE>", BG_COLOR);
printf("<TITLE> STS Match Program </TITLE>");
}
} else {
stsp->html = TRUE;
}
return stsp;
} /* Link to Electronic PCR proccesing */
} /* Method == GET */
if((stsp = StsParNew()) == NULL)
return NULL;
#ifdef TEST
printf("Content-type: text/html\r\n\r\n");
info_data = (WWWInfoDataPtr) info;
for(i=0; i < info_data->num_entries; i++) {
printf("%s : %s\n <BR>%c",
info_data->entries[i]->name,
info_data->entries[i]->val, LF);
}
exit(1);
#endif
if((chptr = WWWGetValueByName(info, "ORGANISM")) != NULL)
stsp->orgname = StringSave(chptr);
if((chptr = WWWGetValueByName(info, "SEQUENCE")) != NULL) {
if(chptr[0] != NULLB)
SequenceOK = TRUE;
stsp->sequence = StringSave(chptr);
}
if(((chptr = WWWGetValueByName(info, "SEQFILE")) != NULL) &&
!SequenceOK) {
stsp->sequence = StringSave(chptr);
}
if((chptr = WWWGetValueByName(info, "INPUT_TYPE")) != NULL) {
if(StringStr(chptr, "Sequence")) {
stsp->intype = FASTA_IN;
} else if(StringStr(chptr, "Accession")) {
stsp->intype = ACC_IN;
}
}
if((chptr = WWWGetValueByName(info, "DETAILED")) != NULL) {
stsp->detailed = TRUE;
}
time_now = time(NULL);
TimeNowStr = ctime(&time_now);
TimeNowStr[24] = '\0';
fprintf(fd, "\n%s|%s|%s|%s|%d|%d|%d",
TimeNowStr, WWWGetAddress(info),
WWWGetHost(info), WWWGetAgent(info),
stsp->intype,
stsp->organism,
stsp->detailed);
fclose(fd);
WWWInfoFree(info);
return stsp;
}
static StsParPtr StsParNew(void)
{
StsParPtr param;
param = (StsParPtr) MemNew(sizeof(StsPar));
param->sequence = NULL;
param->detailed = FALSE;
param->intype = FASTA_IN;
param->html = TRUE;
return param;
}
static void StsParFree(StsParPtr param) {
MemFree(param->sequence);
MemFree(param->sts_db_name);
MemFree(param->org_db_name);
MemFree(param->map_db_name);
MemFree(param->orgname);
MemFree(param);
}
static FastaSeqPtr NextFastaFromBuff(CharPtr p, CharPtr PNTR next)
{
FastaSeqPtr fseq;
CharPtr t;
CharPtr str;
Int4 i, SeqSize = INIT_BUFF_SIZE;
*next = NULL;
if(p == NULL | p[0] == NULLB)
return NULL;
t = p;
while (isspace(*t)) /* Rolling spaces */
*t++;
fseq = (FastaSeqPtr) MemNew(sizeof(FastaSeq));
fseq->label = NULL;
fseq->seq = NULL;
switch (*t) {
case NULLB:
return NULL;
case '>':
/* Reading label */
str = (CharPtr) MemNew(SeqSize + 5);
str[0] = NULLB;
for(i=0; *t != NULLB; i++) {
if((str[i] = *t) == '\n' || *t == '\r')
break;
if (i > SeqSize) {
SeqSize = i + INIT_BUFF_SIZE;
str = (CharPtr) Realloc(str, SeqSize + 5);
}
*t++;
}
str[i] = NULLB;
fseq->label = StringSave(str);
MemFree(str);
/* Reading sequence */
while (isspace(*t)) /* Rolling spaces */
*t++;
str = (CharPtr) MemNew(SeqSize + 5);
str[0] = NULLB;
for(i=0; *t != NULLB; i++) {
if((str[i] = *t) == '>') {
*next = t;
break;
}
if (i > SeqSize) {
SeqSize = i + INIT_BUFF_SIZE;
str = (CharPtr) Realloc(str, SeqSize + 5);
}
*t++;
}
str[i] = NULLB;
fseq->seq = StringSave(str);
MemFree(str);
break;
default:
/* Reading sequence */
while (isspace(*t)) /* Rolling spaces */
*t++;
str = (CharPtr) MemNew(SeqSize + 5);
str[0] = NULLB;
for(i=0; *t != NULLB; i++) {
if((str[i] = *t) == '>') {
*next = t;
break;
}
if (i > SeqSize) {
SeqSize = i + INIT_BUFF_SIZE;
str = (CharPtr) Realloc(str, SeqSize + 5);
}
*t++;
}
str[i] = NULLB;
fseq->seq = StringSave(str);
MemFree(str);
break;
}
if(fseq->label == NULL)
fseq->label = StringSave(">Your sequence");
return fseq;
}
static Int4 FilterNucSequence(CharPtr p)
{
CharPtr t, s;
Int4 len, i =0;
Int4 NumBadChar=0;
len = StringLen(p);
s = p;
for(t = p; i < len; i++){
*p = toupper(*p);
if (isalpha(*p)) {
*t = *p;
*t++;
} else {
if(!isspace(*p)) {
NumBadChar++;
}
}
*p++;
}
*t = NULLB;
p = s;
return NumBadChar;
}
|