~ubuntu-branches/debian/experimental/ncbi-tools6/experimental

« back to all changes in this revision

Viewing changes to demo/getseq.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2008-07-14 19:43:15 UTC
  • mfrom: (2.1.12 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080714194315-ed44u9ek7txva2rz
Tags: 6.1.20080302-3
tools/readdb.c: enable madvise()-based code on all glibc (hence all
Debian) systems, not just Linux.  (Closes: #490437.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
*
3
 
*   getseq.c
4
 
*     entrez version
5
 
*
6
 
*****************************************************************************/
7
 
#include <accentr.h>
8
 
#include <sequtil.h>
9
 
 
10
 
#define NUMARGS 9
11
 
Args myargs[NUMARGS] = {
12
 
 /*0*/ { "Input string id",  "DROADH", NULL, NULL, FALSE, 'i', ARG_STRING, 0.0,0,NULL},
13
 
 /*1*/ { "Output Seq-entry", "T", NULL, NULL, TRUE , 's', ARG_BOOLEAN, 0.0,0,NULL},
14
 
 /*2*/ { "Output File Name", "getseq.out", NULL, NULL, FALSE, 'o', ARG_FILE_OUT, 0.0,0,NULL},
15
 
 /*3*/ { "GenInfo Import id", "0", NULL, NULL, TRUE , 'g', ARG_INT, 0.0,0,NULL},
16
 
 /*4*/ { "Id is GenBank accession", "F", NULL, NULL, TRUE , 'a', ARG_BOOLEAN, 0.0,0,NULL},
17
 
 /*5*/ { "Id is GenBank locus", "T", NULL, NULL, TRUE , 'l', ARG_BOOLEAN, 0.0,0,NULL},
18
 
 /*6*/ { "Id is PIR accession", "F", NULL, NULL, TRUE , 'b', ARG_BOOLEAN, 0.0,0,NULL},
19
 
 /*7*/ { "Id is PIR locus", "F", NULL, NULL, TRUE , 'p', ARG_BOOLEAN, 0.0,0,NULL},
20
 
 /*8*/ { "Return type 1=Bioseq,2=seg-set,3=nuc-prot,4=pub-set", "3", "1", "4", TRUE , 'r', ARG_INT, 0.0,0,NULL}};
21
 
 
22
 
Int2 Main(void)
23
 
{
24
 
        Boolean      seqentry; /* Arg 1 should always be TRUE */
25
 
        Int2         retcode;  /* Default is nuc-prot         */
26
 
 
27
 
        TextSeqIdPtr tsip;     /* Text object, name, locus, or release */
28
 
        SeqIdPtr     sip;      /* Same as a ValNodePtr, generic data ptr implemented */
29
 
                               /*   as a choice and a union.  Used to pass "tsip" data */
30
 
        GiimPtr      giim;     /* GenInfo structure passed via "sip" in the special case */
31
 
                               /*   of accessing a by GenInfo Id */
32
 
 
33
 
        Int4         uid;
34
 
        SeqEntryPtr  sep;
35
 
        AsnIoPtr     aipout;
36
 
        Boolean      is_network;
37
 
        SeqIdPtr     sip2;
38
 
        Char buf[40];
39
 
 
40
 
        buf[0] = '\0';
41
 
 
42
 
        /*
43
 
        ** Get program arguments
44
 
        */
45
 
 
46
 
        if ( !GetArgs("GetSeq 1.0", NUMARGS, myargs) ) return 1;
47
 
 
48
 
        /*
49
 
        ** Set parameters from the command line
50
 
        */
51
 
 
52
 
        seqentry = (Boolean)myargs[1].intvalue;
53
 
        retcode = (Int2)myargs[8].intvalue;
54
 
 
55
 
        /*
56
 
        ** Instantiate ASN stream pointers and data.
57
 
        ** "sip" is used to pass the information in "tsip".
58
 
        */
59
 
 
60
 
        tsip = TextSeqIdNew();
61
 
        sip = ValNodeNew(NULL);
62
 
        sip->data.ptrvalue = tsip;
63
 
 
64
 
        /*
65
 
        ** From the command line, set either the name or accession field
66
 
        ** and the choice field of SeqIdPtr, this structure will be used
67
 
        ** to return an ASN stream from the CD-ROM
68
 
        */
69
 
 
70
 
        if (myargs[3].intvalue) {                      /* GenInfo import ID */
71
 
                giim = GiimNew();
72
 
                giim->id = myargs[3].intvalue;
73
 
                sip->data.ptrvalue = giim;
74
 
                sip->choice = SEQID_GIIM;
75
 
        } else if (myargs[4].intvalue)  {              /* GenBank accession */
76
 
                tsip->accession = myargs[0].strvalue;
77
 
                sip->choice = SEQID_GENBANK;
78
 
        } else if (myargs[5].intvalue)  {              /* GenBank locus     */
79
 
                tsip->name = myargs[0].strvalue;
80
 
                sip->choice = SEQID_GENBANK;
81
 
        } else if (myargs[6].intvalue) {               /* PIR accession     */
82
 
                tsip->accession = myargs[0].strvalue;
83
 
                sip->choice = SEQID_PIR;
84
 
        } else if (myargs[7].intvalue) {               /* PIR locus name    */
85
 
                tsip->name = myargs[0].strvalue;
86
 
                sip->choice = SEQID_PIR;
87
 
        }
88
 
 
89
 
        /*
90
 
        ** Initialize, open and otherwise prepare for CD-ROM or Network access.
91
 
        */
92
 
 
93
 
        if ( !EntrezInit("GetSeq", FALSE, &is_network) ) {
94
 
                Message(MSG_ERROR, "Init failed");
95
 
                return 1;
96
 
        }
97
 
 
98
 
        /*
99
 
        ** Using the SeqEntryPtr structure query the access routines
100
 
        ** and get the internal access number for this SeqEntry
101
 
        **
102
 
        ** If the SeqEntryPtr comes up without a hit, report the error and
103
 
        ** and exit.
104
 
        **
105
 
        ** Otherwise, use the internal access number, uid, and retrieve a
106
 
        ** a sequence entry ASN pointer, sep.  If for some strange reason
107
 
        ** that it is NULL report the error and exit.
108
 
        **
109
 
        ** Finaly, open an ASN file stream and write the sequence entry out
110
 
        ** in Print-Value format. Filename is from command line.
111
 
        **
112
 
        ** Close the ASN file stream, free up memory create which was 
113
 
        ** allocated elsewhere, sep.
114
 
        */
115
 
 
116
 
        if (seqentry) {
117
 
                uid = EntrezFindSeqId(sip);
118
 
                if (! uid)
119
 
                        Message(MSG_ERROR, "Couldn't find uid");
120
 
                else {
121
 
                        sip2 = EntrezSeqIdForGI(uid);
122
 
                        SeqIdPrint(sip2, buf, PRINTID_FASTA_LONG);
123
 
                        Message(MSG_OK, "Got back [%s]", buf);
124
 
                        sep = EntrezSeqEntryGet(uid, retcode);
125
 
                        if (sep == NULL)
126
 
                                Message(MSG_ERROR, "sep was NULL");
127
 
                        else {
128
 
                                aipout = AsnIoOpen(myargs[2].strvalue, "w");
129
 
                                SeqEntryAsnWrite(sep, aipout, NULL);
130
 
                                AsnIoClose(aipout);
131
 
                                SeqEntryFree(sep);
132
 
                        }
133
 
                }
134
 
        } else {
135
 
                Message(MSG_ERROR, "Oops");
136
 
        }
137
 
 
138
 
        /*
139
 
        ** Close down the CD-ROM or Network access.
140
 
        ** Return OK to Operating system.
141
 
        */
142
 
 
143
 
        EntrezFini();
144
 
        return 0;
145
 
}
146
 
 
147