Next version of JABA
[jabaws.git] / binaries / src / fasta34 / url_subs.c
1
2 /* copyright (c) 1998, 1999 William R. Pearson and the
3    U. of Virginia */
4
5 /* $Name: fa_34_26_5 $ - $Id: url_subs.c,v 1.9 2006/08/20 18:18:33 wrp Exp $ */
6
7 /* 30 Dec 2004 - modify REF_URL to accomodate current Entrez */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 #include "defs.h"
14 #include "structs.h"
15 #include "param.h"
16
17 #ifndef DEF_PROT_LIB
18 #define DEF_PROT_LIB "q"
19 #endif
20
21 #ifndef FASTA_HOST
22 #define FASTA_HOST "your.fasta.host.here/fasta/cgi"
23 #endif
24
25 void do_url1(FILE *fp, struct mngmsg m_msg, struct pstruct pst,
26              char *l_name, int n1, struct a_struct aln, long loffset)
27 {
28   char my_l_name[200];
29   char *db;
30   char pgm[10], lib[MAX_FN];
31   char *ref_url, *lbp=NULL;
32   char *srch_url, *srch_url1;
33
34   if (m_msg.ldnaseq==SEQT_DNA) db="nucleotide";
35   else db="Protein";
36
37   if (strncmp(m_msg.f_id0,"rss",3)==0) {
38     strncpy(pgm,"fa",sizeof(pgm));
39   }
40   else if (strncmp(m_msg.f_id0,"rfx",3)==0) {
41     strncpy(pgm,"fx",sizeof(pgm));
42   }
43   else { strncpy(pgm,m_msg.f_id0,sizeof(pgm)); }
44
45   if (m_msg.lname[0]!='%') {
46     strncpy(lib,m_msg.lname,sizeof(lib));
47   }
48   else {
49     strncpy(lib,"%25",sizeof(lib));
50     strncat(lib,&m_msg.lname[1],sizeof(lib));
51   }
52   lib[sizeof(lib)-1]='\0';
53
54   strncpy(my_l_name,l_name,sizeof(my_l_name));
55   my_l_name[sizeof(my_l_name)-1]='\0';
56
57   if (pgm[0]=='t' || strcmp(pgm,"fx") || strcmp(pgm,"fy")==0 ) {
58     if ((lbp=strchr(my_l_name,':'))!=NULL) *lbp='\0';
59     lbp = &my_l_name[strlen(my_l_name)-2];
60     if ( *lbp == '_' ) *lbp = '\0';
61   }
62
63   /* change the program name for fastx, tfastx, tfasta */
64   /* fastx returns proteins */
65   if (strcmp(pgm,"fx")==0 || strcmp(pgm,"fy")==0) strncpy(pgm,"fa",sizeof(pgm));
66   else if (strcmp(pgm,"ff")==0) strncpy(pgm,"fa",sizeof(pgm));
67   else if (pgm[0]=='t') {
68     strncpy(pgm,"fx",sizeof(pgm));
69     strncpy(lib,DEF_PROT_LIB,sizeof(lib));
70   }
71
72   fflush(fp);
73   if ((ref_url = getenv("REF_URL"))==NULL)
74     fprintf(fp,"<A HREF=\"http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=%s&fcmd=Search&doptcmd1=DocSum&term=%s\">Entrez lookup</A>&nbsp;&nbsp;",
75             db,my_l_name);
76   else
77     fprintf(fp,ref_url,db,my_l_name);
78
79   if ((srch_url = getenv("SRCH_URL"))==NULL)
80     fprintf(fp,"<A HREF=\"http://%s/searchfa.cgi?query=%s&db=%s&lib=%s&pgm=%s&start=%ld&stop=%ld&n1=%d\">Re-search database</A>&nbsp;&nbsp;",
81             FASTA_HOST,my_l_name,db,lib,pgm,
82             loffset+aln.amin1+1,loffset+aln.amax1,n1);
83   else 
84     fprintf(fp,srch_url,my_l_name,db,lib,pgm,
85             loffset+aln.amin1+1,loffset+aln.amax1,n1);
86
87   if ((srch_url1 = getenv("SRCH_URL1"))==NULL)
88     fprintf(fp,"<A HREF=\"http://%s/searchxf.cgi?query=%s&db=%s&lib=%s&pgm=%s&start=%ld&stop=%ld&n1=%d\">General re-search</A>\n<p>\n",
89             FASTA_HOST,my_l_name,db,lib,pgm,
90             loffset+aln.amin1+1,loffset+aln.amax1,n1);
91   else 
92     fprintf(fp,srch_url1,my_l_name,db,lib,pgm,
93             loffset+aln.amin1+1,loffset+aln.amax1,n1);
94
95   /* put back "_r"  */
96   if (lbp!=NULL) *lbp = '_';
97
98   /*
99   if ((srch_url2 = getenv("SRCH_URL2"))==NULL)
100     fprintf(fp,"<A HREF=\"http://fasta.bioch.virginia.edu/fasta/cgi/lalignx.cgi?seq1=\"%s\"&in_seq1=\"FASTA\"&seq2=\"%s\"&in_seq2=\"Accession\"&ssr2=%ld:%ld\">lalign</A>\n<p>\n",my_l_name,db,lib,pgm,loffset+aln.amin1+1,loffset+aln.amax1,n1);
101   else 
102     fprintf(fp,srch_url1,my_l_name,db,lib,pgm,
103             loffset+aln.amin1+1,loffset+aln.amax1,n1);
104   */
105   fflush(fp);
106
107 }