~ubuntu-branches/ubuntu/warty/ncbi-tools6/warty

« back to all changes in this revision

Viewing changes to demo/getfasta.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2002-04-04 22:13:09 UTC
  • Revision ID: james.westby@ubuntu.com-20020404221309-vfze028rfnlrldct
Tags: upstream-6.1.20011220a
ImportĀ upstreamĀ versionĀ 6.1.20011220a

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 <tofasta.h>
 
9
 
 
10
#define NUMARGS 9
 
11
Args myargs[NUMARGS] = {
 
12
 /*0*/ { "Input string id",  "M65051", 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", "stdout", 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", "T", NULL, NULL, TRUE , 'a', ARG_BOOLEAN, 0.0,0,NULL},
 
17
 /*5*/ { "Id is GenBank locus", "F", 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", "1", "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
        FILE * output;
 
36
 
 
37
        /*
 
38
        ** Get program arguments
 
39
        */
 
40
 
 
41
        if ( !GetArgs("GetSeq 1.1", NUMARGS, myargs) ) return 1;
 
42
 
 
43
        /*
 
44
        ** Set parameters from the command line
 
45
        */
 
46
 
 
47
        seqentry = (Boolean)myargs[1].intvalue;
 
48
        retcode = (Int2)myargs[8].intvalue;
 
49
 
 
50
        /*
 
51
        ** Instantiate ASN stream pointers and data.
 
52
        ** "sip" is used to pass the information in "tsip".
 
53
        */
 
54
 
 
55
        tsip = TextSeqIdNew();
 
56
        sip = ValNodeNew(NULL);
 
57
        sip->data.ptrvalue = tsip;
 
58
 
 
59
        /*
 
60
        ** From the command line, set either the name or accession field
 
61
        ** and the choice field of SeqIdPtr, this structure will be used
 
62
        ** to return an ASN stream from the CD-ROM
 
63
        */
 
64
 
 
65
        if (myargs[3].intvalue) {                      /* GenInfo import ID */
 
66
                giim = GiimNew();
 
67
                giim->id = myargs[3].intvalue;
 
68
                sip->data.ptrvalue = giim;
 
69
                sip->choice = SEQID_GIIM;
 
70
        } else if (myargs[4].intvalue)  {              /* GenBank accession */
 
71
                tsip->accession = myargs[0].strvalue;
 
72
                sip->choice = SEQID_GENBANK;
 
73
        } else if (myargs[5].intvalue)  {              /* GenBank locus     */
 
74
                tsip->name = myargs[0].strvalue;
 
75
                sip->choice = SEQID_GENBANK;
 
76
        } else if (myargs[6].intvalue) {               /* PIR accession     */
 
77
                tsip->accession = myargs[0].strvalue;
 
78
                sip->choice = SEQID_PIR;
 
79
        } else if (myargs[7].intvalue) {               /* PIR locus name    */
 
80
                tsip->name = myargs[0].strvalue;
 
81
                sip->choice = SEQID_PIR;
 
82
        }
 
83
 
 
84
        /*
 
85
        ** Initialize, open and otherwise prepare for CD-ROM or Network access.
 
86
        */
 
87
 
 
88
        if ( !EntrezInit("getfasta", FALSE, NULL) ) {
 
89
                Message(MSG_ERROR, "Init failed");
 
90
                return 1;
 
91
        }
 
92
 
 
93
        /*
 
94
        ** Using the SeqEntryPtr structure query the access routines
 
95
        ** and get the internal access number for this SeqEntry
 
96
        **
 
97
        ** If the SeqEntryPtr comes up without a hit, report the error and
 
98
        ** and exit.
 
99
        **
 
100
        ** Otherwise, use the internal access number, uid, and retrieve a
 
101
        ** a sequence entry ASN pointer, sep.  If for some strange reason
 
102
        ** that it is NULL report the error and exit.
 
103
        **
 
104
        ** Write a (nucleic acid) sequence to output in FASTA format
 
105
        **
 
106
        ** Close the ASN file stream, free up memory create which was 
 
107
        ** allocated elsewhere, sep.
 
108
        */
 
109
 
 
110
        if (seqentry) {
 
111
                uid = EntrezFindSeqId(sip);
 
112
                if (! uid)
 
113
                        Message(MSG_ERROR, "Couldn't find uid");
 
114
                else {
 
115
                        sep = EntrezSeqEntryGet(uid, retcode);
 
116
                        if (sep == NULL)
 
117
                                Message(MSG_ERROR, "sep was NULL");
 
118
                        else {
 
119
                                output = FileOpen(myargs[2].strvalue, "w");
 
120
                                SeqEntryToFasta(sep, output, TRUE);  /* nucleic acid output */
 
121
                                FileClose(output);
 
122
                                SeqEntryFree(sep);
 
123
                        }
 
124
                }
 
125
        } else {
 
126
                Message(MSG_ERROR, "Oops");
 
127
        }
 
128
 
 
129
        /*
 
130
        ** Close down the CD-ROM or Network access.
 
131
        ** Return OK to Operating system.
 
132
        */
 
133
 
 
134
        EntrezFini();
 
135
        return 0;
 
136
}
 
137
 
 
138