~ubuntu-branches/ubuntu/maverick/ncbi-tools6/maverick

« back to all changes in this revision

Viewing changes to demo/getunfin.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
#include <ncbi.h>
 
2
#include <objall.h>
 
3
#include <objsset.h>
 
4
#include <objsub.h>
 
5
#include <objfdef.h>
 
6
#include <sequtil.h>
 
7
#include <edutil.h>
 
8
#include <sqnutils.h>
 
9
#include <explore.h>
 
10
#include <gather.h>
 
11
#include <tofasta.h>
 
12
#include <pmfapi.h>
 
13
 
 
14
static void ProcessAGI (
 
15
  Int4 uid,
 
16
  FILE *fp
 
17
)
 
18
 
 
19
{
 
20
  BioseqPtr    bsp;
 
21
  Int4         gi;
 
22
  SeqHistPtr   hist;
 
23
  MolInfoPtr   mip;
 
24
  SeqDescrPtr  sdp;
 
25
  SeqEntryPtr  sep;
 
26
  SeqIdPtr     sip;
 
27
  ValNode      vn;
 
28
 
 
29
  if (uid == 0 || fp == NULL) return;
 
30
 
 
31
  sep = PubSeqSynchronousQuery (uid, 0, 0);
 
32
  if (sep == NULL) return;
 
33
 
 
34
  MemSet ((Pointer) &vn, 0, sizeof (ValNode));
 
35
  vn.choice = SEQID_GI;
 
36
  vn.data.intvalue = uid;
 
37
 
 
38
  bsp = BioseqFind (&vn);
 
39
  if (bsp == NULL) {
 
40
    sep = SeqEntryFree (sep);
 
41
    return;
 
42
  }
 
43
 
 
44
  AssignIDsInEntity (0, OBJ_SEQENTRY, (Pointer) sep);
 
45
 
 
46
  sdp = GetNextDescriptorUnindexed (bsp, Seq_descr_molinfo, NULL);
 
47
  if (sdp != NULL) {
 
48
    mip = (MolInfoPtr) sdp->data.ptrvalue;
 
49
    if (mip != NULL) {
 
50
      if (mip->tech == MI_TECH_htgs_1 || mip->tech == MI_TECH_htgs_2) {
 
51
        BioseqToFasta (bsp, fp, ISA_na (bsp->mol));
 
52
        sep = SeqEntryFree (sep);
 
53
        return;
 
54
      }
 
55
    }
 
56
  }
 
57
 
 
58
  hist = bsp->hist;
 
59
  if (hist != NULL) {
 
60
    sip = hist->replace_ids;
 
61
    if (sip != NULL) {
 
62
      gi = 0;
 
63
      if (sip->choice == SEQID_GI) {
 
64
        gi = sip->data.intvalue;
 
65
      } else {
 
66
        gi = GetGIForSeqId (sip);
 
67
      }
 
68
      if (gi > 0) {
 
69
        sep = SeqEntryFree (sep);
 
70
        ProcessAGI (gi, fp);
 
71
        return;
 
72
      }
 
73
    }
 
74
  }
 
75
 
 
76
  SeqEntryFree (sep);
 
77
}
 
78
 
 
79
/* Args structure contains command-line arguments */
 
80
 
 
81
#define a_argInputAccn   0
 
82
#define o_argOutputFile  1
 
83
 
 
84
Args myargs [] = {
 
85
  {"Accession", NULL, NULL, NULL,
 
86
    FALSE, 'a', ARG_STRING, 0.0, 0, NULL},
 
87
  {"Output File Name", "stdout", NULL, NULL,
 
88
    FALSE, 'o', ARG_FILE_OUT, 0.0, 0, NULL},
 
89
};
 
90
 
 
91
Int2 Main (void)
 
92
 
 
93
{
 
94
  Char      ch;
 
95
  CharPtr   accn;
 
96
  FILE      *fp;
 
97
  Boolean   isgi;
 
98
  SeqIdPtr  sip;
 
99
  CharPtr   ptr;
 
100
  Int4      uid;
 
101
  long      val;
 
102
 
 
103
  /* standard setup */
 
104
 
 
105
  ErrSetFatalLevel (SEV_MAX);
 
106
  ErrClearOptFlags (EO_SHOW_USERSTR);
 
107
  UseLocalAsnloadDataAndErrMsg ();
 
108
  ErrPathReset ();
 
109
 
 
110
  if (! AllObjLoad ()) {
 
111
    Message (MSG_FATAL, "AllObjLoad failed");
 
112
    return 1;
 
113
  }
 
114
  if (! SubmitAsnLoad ()) {
 
115
    Message (MSG_FATAL, "SubmitAsnLoad failed");
 
116
    return 1;
 
117
  }
 
118
  if (! FeatDefSetLoad ()) {
 
119
    Message (MSG_FATAL, "FeatDefSetLoad failed");
 
120
    return 1;
 
121
  }
 
122
  if (! SeqCodeSetLoad ()) {
 
123
    Message (MSG_FATAL, "SeqCodeSetLoad failed");
 
124
    return 1;
 
125
  }
 
126
  if (! GeneticCodeTableLoad ()) {
 
127
    Message (MSG_FATAL, "GeneticCodeTableLoad failed");
 
128
    return 1;
 
129
  }
 
130
 
 
131
  /* process command line arguments */
 
132
 
 
133
  if (! GetArgs ("getunfin", sizeof (myargs) / sizeof (Args), myargs)) {
 
134
    return 0;
 
135
  }
 
136
 
 
137
  accn = myargs [a_argInputAccn].strvalue;
 
138
  if (StringHasNoText (accn)) {
 
139
    Message (MSG_FATAL, "Must have accession number");
 
140
    return 1;
 
141
  }
 
142
 
 
143
  fp = FileOpen (myargs [o_argOutputFile].strvalue, "w");
 
144
  if (fp == NULL) {
 
145
    Message (MSG_FATAL, "FileOpen failed for output file");
 
146
    return 1;
 
147
  }
 
148
 
 
149
  PubSeqFetchEnable ();
 
150
 
 
151
  ptr = accn;
 
152
  ch = *ptr;
 
153
  isgi = TRUE;
 
154
 
 
155
  while (ch != '\0') {
 
156
    if (! IS_DIGIT (ch)) {
 
157
      isgi = FALSE;
 
158
    }
 
159
    ptr++;
 
160
    ch = *ptr;
 
161
  }
 
162
 
 
163
  if (isgi) {
 
164
    sscanf (accn, "%ld", &val);
 
165
    uid = (Int4) val;
 
166
  } else {
 
167
    sip = SeqIdFromAccessionDotVersion (accn);
 
168
    uid = GetGIForSeqId (sip);
 
169
    SeqIdFree (sip);
 
170
  }
 
171
 
 
172
  ProcessAGI (uid, fp);
 
173
 
 
174
  FileClose (fp);
 
175
 
 
176
  PubSeqFetchDisable ();
 
177
 
 
178
  return 0;
 
179
}
 
180