summaryrefslogtreecommitdiffstats
path: root/src/load/load_asn.c (plain)
blob: fc27d842a3cd448474b09d6cb510c48364a3c97f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#define _GNU_SOURCE
#include "load_asn.h"
#include <string.h>
#include <asn.h>
#include <objgbseq.h>
#include <objsset.h>
#include <sqnutils.h>

void
print_asn (ObjectIdPtr oid, SeqIdPtr id, ValNodePtr descr, SeqAnnotPtr annot)
{
  /*
   * Print the record identifiers.
   */
  printf ("  IDENTIFIERS\n");
  printf ("  -----------\n");
  while (oid != NULL)
    {
      printf("%i, %s\n", oid->id, oid->str);
    }
  while (id != NULL)
    {
      //      printf ("ID: %i\n", id->choice);

      char idval[256];
      SeqIdPrint (id, idval, PRINTID_FASTA_SHORT);
      printf ("  %s\n", idval);

      //     if (id->choice == SEQID_GI)
      //	printf ("GI: %i\n", id->data.intvalue);

      id = id->next;
    }

  /*
   * Print descriptions.
   * [http://www.ncbi.nlm.nih.gov/IEB/ToolBox/SDKDOCS/BIOSEQ.HTML#_Seq-descr:_Describing_the]
   */
  printf ("\n  DESCRIPTIONS\n");
  printf ("  ------------\n");
  while (descr != NULL)
    {
      switch (descr->choice)
	{
	case Seq_descr_title:
	  printf ("  TITLE: %s\n", (char*)descr->data.ptrvalue);
	  break;
	case Seq_descr_genbank:
	  printf ("  GENBANK\n");
	  break;
	case Seq_descr_pub:
	  printf ("  PUB\n");
	  break;
	case Seq_descr_create_date:
	  printf ("  CREATE DATE\n");
	  break;
	case Seq_descr_update_date:
	  printf ("  UPDATE DATE\n");
	  break;
	case Seq_descr_source:
	  printf ("  BIOSOURCE\n");
	  break;
	case Seq_descr_molinfo:
	  printf ("  MOLINFO\n");
	  break;
	default:
	  printf ("  DESCRIPTION CHOICE=%i\n", descr->choice);
	  break;
	}

      descr = descr->next;
    }

  /*
   * Print annotations.
   */
  printf ("\n  ANNOTATIONS\n");
  printf ("  -----------\n");
  while (annot != NULL)
    {
      printf ("  ANNOTATION: %s, ", annot->name);
      if (annot->desc != NULL) {
	switch (annot->desc->choice)
	  {
	  case Annot_descr_name:
	    printf ("  NAME: %s\n", (char*)annot->desc->data.ptrvalue);
	    break;
	  default:
	    printf ("  CHOICE=%i\n", annot->desc->choice);
	    break;
	  }
      }
      else
	printf ("  NONE\n");

      annot = annot->next;
    }

}

/*
 * Based on example at
 * [http://www.ncbi.nlm.nih.gov/IEB/ToolBox/SDKDOCS/SEQUTIL.HTML].
 */
void
load_asn (hid_t file_id, const char* file_name)
{
  char* asn_file = strdup(file_name);
  AsnIoPtr aip = AsnIoOpen (asn_file, "r");
  SeqEntryPtr sep = SeqEntryAsnRead (aip, NULL);
  BioseqSetPtr bsetp = 0;
  ValNodePtr descr = 0;
  SeqAnnotPtr annot = 0;
  SeqIdPtr id = 0;
  ObjectIdPtr oid = 0;

  /*
   * Data file statistics.
   */
  printf ("NODES: %i\tBIOSEQS: %i\n", ValNodeLen (sep), BioseqCount (sep));
  printf ("\n");

  /*
   * This loop needs to be corrected to handle nesting of sets.
   */

  while (sep != NULL)
    {
      bsetp = (BioseqSetPtr) sep->data.ptrvalue;
      if (bsetp != NULL)
	{
	  oid = bsetp->id;
	  id = NULL;
	  descr = bsetp->descr;
	  annot = bsetp->annot;
	}

      printf ("BIOSEQSET\n");
      printf ("\n");
      print_asn (oid, id, descr, annot);
      printf ("\n");

      /*
       * Process Bioseqs in the set.
       */
      SeqEntryPtr sep2 = bsetp->seq_set;
      while (sep2 != NULL)
	{
	  BioseqPtr bsp = sep2->data.ptrvalue;
	  if (bsp != NULL)
	    {
	      oid = NULL;
	      id = bsp->id;
	      descr = bsp->descr;
	      annot = bsp->annot;

	      printf ("BIOSEQ\n");
	      printf ("\n");
	      print_asn (oid, id, descr, annot);
	      printf ("\n");
	    }

	  sep2 = sep2->next;
	}

      sep = sep->next;
    }

  AsnIoClose (aip);
  free (asn_file);

  return;
}

Valid XHTML 1.0 Strict

Copyright © 2009 Don Pellegrino All Rights Reserved.