37
37
* --------------------------------------------------------------------------
39
39
* $Log: qblastapi.c,v $
40
* Revision 1.30 2004/02/23 15:30:02 lavr
41
* New (last) parameter "how" added in CONN_Write() API call
43
* Revision 1.29 2004/02/20 17:13:01 madden
44
* Doubled some timeouts
46
* Revision 1.28 2003/11/14 16:23:08 dondosha
47
* If query id not local, append title to id to get defline in BLASTGetQuerySummary
49
* Revision 1.27 2003/11/12 21:19:03 kans
50
* changed query_number to query_num - fixing typo
52
* Revision 1.26 2003/11/12 20:49:20 coulouri
53
* Replace code accidentally removed between 1.24 and 1.25 in BlastGetQueryBioseqByRIDEx
55
* Revision 1.25 2003/11/03 20:50:53 madden
56
* Fix problem with content length, remove call to QblastTestRID, add BLASTGetBOByRIDEx
58
* Revision 1.24 2003/01/17 20:40:29 madden
59
* Put QUERY_NUMBER back in URL for fetching Seqannot
61
* Revision 1.23 2003/01/15 22:04:49 madden
62
* Moved BLASTGetSeqAnnotByRIDEx from internal
64
* Revision 1.22 2003/01/02 15:06:48 boemker
65
* Wrote BLASTGetQueryBioseqByRIDEx that extends behavior of
66
* BLASTGetQueryBioseqByRID by returning the Bioseq for a particular query
67
* (rather than always returning the Bioseq for the first query. Modified
68
* BLASTGetQueryBioseqByRID to use BLASTGetQueryBioseqByRIDEx. Wrote
69
* BLASTGetQuerySummary to return information about a query.
71
* Revision 1.21 2002/11/08 22:36:17 kans
72
* in synchronous query, loop on == eIO_Timeout instead of != eIO_Success
74
* Revision 1.20 2002/08/07 18:45:15 lavr
75
* Change from deprecated to current EIO_ReadMethod enums
77
* Revision 1.19 2002/07/24 21:09:56 kans
80
* Revision 1.18 2002/07/23 16:45:21 kans
81
* changed www.ncbi.nlm.nih.gov to www.ncbi.nih.gov
83
* Revision 1.17 2002/04/12 14:27:35 madden
84
* Check RID for internal jobs, send to appropriate place
40
86
* Revision 1.16 2001/02/25 21:50:41 kans
41
87
* changes from Uint4 to size_t due to connection type changes
130
176
starttime = GetSecs ();
131
while ((status = CONN_Wait (conn, eIO_Read, &timeout)) != eIO_Success && max < 300) {
177
while ((status = CONN_Wait (conn, eIO_Read, &timeout)) == eIO_Timeout && max < 300) {
132
178
currtime = GetSecs ();
133
179
max = currtime - starttime;
502
548
fp = FileOpen (path, "r");
503
CONN_Write (conn, (const void *) str, StringLen (str), &n_written);
549
CONN_Write (conn, (const void *) str, StringLen (str),
550
&n_written, eIO_WritePersist);
504
551
QUERY_CopyFileToQuery (conn, fp);
605
652
sprintf (str, "RID=%s&CMD=Get\n", curr->rid);
606
653
conn = QBlastOpenConnection ();
607
654
if (conn != NULL) {
608
CONN_Write (conn, (const void *) str, StringLen (str), &n_written);
655
CONN_Write (conn, (const void *) str, StringLen (str),
656
&n_written, eIO_WritePersist);
609
657
QUERY_SendQuery (conn);
610
658
QUERY_AddToQueue (&(curr->connqueue), conn, SecondQBlastCallback, (Pointer) curr, TRUE);
622
670
sprintf (str, "CMD=Get&RID=%s&FORMAT_OBJECT=Alignment&FORMAT_TYPE=ASN.1\n", curr->rid);
623
671
conn = QBlastOpenConnection ();
624
672
if (conn != NULL) {
625
CONN_Write (conn, (const void *) str, StringLen (str), &n_written);
673
CONN_Write (conn, (const void *) str, StringLen (str),
674
&n_written, eIO_WritePersist);
626
675
QUERY_SendQuery (conn);
627
676
QUERY_AddToQueue (&(curr->connqueue), conn, ThirdQBlastCallback, (Pointer) curr, TRUE);
654
703
sprintf (str, "RID=%s&CMD=Get\n", rid);
655
704
conn = QBlastOpenConnection ();
656
705
if (conn == NULL) return FALSE;
657
CONN_Write (conn, (const void *) str, StringLen (str), &n_written);
706
CONN_Write (conn, (const void *) str, StringLen (str),
707
&n_written, eIO_WritePersist);
658
708
QUERY_SendQuery (conn);
660
710
QBlast_AddToQueue (queue, resultproc, announceproc, userdata, conn, NULL, rid);
733
783
NLM_EXTERN SeqAnnotPtr BLASTGetSeqAnnotByRID(CharPtr RID)
785
return BLASTGetSeqAnnotByRIDEx(RID, NULL, 0, NULL, 0);
789
Returns a SeqAnnot for a given RID.
790
If host_machine and host_path are set to NULL and host_port to zero
791
Default servers will be used.
793
if query_number is set to zero all will be returned, otherwise the
794
one-based offset query will be returned.
796
NLM_EXTERN SeqAnnotPtr BLASTGetSeqAnnotByRIDEx(CharPtr RID,
797
Nlm_CharPtr host_machine,
799
Nlm_CharPtr host_path,
735
802
Char query_string[256];
737
804
SeqAnnotPtr annot;
740
807
AsnIoConnPtr aicp;
741
808
EIO_Status status;
743
/* sprintf(query_string, "RID=%s&ALIGNMENT_VIEW=11", RID); */
745
sprintf(query_string, "FORMAT_TYPE=ASN.1&CMD=Get&RID=%s&"
746
"FORMAT_OBJECT=Alignment", RID);
748
/* conn = QUERY_OpenUrlQuery ("www.ncbi.nlm.nih.gov", 80, */
749
conn = QUERY_OpenUrlQuery ("www.ncbi.nlm.nih.gov", 80,
750
"/blast/Blast.cgi", NULL,
751
"BLASTGetSeqAnnotByRID()",
752
30, eMIME_T_Application,
810
sprintf(query_string,
811
"FORMAT_TYPE=ASN.1&CMD=Get&RID=%s&QUERY_NUMBER=%ld&FORMAT_OBJECT=Alignment",
813
(long) query_number);
815
conn = QUERY_OpenUrlQuery ((host_machine == NULL) ? "www.ncbi.nlm.nih.gov" : host_machine,
816
(host_port <= 0) ? 80 : host_port,
817
(host_path == NULL) ? "/blast/Blast.cgi" : host_path,
818
NULL, "BLASTGetSeqAnnotByRIDEx()",
819
240, eMIME_T_Application,
753
820
eMIME_WwwForm, eENCOD_Url, 0);
755
length = StringLen(query_string)+1;
756
status = CONN_Write (conn, query_string, length , &n_written);
822
length = StringLen(query_string);
823
status = CONN_Write (conn, query_string, length,
824
&n_written, eIO_WritePersist);
757
825
QUERY_SendQuery (conn);
759
827
aicp = QUERY_AsnIoConnOpen ("r", conn);
765
833
CONN_Close(conn);
768
/* Function to get SeqAnnot for RID. We suupose, that search already
837
/* Function to get Bioseq for RID. We suupose, that search already
769
838
finished and results are exists on the Qblast repository */
771
840
NLM_EXTERN BioseqPtr BLASTGetQueryBioseqByRID(CharPtr RID)
842
return BLASTGetQueryBioseqByRIDEx(RID, 0);
845
NLM_EXTERN BioseqPtr BLASTGetQueryBioseqByRIDEx(CharPtr RID, int query_num)
773
847
Char query_string[256];
778
852
AsnIoConnPtr aicp;
779
853
EIO_Status status;
781
/* sprintf(query_string, "RID=%s&ALIGNMENT_VIEW=11", RID); */
783
sprintf(query_string, "CMD=Get&RID=%s&FORMAT_OBJECT=Bioseq&"
784
"FORMAT_TYPE=ASN.1", RID);
786
/* conn = QUERY_OpenUrlQuery ("www.ncbi.nlm.nih.gov", 80, */
855
sprintf(query_string,
856
"FORMAT_TYPE=ASN.1&CMD=Get&RID=%s&QUERY_NUMBER=%ld&FORMAT_OBJECT=Bioseq",
788
860
conn = QUERY_OpenUrlQuery ("www.ncbi.nlm.nih.gov", 80,
789
861
"/blast/Blast.cgi", NULL,
790
"BLASTGetQueryBioseqByRID()",
791
30, eMIME_T_Application,
862
"BLASTGetQueryBioseqByRIDEx()",
863
60, eMIME_T_Application,
792
864
eMIME_WwwForm, eENCOD_Url, 0);
794
866
length = StringLen(query_string);
795
status = CONN_Write (conn, query_string, length , &n_written);
867
status = CONN_Write (conn, query_string, length,
868
&n_written, eIO_WritePersist);
796
869
QUERY_SendQuery (conn);
798
871
aicp = QUERY_AsnIoConnOpen ("r", conn);
881
NLM_EXTERN Nlm_Boolean BLASTGetQuerySummary(CharPtr RID, Int4 query_number,
882
CharPtr *defline, Int4Ptr query_length)
884
BioseqPtr bsp = BLASTGetQueryBioseqByRIDEx(RID, query_number);
887
if (bsp->id->choice == SEQID_LOCAL) {
888
*defline = StringSave(BioseqGetTitle(bsp));
890
#define SEQID_LENGTH 255
892
Char tmp[SEQID_LENGTH+1];
893
Int4 title_length = StringLen(BioseqGetTitle(bsp));
894
SeqIdWrite(bsp->id, tmp, PRINTID_FASTA_LONG, SEQID_LENGTH);
895
id_length = StringLen(tmp);
896
title_length += id_length + 3;
897
*defline = (CharPtr) MemNew(title_length*sizeof(Char));
898
sprintf(*defline, "%s %s", tmp, BioseqGetTitle(bsp));
900
*query_length = BioseqGetLen(bsp);
808
906
/* Function to get BlastObject for RID. We suupose, that search already
809
907
finished and results are exists on the Qblast repository. Blast Object
810
908
ASN.1 will be returned as CharPtr buffer*/
811
NLM_EXTERN CharPtr BLASTGetBOByRID(CharPtr RID)
910
* retrive blast object
912
NLM_EXTERN CharPtr BLASTGetBOByRIDEx(CharPtr RID,
913
Nlm_CharPtr host_machine,
915
Nlm_CharPtr host_path)
813
917
Char query_string[256];
818
922
EIO_Status status;
822
sprintf(query_string, "RID=%s&ALIGNMENT_VIEW=13", RID);
824
925
sprintf(query_string, "CMD=Get&RID=%s&FORMAT_OBJECT=BlastObject&FORMAT_TYPE=ASN.1", RID);
826
conn = QUERY_OpenUrlQuery ("www.ncbi.nlm.nih.gov", 80,
827
"/blast/Blast.cgi", NULL,
829
30, eMIME_T_Application,
927
conn = QUERY_OpenUrlQuery ((host_machine == NULL) ? "www.ncbi.nlm.nih.gov" : host_machine,
928
(host_port <= 0) ? 80 : host_port,
929
(host_path == NULL) ? "/blast/Blast.cgi" : host_path,
931
"BLASTGetBOByRIDEx()",
932
60, eMIME_T_Application,
830
933
eMIME_WwwForm, eENCOD_Url, 0);
832
length = StringLen(query_string) + 1;
833
status = CONN_Write (conn, query_string, length , &n_written);
935
length = StringLen(query_string);
936
status = CONN_Write (conn, query_string, length,
937
&n_written, eIO_WritePersist);
834
938
QUERY_SendQuery (conn);
843
947
while ((status = CONN_Read(conn, in_buff + buff_len,
844
1024, &bytes, eIO_Plain)) == eIO_Success) {
948
1024, &bytes, eIO_ReadPlain)) == eIO_Success) {