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

« back to all changes in this revision

Viewing changes to tools/taxblast.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:
1
 
/* $Id: taxblast.c,v 6.12 2001/12/13 21:48:51 camacho Exp $
 
1
static char const rcsid[] = "$Id: taxblast.c,v 6.23 2004/09/08 11:40:09 bollin Exp $";
 
2
 
 
3
/* $Id: taxblast.c,v 6.23 2004/09/08 11:40:09 bollin Exp $
2
4
* ===========================================================================
3
5
*
4
6
*                            PUBLIC DOMAIN NOTICE
29
31
*
30
32
* Initial Version Creation Date: 04/04/2000
31
33
*
32
 
* $Revision: 6.12 $
 
34
* $Revision: 6.23 $
33
35
*
34
36
* File Description:
35
37
*        Utilities and functions for Tax-Blast program
36
38
*
37
39
* $Log: taxblast.c,v $
 
40
* Revision 6.23  2004/09/08 11:40:09  bollin
 
41
* removed network/taxon1 dependencies
 
42
*
 
43
* Revision 6.22  2004/08/30 13:43:54  madden
 
44
* Change from htbin-post URL
 
45
*
 
46
* Revision 6.21  2003/09/16 16:03:19  rsmith
 
47
* guard include of unistd.h to only those platforms that need it and can use it.
 
48
*
 
49
* Revision 6.20  2003/09/15 18:46:29  rsmith
 
50
* added unistd.h include for sleep
 
51
*
 
52
* Revision 6.19  2003/05/30 17:25:38  coulouri
 
53
* add rcsid
 
54
*
 
55
* Revision 6.18  2003/05/13 16:02:54  coulouri
 
56
* make ErrPostEx(SEV_FATAL, ...) exit with nonzero status
 
57
*
 
58
* Revision 6.17  2002/11/06 21:31:47  ucko
 
59
* TXBGetGiFromSeqId: Compare oip->id to 0 rather than NULL, as it is an integer.
 
60
*
 
61
* Revision 6.16  2002/10/07 19:52:07  camacho
 
62
* Added RDTaxLookupReset
 
63
*
 
64
* Revision 6.15  2002/07/02 16:38:04  camacho
 
65
* Moved increment of number of taxids in db to end of FDBTaxCallback
 
66
*
 
67
* Revision 6.14  2002/05/23 22:22:15  camacho
 
68
* Do not keep entries with taxid 0 in blast taxonomy database
 
69
*
 
70
* Revision 6.13  2002/01/11 16:31:13  camacho
 
71
* Verify if taxonomy service is properly initialized in RDTaxLookupInit
 
72
*
38
73
* Revision 6.12  2001/12/13 21:48:51  camacho
39
74
* Fixed retrieval of maximum taxonomy id to properly populate the
40
75
* RDBTaxLookup structure.
100
135
*/
101
136
 
102
137
#include <ncbi.h>
 
138
#if defined(OS_MAC)  ||  defined(COMP_METRO)
 
139
#include <unistd.h> /* for sleep()  */
 
140
#endif
103
141
#include <sequtil.h>
104
142
#include <treemgr.h>
105
 
#include <taxinc.h>
106
143
#include <taxext.h>
107
 
#include <taxutil.h>
108
144
#include <txclient.h>
109
145
#include <objseq.h>
110
146
#include <objgen.h>
383
419
            oip = (ObjectIdPtr) dbtag->tag;
384
420
 
385
421
            if (oip != NULL) {
386
 
                if (oip->id != NULL) {
 
422
                if (oip->id != 0) {
387
423
                    sprintf(buffer, "%d", oip->id);
388
424
                    *accessionp = StringSave(buffer);
389
425
                } else if (oip->str)
1243
1279
        for (i=0; i<depth; i++) 
1244
1280
            fputs (". ", outfile);
1245
1281
 
1246
 
        fprintf (outfile, "<a href=http://www.ncbi.nlm.nih.gov/htbin-post/Taxonomy/wgetorg?id=%d>%s</a>", lo_next->taxid, lo_next->name);
 
1282
        fprintf (outfile, "<a href=http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=%ld>%s</a>", 
 
1283
           (long) lo_next->taxid, lo_next->name);
1247
1284
        
1248
1285
        bname = GetBlastName (lo_next->taxid, tree);
1249
1286
 
1250
1287
        if (bname && bname->name) {
1251
1288
            for (i=taxa_name_len[depth]; 
1252
1289
                 i<=longname; i++) fputc (' ', outfile);
1253
 
            fprintf (outfile, "[<a href=http://www.ncbi.nlm.nih.gov/htbin-post/Taxonomy/wgetorg?id=%d>%s</a>]", bname->taxid, bname->name);
 
1290
            fprintf (outfile, "[<a href=http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=%ld>%s</a>]", 
 
1291
               (long) bname->taxid, bname->name);
1254
1292
        }
1255
1293
        fputc ('\n', outfile);
1256
1294
 
1297
1335
            orgoff = org->data.intvalue;
1298
1336
            taxid = orgobj->taxids[orgoff];
1299
1337
            for (j=0; j<depth; j++) fputs(". ", outfile);
1300
 
            fprintf (outfile, "<A HREF=http://www.ncbi.nlm.nih.gov/htbin-post/Taxonomy/wgetorg?id=%d>%s</A>", taxid, orgobj->names[orgoff]);
 
1338
            fprintf (outfile, "<A HREF=http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=%ld>%s</A>", 
 
1339
               (long) taxid, orgobj->names[orgoff]);
1301
1340
            if (orgobj->cnames[orgoff]->count > 0) {
1302
1341
                cname = (CharPtr)orgobj->cnames[orgoff]->names->data.ptrvalue;
1303
1342
                StrNCpy (buffer, cname, BUFFLEN);
1328
1367
            else fprintf(outfile, "<a href=#%d>%d hits</a>", taxid, numhits);
1329
1368
            
1330
1369
            if (size_bnames[i]>0)
1331
 
                fprintf (outfile, " [<a href=http://www.ncbi.nlm.nih.gov/htbin-post/Taxonomy/wgetorg?id=%d>%s</a>]", orgobj->bnames[orgoff]->taxid, orgobj->bnames[orgoff]->name);
 
1370
                fprintf (outfile, " [<a href=http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=%ld>%s</a>]", 
 
1371
                    (long) orgobj->bnames[orgoff]->taxid, orgobj->bnames[orgoff]->name);
1332
1372
            else fputs(" []", outfile);
1333
1373
            for (j=size_bnames[i]; j<=max_bnames; j++) fputc(' ', outfile);
1334
1374
 
1385
1425
    numorgs = orgobj->numorgs;
1386
1426
    for (i=0; i<numorgs; i++) {
1387
1427
        fprintf (outfile, "<a name=%d></a>", orgobj->taxids[i]);
1388
 
        fprintf (outfile, "  <b><a href=http://www.ncbi.nlm.nih.gov/htbin-post/Taxonomy/wgetorg?id=%d>%s</a></b>", orgobj->taxids[i], orgobj->names[i]);
 
1428
        fprintf (outfile, "  <b><a href=http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=%ld>%s</a></b>", 
 
1429
               (long) orgobj->taxids[i], orgobj->names[i]);
1389
1430
        
1390
1431
        if (orgobj->cnames[i]->count > 0) {
1391
1432
            cname= (CharPtr) orgobj->cnames[i]->names->data.ptrvalue;
1396
1437
        }
1397
1438
        
1398
1439
        if (orgobj->bnames[i] && orgobj->bnames[i]->name) {
1399
 
            fprintf (outfile, " [<a href=http://www.ncbi.nlm.nih.gov/htbin-post/Taxonomy/wgetorg?id=%d>%s</a>]", orgobj->bnames[i]->taxid, orgobj->bnames[i]->name);
 
1440
            fprintf (outfile, " [<a href=http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=%ld>%s</a>]", 
 
1441
                 (long) orgobj->bnames[i]->taxid, orgobj->bnames[i]->name);
1400
1442
        }
1401
1443
        
1402
1444
        fprintf (outfile, " taxid %d", orgobj->taxids[i]);
1693
1735
    if(tax_lookup->tax_array[tax_id] != NULL)
1694
1736
        return TRUE;
1695
1737
 
1696
 
    if(tax_id == 0) {
1697
 
        /* For unresolved tax_id we will eventually create some
1698
 
           entry */
1699
 
        tnames = MemNew(sizeof(RDBTaxNames));
1700
 
        tnames->sci_name = StringSave("Unknown");
1701
 
        tnames->common_name = StringSave("Unknown");
1702
 
        tnames->blast_name = StringSave("Unknown");
1703
 
        StringCpy(tnames->s_king, "-");
1704
 
        tax_lookup->tax_array[0] = tnames;
1705
 
        tax_lookup->taxids_in_db++;
1706
 
 
 
1738
    if(tax_id == 0)
1707
1739
        return TRUE;
1708
 
    }
1709
1740
    
1710
 
    tax_lookup->taxids_in_db++;
1711
1741
    tdp = (TAXDataPtr) tax_lookup->tax_data;
1712
1742
    
1713
1743
    tax_tree= tdp->tax_tree;
1769
1799
            tnames->blast_name,tnames->s_king[0],tnames->s_king[1],
1770
1800
            tnames->s_king[2]);
1771
1801
#endif
 
1802
    tax_lookup->taxids_in_db++;
1772
1803
 
1773
1804
    return TRUE;
1774
1805
}
1802
1833
{
1803
1834
    RDBTaxLookupPtr tax_lookup;
1804
1835
    TAXDataPtr tax_data;
 
1836
    Int2 retries = 3, secs2wait = 10;
1805
1837
 
1806
1838
    /* connect to taxonomy service */
1807
 
    tax1_init();   
 
1839
    while (retries--) {
 
1840
        if (tax1_init())
 
1841
            break;
 
1842
        else
 
1843
            sleep(secs2wait);
 
1844
    }
 
1845
 
 
1846
    if (!tax1_isAlive()) {
 
1847
        ErrPostEx(SEV_FATAL, 1,0, 
 
1848
                "Could not initialize taxonomy service: RDTaxLookupInit");
 
1849
        return NULL;
 
1850
    }
1808
1851
    
1809
1852
    /* download all the taxonomy tree from the server */
1810
1853
    tax1e_invokeChildren(-1); 
1823
1866
    return tax_lookup;
1824
1867
}
1825
1868
 
1826
 
void RDTaxLookupClose(RDBTaxLookupPtr tax_lookup)
 
1869
/* Remove all entries from taxonomy lookup structure but don't close the 
 
1870
 * connection to the taxonomy service */
 
1871
RDBTaxLookupPtr RDTaxLookupReset(RDBTaxLookupPtr tax_lookup)
1827
1872
{
1828
1873
    RDBTaxNamesPtr tnames;
1829
1874
    Int4 i;
1830
1875
 
1831
 
    MemFree(tax_lookup->tax_data);
1832
 
    
1833
1876
    for(i = 0; i < tax_lookup->all_taxid_count; i++) {        
1834
1877
        
1835
1878
        tnames = tax_lookup->tax_array[i];
1836
1879
        
1837
 
        if(tnames != NULL) {
 
1880
        if (tnames != NULL) {
1838
1881
            MemFree(tnames->sci_name);
1839
1882
            MemFree(tnames->common_name);
1840
1883
            MemFree(tnames->blast_name);
1841
1884
            MemFree(tnames);
1842
1885
        }
 
1886
        tax_lookup->tax_array[i] = tnames = NULL;
1843
1887
    }
1844
 
    
 
1888
        tax_lookup->taxids_in_db = 0; 
 
1889
}
 
1890
 
 
1891
void RDTaxLookupClose(RDBTaxLookupPtr tax_lookup)
 
1892
{
 
1893
        tax_lookup = RDTaxLookupReset(tax_lookup);
 
1894
 
 
1895
    MemFree(tax_lookup->tax_data);
1845
1896
    MemFree(tax_lookup->tax_array);
1846
1897
    MemFree(tax_lookup);
1847
1898
    
1880
1931
        is_na = TRUE;
1881
1932
    
1882
1933
    if((aip = AsnIoOpen(myargs[0].strvalue, "r")) == NULL) {
1883
 
        ErrPostEx(SEV_FATAL, 0,0, "AsnIoOpen failure\n");
 
1934
        ErrPostEx(SEV_FATAL, 1,0, "AsnIoOpen failure\n");
1884
1935
        return 1;
1885
1936
    }
1886
1937
    
1887
1938
    if((sap = SeqAnnotAsnRead (aip, NULL)) == NULL) {
1888
 
        ErrPostEx(SEV_FATAL, 0,0,"SeqAlignAsnRead failure\n");
 
1939
        ErrPostEx(SEV_FATAL, 1,0,"SeqAlignAsnRead failure\n");
1889
1940
        return 1;
1890
1941
    }
1891
1942