-rw-r--r-- | src/load/load_asn.c | 173 | ||||
-rw-r--r-- | src/load/load_asn.h | 24 | ||||
-rw-r--r-- | src/load/load_features.c | 167 | ||||
-rw-r--r-- | src/load/load_features.h | 12 |
4 files changed, 376 insertions, 0 deletions
diff --git a/src/load/load_asn.c b/src/load/load_asn.c new file mode 100644 index 0000000..fc27d84 --- a/dev/null +++ b/src/load/load_asn.c | |||
@@ -0,0 +1,173 @@ | |||
1 | #define _GNU_SOURCE | ||
2 | #include "load_asn.h" | ||
3 | #include <string.h> | ||
4 | #include <asn.h> | ||
5 | #include <objgbseq.h> | ||
6 | #include <objsset.h> | ||
7 | #include <sqnutils.h> | ||
8 | |||
9 | void | ||
10 | print_asn (ObjectIdPtr oid, SeqIdPtr id, ValNodePtr descr, SeqAnnotPtr annot) | ||
11 | { | ||
12 | /* | ||
13 | * Print the record identifiers. | ||
14 | */ | ||
15 | printf (" IDENTIFIERS\n"); | ||
16 | printf (" -----------\n"); | ||
17 | while (oid != NULL) | ||
18 | { | ||
19 | printf("%i, %s\n", oid->id, oid->str); | ||
20 | } | ||
21 | while (id != NULL) | ||
22 | { | ||
23 | // printf ("ID: %i\n", id->choice); | ||
24 | |||
25 | char idval[256]; | ||
26 | SeqIdPrint (id, idval, PRINTID_FASTA_SHORT); | ||
27 | printf (" %s\n", idval); | ||
28 | |||
29 | // if (id->choice == SEQID_GI) | ||
30 | //printf ("GI: %i\n", id->data.intvalue); | ||
31 | |||
32 | id = id->next; | ||
33 | } | ||
34 | |||
35 | /* | ||
36 | * Print descriptions. | ||
37 | * [http://www.ncbi.nlm.nih.gov/IEB/ToolBox/SDKDOCS/BIOSEQ.HTML#_Seq-descr:_Describing_the] | ||
38 | */ | ||
39 | printf ("\n DESCRIPTIONS\n"); | ||
40 | printf (" ------------\n"); | ||
41 | while (descr != NULL) | ||
42 | { | ||
43 | switch (descr->choice) | ||
44 | { | ||
45 | case Seq_descr_title: | ||
46 | printf (" TITLE: %s\n", (char*)descr->data.ptrvalue); | ||
47 | break; | ||
48 | case Seq_descr_genbank: | ||
49 | printf (" GENBANK\n"); | ||
50 | break; | ||
51 | case Seq_descr_pub: | ||
52 | printf (" PUB\n"); | ||
53 | break; | ||
54 | case Seq_descr_create_date: | ||
55 | printf (" CREATE DATE\n"); | ||
56 | break; | ||
57 | case Seq_descr_update_date: | ||
58 | printf (" UPDATE DATE\n"); | ||
59 | break; | ||
60 | case Seq_descr_source: | ||
61 | printf (" BIOSOURCE\n"); | ||
62 | break; | ||
63 | case Seq_descr_molinfo: | ||
64 | printf (" MOLINFO\n"); | ||
65 | break; | ||
66 | default: | ||
67 | printf (" DESCRIPTION CHOICE=%i\n", descr->choice); | ||
68 | break; | ||
69 | } | ||
70 | |||
71 | descr = descr->next; | ||
72 | } | ||
73 | |||
74 | /* | ||
75 | * Print annotations. | ||
76 | */ | ||
77 | printf ("\n ANNOTATIONS\n"); | ||
78 | printf (" -----------\n"); | ||
79 | while (annot != NULL) | ||
80 | { | ||
81 | printf (" ANNOTATION: %s, ", annot->name); | ||
82 | if (annot->desc != NULL) { | ||
83 | switch (annot->desc->choice) | ||
84 | { | ||
85 | case Annot_descr_name: | ||
86 | printf (" NAME: %s\n", (char*)annot->desc->data.ptrvalue); | ||
87 | break; | ||
88 | default: | ||
89 | printf (" CHOICE=%i\n", annot->desc->choice); | ||
90 | break; | ||
91 | } | ||
92 | } | ||
93 | else | ||
94 | printf (" NONE\n"); | ||
95 | |||
96 | annot = annot->next; | ||
97 | } | ||
98 | |||
99 | } | ||
100 | |||
101 | /* | ||
102 | * Based on example at | ||
103 | * [http://www.ncbi.nlm.nih.gov/IEB/ToolBox/SDKDOCS/SEQUTIL.HTML]. | ||
104 | */ | ||
105 | void | ||
106 | load_asn (hid_t file_id, const char* file_name) | ||
107 | { | ||
108 | char* asn_file = strdup(file_name); | ||
109 | AsnIoPtr aip = AsnIoOpen (asn_file, "r"); | ||
110 | SeqEntryPtr sep = SeqEntryAsnRead (aip, NULL); | ||
111 | BioseqSetPtr bsetp = 0; | ||
112 | ValNodePtr descr = 0; | ||
113 | SeqAnnotPtr annot = 0; | ||
114 | SeqIdPtr id = 0; | ||
115 | ObjectIdPtr oid = 0; | ||
116 | |||
117 | /* | ||
118 | * Data file statistics. | ||
119 | */ | ||
120 | printf ("NODES: %i\tBIOSEQS: %i\n", ValNodeLen (sep), BioseqCount (sep)); | ||
121 | printf ("\n"); | ||
122 | |||
123 | /* | ||
124 | * This loop needs to be corrected to handle nesting of sets. | ||
125 | */ | ||
126 | |||
127 | while (sep != NULL) | ||
128 | { | ||
129 | bsetp = (BioseqSetPtr) sep->data.ptrvalue; | ||
130 | if (bsetp != NULL) | ||
131 | { | ||
132 | oid = bsetp->id; | ||
133 | id = NULL; | ||
134 | descr = bsetp->descr; | ||
135 | annot = bsetp->annot; | ||
136 | } | ||
137 | |||
138 | printf ("BIOSEQSET\n"); | ||
139 | printf ("\n"); | ||
140 | print_asn (oid, id, descr, annot); | ||
141 | printf ("\n"); | ||
142 | |||
143 | /* | ||
144 | * Process Bioseqs in the set. | ||
145 | */ | ||
146 | SeqEntryPtr sep2 = bsetp->seq_set; | ||
147 | while (sep2 != NULL) | ||
148 | { | ||
149 | BioseqPtr bsp = sep2->data.ptrvalue; | ||
150 | if (bsp != NULL) | ||
151 | { | ||
152 | oid = NULL; | ||
153 | id = bsp->id; | ||
154 | descr = bsp->descr; | ||
155 | annot = bsp->annot; | ||
156 | |||
157 | printf ("BIOSEQ\n"); | ||
158 | printf ("\n"); | ||
159 | print_asn (oid, id, descr, annot); | ||
160 | printf ("\n"); | ||
161 | } | ||
162 | |||
163 | sep2 = sep2->next; | ||
164 | } | ||
165 | |||
166 | sep = sep->next; | ||
167 | } | ||
168 | |||
169 | AsnIoClose (aip); | ||
170 | free (asn_file); | ||
171 | |||
172 | return; | ||
173 | } | ||