~ubuntu-branches/ubuntu/precise/ncbi-tools6/precise

« back to all changes in this revision

Viewing changes to access/qblastapi.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-03-27 12:00:15 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050327120015-embhesp32nj73p9r
Tags: 6.1.20041020-3
* Fix FTBFS under GCC 4.0 caused by inconsistent use of "static" on
  functions.  (Closes: #295110.)
* Add a watch file, now that we can.  (Upstream's layout needs version=3.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
*
30
30
* Version Creation Date:   6/28/00
31
31
*
32
 
* $Revision: 1.16 $
 
32
* $Revision: 1.30 $
33
33
*
34
34
* File Description: 
35
35
*
37
37
* --------------------------------------------------------------------------
38
38
*
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
 
42
*
 
43
* Revision 1.29  2004/02/20 17:13:01  madden
 
44
* Doubled some timeouts
 
45
*
 
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
 
48
*
 
49
* Revision 1.27  2003/11/12 21:19:03  kans
 
50
* changed query_number to query_num - fixing typo
 
51
*
 
52
* Revision 1.26  2003/11/12 20:49:20  coulouri
 
53
* Replace code accidentally removed between 1.24 and 1.25 in BlastGetQueryBioseqByRIDEx
 
54
*
 
55
* Revision 1.25  2003/11/03 20:50:53  madden
 
56
* Fix problem with content length, remove call to QblastTestRID, add BLASTGetBOByRIDEx
 
57
*
 
58
* Revision 1.24  2003/01/17 20:40:29  madden
 
59
* Put QUERY_NUMBER back in URL for fetching Seqannot
 
60
*
 
61
* Revision 1.23  2003/01/15 22:04:49  madden
 
62
* Moved BLASTGetSeqAnnotByRIDEx from internal
 
63
*
 
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.
 
70
*
 
71
* Revision 1.21  2002/11/08 22:36:17  kans
 
72
* in synchronous query, loop on == eIO_Timeout instead of != eIO_Success
 
73
*
 
74
* Revision 1.20  2002/08/07 18:45:15  lavr
 
75
* Change from deprecated to current EIO_ReadMethod enums
 
76
*
 
77
* Revision 1.19  2002/07/24 21:09:56  kans
 
78
* reverted ncbi URL
 
79
*
 
80
* Revision 1.18  2002/07/23 16:45:21  kans
 
81
* changed www.ncbi.nlm.nih.gov to www.ncbi.nih.gov
 
82
*
 
83
* Revision 1.17  2002/04/12 14:27:35  madden
 
84
* Check RID for internal jobs, send to appropriate place
 
85
*
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
42
88
*
128
174
#endif
129
175
 
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;
134
180
#ifdef OS_MAC
500
546
  FileClose (fp);
501
547
 
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);
505
552
  FileClose (fp);
506
553
 
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);
611
659
          } else {
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);
628
677
      } else {
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);
659
709
 
660
710
  QBlast_AddToQueue (queue, resultproc, announceproc, userdata, conn, NULL, rid);
732
782
 
733
783
NLM_EXTERN SeqAnnotPtr BLASTGetSeqAnnotByRID(CharPtr RID)
734
784
{
 
785
    return BLASTGetSeqAnnotByRIDEx(RID, NULL, 0, NULL, 0);
 
786
}
 
787
 
 
788
/*
 
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.
 
792
 
 
793
        if query_number is set to zero all will be returned, otherwise the
 
794
        one-based offset query will be returned.
 
795
 */
 
796
NLM_EXTERN SeqAnnotPtr BLASTGetSeqAnnotByRIDEx(CharPtr RID,
 
797
                                               Nlm_CharPtr host_machine, 
 
798
                                               Nlm_Uint2 host_port, 
 
799
                                               Nlm_CharPtr host_path,
 
800
                                               Int4 query_number)
 
801
{
735
802
    Char         query_string[256];
736
803
    CONN         conn;
737
804
    SeqAnnotPtr  annot;
740
807
    AsnIoConnPtr aicp;
741
808
    EIO_Status   status;
742
809
 
743
 
    /* sprintf(query_string, "RID=%s&ALIGNMENT_VIEW=11", RID); */
744
 
    
745
 
    sprintf(query_string, "FORMAT_TYPE=ASN.1&CMD=Get&RID=%s&"
746
 
            "FORMAT_OBJECT=Alignment", RID);
747
 
    
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", 
 
812
            RID,
 
813
            (long) query_number);
 
814
 
 
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);
754
821
    
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);
758
826
    
759
827
    aicp = QUERY_AsnIoConnOpen ("r", conn);
765
833
    CONN_Close(conn);
766
834
    return annot;
767
835
}
768
 
/* Function to get SeqAnnot for RID. We suupose, that search already
 
836
 
 
837
/* Function to get Bioseq for RID. We suupose, that search already
769
838
   finished and results are exists on the Qblast repository */
770
839
 
771
840
NLM_EXTERN BioseqPtr BLASTGetQueryBioseqByRID(CharPtr RID)
772
841
{
 
842
        return BLASTGetQueryBioseqByRIDEx(RID, 0);
 
843
}
 
844
 
 
845
NLM_EXTERN BioseqPtr BLASTGetQueryBioseqByRIDEx(CharPtr RID, int query_num)
 
846
{
773
847
    Char         query_string[256];
774
848
    CONN         conn;
775
849
    BioseqPtr    bsp;
777
851
    Int4         length;
778
852
    AsnIoConnPtr aicp;
779
853
    EIO_Status   status;
780
 
    
781
 
    /* sprintf(query_string, "RID=%s&ALIGNMENT_VIEW=11", RID); */
782
 
    
783
 
    sprintf(query_string, "CMD=Get&RID=%s&FORMAT_OBJECT=Bioseq&"
784
 
            "FORMAT_TYPE=ASN.1", RID);
785
 
    
786
 
    /* conn = QUERY_OpenUrlQuery ("www.ncbi.nlm.nih.gov", 80,  */
 
854
 
 
855
    sprintf(query_string,
 
856
            "FORMAT_TYPE=ASN.1&CMD=Get&RID=%s&QUERY_NUMBER=%ld&FORMAT_OBJECT=Bioseq", 
 
857
            RID,
 
858
            (long) query_num);
787
859
    
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);
793
865
 
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);
797
870
    
798
871
    aicp = QUERY_AsnIoConnOpen ("r", conn);
805
878
    return bsp;
806
879
}
807
880
 
 
881
NLM_EXTERN Nlm_Boolean BLASTGetQuerySummary(CharPtr RID, Int4 query_number,
 
882
    CharPtr *defline, Int4Ptr query_length)
 
883
{
 
884
    BioseqPtr bsp = BLASTGetQueryBioseqByRIDEx(RID, query_number);
 
885
    if(!bsp)
 
886
        return FALSE;
 
887
    if (bsp->id->choice == SEQID_LOCAL) {
 
888
       *defline = StringSave(BioseqGetTitle(bsp));
 
889
    } else {
 
890
#define SEQID_LENGTH 255
 
891
       Int4 id_length;
 
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));
 
899
    }
 
900
    *query_length = BioseqGetLen(bsp);
 
901
    BioseqFree(bsp);
 
902
    return TRUE;
 
903
}
 
904
 
 
905
 
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)
 
909
/*
 
910
 * retrive blast object
 
911
 */
 
912
NLM_EXTERN CharPtr BLASTGetBOByRIDEx(CharPtr RID,
 
913
                                     Nlm_CharPtr host_machine,
 
914
                                     Nlm_Uint2 host_port,
 
915
                                     Nlm_CharPtr host_path)
812
916
{
813
917
    Char         query_string[256];
814
918
    CONN         conn;
818
922
    EIO_Status   status;
819
923
    CharPtr      in_buff;
820
924
    
821
 
/*
822
 
    sprintf(query_string, "RID=%s&ALIGNMENT_VIEW=13", RID);
823
 
*/
824
925
    sprintf(query_string, "CMD=Get&RID=%s&FORMAT_OBJECT=BlastObject&FORMAT_TYPE=ASN.1", RID);
825
 
    
826
 
    conn = QUERY_OpenUrlQuery ("www.ncbi.nlm.nih.gov", 80, 
827
 
                               "/blast/Blast.cgi", NULL, 
828
 
                               "BLASTGetBOByRID()", 
829
 
                               30, eMIME_T_Application, 
 
926
 
 
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,
 
930
                                NULL,
 
931
                               "BLASTGetBOByRIDEx()", 
 
932
                               60, eMIME_T_Application, 
830
933
                               eMIME_WwwForm, eENCOD_Url, 0);
831
934
 
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);
835
939
    
836
940
    new_size = 1024;   
841
945
 
842
946
    buff_len = 0;
843
947
    while ((status = CONN_Read(conn, in_buff + buff_len, 
844
 
                               1024, &bytes, eIO_Plain)) == eIO_Success) {
845
 
        
 
948
                               1024, &bytes, eIO_ReadPlain)) == eIO_Success) {
846
949
        if(bytes == 0) 
847
950
            break;
848
951
 
860
963
    CONN_Close(conn);
861
964
    return in_buff;
862
965
}
 
966
 
 
967
NLM_EXTERN CharPtr BLASTGetBOByRID(CharPtr RID)
 
968
{
 
969
        return BLASTGetBOByRIDEx(RID, NULL, 0, NULL);
 
970
}