~ubuntu-branches/ubuntu/natty/ncbi-tools6/natty

« back to all changes in this revision

Viewing changes to demo/sugint.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2009-03-19 10:17:26 UTC
  • mfrom: (1.3.1 upstream) (5.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090319101726-wjuj7ajnq0w5a0mg
Tags: 6.1.20090301-1
* New upstream release; uploading to unstable now that lenny is out.
* debian/lib{ncbi6,vibrant6a}.symbols: update accordingly.
* doc/man/*.1: update accordingly as well.
* debian/control: place lib*-dbg in the new debug section, per the
  current override file.
* debian/control: declare compliance with Policy 3.8.1 (no changes needed).
* api/aliread.c: merge in fix (from 6.1.20080302-4) to undefined use of
  sprintf caught by Kees Cook's scan.
* debian/watch: belatedly update regex to recognize releases like the
  previous one ([6.1.]20081116a).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*   sugint.c
 
2
* ===========================================================================
 
3
*
 
4
*                            PUBLIC DOMAIN NOTICE
 
5
*            National Center for Biotechnology Information (NCBI)
 
6
*
 
7
*  This software/database is a "United States Government Work" under the
 
8
*  terms of the United States Copyright Act.  It was written as part of
 
9
*  the author's official duties as a United States Government employee and
 
10
*  thus cannot be copyrighted.  This software/database is freely available
 
11
*  to the public for use. The National Library of Medicine and the U.S.
 
12
*  Government do not place any restriction on its use or reproduction.
 
13
*  We would, however, appreciate having the NCBI and the author cited in
 
14
*  any work or product based on this material
 
15
*
 
16
*  Although all reasonable efforts have been taken to ensure the accuracy
 
17
*  and reliability of the software and data, the NLM and the U.S.
 
18
*  Government do not and cannot warrant the performance or results that
 
19
*  may be obtained by using this software or data. The NLM and the U.S.
 
20
*  Government disclaim all warranties, express or implied, including
 
21
*  warranties of performance, merchantability or fitness for any particular
 
22
*  purpose.
 
23
*
 
24
* ===========================================================================
 
25
*
 
26
* File Name:  sugint.c
 
27
*
 
28
* Author:  Jonathan Kans
 
29
*
 
30
* Version Creation Date:   10/31/08
 
31
*
 
32
* $Revision: 1.1 $
 
33
*
 
34
* File Description:
 
35
*
 
36
* Modifications:  
 
37
* --------------------------------------------------------------------------
 
38
* Date     Name        Description of modification
 
39
* -------  ----------  -----------------------------------------------------
 
40
*
 
41
* ==========================================================================
 
42
*/
 
43
 
 
44
#include <ncbi.h>
 
45
#include <objall.h>
 
46
#include <objsset.h>
 
47
#include <objsub.h>
 
48
#include <objfdef.h>
 
49
#include <seqport.h>
 
50
#include <sequtil.h>
 
51
#include <sqnutils.h>
 
52
#include <subutil.h>
 
53
#include <tofasta.h>
 
54
#include <gather.h>
 
55
#include <explore.h>
 
56
#include <suggslp.h>
 
57
 
 
58
static SeqEntryPtr ReadSep (
 
59
  FILE *fp,
 
60
  Boolean forceNuc,
 
61
  Boolean forcePrt
 
62
)
 
63
 
 
64
{
 
65
  Pointer  dataptr;
 
66
  Uint2    datatype, entityID;
 
67
 
 
68
  dataptr = ReadAsnFastaOrFlatFile (fp, &datatype, NULL, forceNuc, forcePrt, TRUE, FALSE);
 
69
  if (dataptr == NULL) return NULL;
 
70
  entityID = ObjMgrRegister (datatype, dataptr);
 
71
  return GetTopSeqEntryForEntityID (entityID);
 
72
}
 
73
 
 
74
static void ProcessSuggest (
 
75
  FILE *nfp,
 
76
  FILE *pfp,
 
77
  AsnIoPtr ofp,
 
78
  Int2 gencode
 
79
)
 
80
 
 
81
{
 
82
  BioseqPtr    nbsp = NULL, pbsp = NULL;
 
83
  SeqEntryPtr  nsep, psep, sep;
 
84
  SeqAnnotPtr  sap;
 
85
  SeqFeatPtr   sfp;
 
86
  SeqLocPtr    slp;
 
87
 
 
88
  nsep = ReadSep (nfp, TRUE, FALSE);
 
89
  psep = ReadSep (pfp, FALSE, TRUE);
 
90
 
 
91
  if (nsep != NULL && psep != NULL) {
 
92
    sep = FindNthBioseq (nsep, 1);
 
93
    if (sep != NULL && IS_Bioseq (sep)) {
 
94
      nbsp = (BioseqPtr) sep->data.ptrvalue;
 
95
    }
 
96
    sep = FindNthBioseq (psep, 1);
 
97
    if (sep != NULL && IS_Bioseq (sep)) {
 
98
      pbsp = (BioseqPtr) sep->data.ptrvalue;
 
99
    }
 
100
    if (nbsp != NULL && pbsp != NULL) {
 
101
      if (ISA_na (nbsp->mol) && ISA_aa (pbsp->mol)) {
 
102
        sap = SuggestCodingRegion (nbsp, pbsp, gencode);
 
103
 
 
104
        if (sap != NULL && sap->type == 1) {
 
105
          sfp = (SeqFeatPtr) sap->data;
 
106
          if (sfp != NULL && sfp->data.choice == SEQFEAT_CDREGION) {
 
107
            slp = sfp->location;
 
108
            if (slp != NULL) {
 
109
              SeqLocAsnWrite (slp,  ofp, NULL);
 
110
            }
 
111
          }
 
112
        }
 
113
 
 
114
        SeqAnnotFree (sap);
 
115
      }
 
116
    }
 
117
  }
 
118
 
 
119
  SeqEntryFree (nsep);
 
120
  SeqEntryFree (psep);
 
121
}
 
122
 
 
123
#define n_argNucInputFile  0
 
124
#define p_argPrtInputFile  1
 
125
#define o_argOutputFile    2
 
126
#define g_argGeneticCode   3
 
127
 
 
128
Args myargs [] = {
 
129
  {"Nucleotide Input File", NULL, NULL, NULL,
 
130
    FALSE, 'n', ARG_FILE_IN, 0.0, 0, NULL},
 
131
  {"Protein Input File", NULL, NULL, NULL,
 
132
    FALSE, 'p', ARG_FILE_IN, 0.0, 0, NULL},
 
133
  {"Output File", NULL, NULL, NULL,
 
134
    FALSE, 'o', ARG_FILE_OUT, 0.0, 0, NULL},
 
135
  {"Genetic Code", "1", "0", "20",
 
136
    TRUE, 'g', ARG_INT, 0.0, 0, NULL},
 
137
};
 
138
 
 
139
Int2 Main (void)
 
140
 
 
141
{
 
142
  Int2      gencode;
 
143
  FILE      *nfp, *pfp;
 
144
  AsnIoPtr  ofp;
 
145
  CharPtr   nucfile, prtfile, outfile;
 
146
 
 
147
  /* standard setup */
 
148
 
 
149
  ErrSetFatalLevel (SEV_MAX);
 
150
  ErrClearOptFlags (EO_SHOW_USERSTR);
 
151
  UseLocalAsnloadDataAndErrMsg ();
 
152
  ErrPathReset ();
 
153
 
 
154
  /* finish resolving internal connections in ASN.1 parse tables */
 
155
 
 
156
  if (! AllObjLoad ()) {
 
157
    Message (MSG_FATAL, "AllObjLoad failed");
 
158
    return 1;
 
159
  }
 
160
  if (! SubmitAsnLoad ()) {
 
161
    Message (MSG_FATAL, "SubmitAsnLoad failed");
 
162
    return 1;
 
163
  }
 
164
  if (! FeatDefSetLoad ()) {
 
165
    Message (MSG_FATAL, "FeatDefSetLoad failed");
 
166
    return 1;
 
167
  }
 
168
  if (! SeqCodeSetLoad ()) {
 
169
    Message (MSG_FATAL, "SeqCodeSetLoad failed");
 
170
    return 1;
 
171
  }
 
172
  if (! GeneticCodeTableLoad ()) {
 
173
    Message (MSG_FATAL, "GeneticCodeTableLoad failed");
 
174
    return 1;
 
175
  }
 
176
 
 
177
  /* process command line arguments */
 
178
 
 
179
  if (! GetArgs ("sugint", sizeof (myargs) / sizeof (Args), myargs)) {
 
180
    return 0;
 
181
  }
 
182
 
 
183
  nucfile = (CharPtr) myargs [n_argNucInputFile].strvalue;
 
184
  prtfile = (CharPtr) myargs [p_argPrtInputFile].strvalue;
 
185
  outfile = (CharPtr) myargs [o_argOutputFile].strvalue;
 
186
  gencode = (Int2) myargs [g_argGeneticCode].intvalue;
 
187
 
 
188
  nfp = FileOpen (nucfile, "r");
 
189
  if (nfp == NULL) {
 
190
    Message (MSG_FATAL, "Unable to open nucleotide input file");
 
191
    return 1;
 
192
  }
 
193
 
 
194
  pfp = FileOpen (prtfile, "r");
 
195
  if (pfp == NULL) {
 
196
    Message (MSG_FATAL, "Unable to open protein input file");
 
197
    return 1;
 
198
  }
 
199
 
 
200
  ofp = AsnIoOpen (outfile, "w");
 
201
  if (ofp == NULL) {
 
202
    Message (MSG_FATAL, "Unable to open output file");
 
203
    return 1;
 
204
  }
 
205
 
 
206
  ProcessSuggest (nfp, pfp, ofp, gencode);
 
207
 
 
208
  AsnIoClose (ofp);
 
209
  FileClose (pfp);
 
210
  FileClose (nfp);
 
211
 
 
212
  return 0;
 
213
}
 
214