summaryrefslogtreecommitdiffstats
Unidiff
-rw-r--r--src/load/load_blast_scores.c119
-rw-r--r--src/load/load_blast_scores.h11
-rw-r--r--src/model/blast_scores_data.h21
-rw-r--r--src/model/blast_scores_data_init.c43
-rw-r--r--src/model/blast_scores_data_init.h14
5 files changed, 208 insertions, 0 deletions
diff --git a/src/load/load_blast_scores.c b/src/load/load_blast_scores.c
new file mode 100644
index 0000000..42e6bd9
--- a/dev/null
+++ b/src/load/load_blast_scores.c
@@ -0,0 +1,119 @@
1#include "error/check_error.h"
2#include "error/check_h5_error.h"
3#include "model/blast_scores_data.h"
4#include "model/blast_scores_data_init.h"
5#include "load_blast_scores.h"
6#include <hdf5_hl.h>
7#include <string.h>
8#include <stdlib.h>
9
10void
11load_blast_scores (hid_t file_id, const char *file_name)
12{
13 size_t dst_size;
14 size_t dst_offset[BLAST_SCORES_DATA_FIELD_NUM];
15 size_t dst_sizes[BLAST_SCORES_DATA_FIELD_NUM];
16 hid_t field_type[BLAST_SCORES_DATA_FIELD_NUM];
17
18 blast_scores_data_init (&dst_size, dst_offset, dst_sizes, field_type);
19
20 hsize_t chunk_size = 10;
21 int *fill_data = NULL;
22 int compress = 0;
23
24 blast_scores_data p_data[1000];
25 FILE *dat = fopen (file_name, "r");
26 if (dat == NULL)
27 check_error (__FILE__, __LINE__);
28 char *line = NULL;
29 size_t len = 0;
30 int current_line = 0;
31 int i = -1;
32
33 while (getline (&line, &len, dat) != -1)
34 {
35 current_line++;
36 i++;
37
38 char *running = strdup (line);
39 char *token = NULL;
40
41 token = strsep (&running, ",");
42 p_data[i].source_gi = atoi (&token[4]);
43
44 token = strsep (&running, ",");
45 p_data[i].source_start = atoi (token);
46
47 token = strsep (&running, ",");
48 p_data[i].source_end = atoi (token);
49
50 token = strsep (&running, ",");
51 p_data[i].target_gi = atoi (&token[4]);
52
53 token = strsep (&running, ",");
54 p_data[i].target_start = atoi (token);
55
56 token = strsep (&running, ",");
57 p_data[i].target_end = atoi (token);
58
59 token = strsep (&running, ",");
60 p_data[i].score = atoi (token);
61
62 token = strsep (&running, ",");
63 p_data[i].bit_score = strtod (token, NULL);
64
65 token = strsep (&running, ",");
66 p_data[i].evalue = strtod (token, NULL);
67
68 if (current_line == 1)
69 {
70
71 const char *blast_scores_data_field_names[BLAST_SCORES_DATA_FIELD_NUM] =
72 BLAST_SCORES_DATA_FIELD_NAMES;
73
74 herr_t status = H5TBmake_table ("blast", file_id,
75 "blast",
76 BLAST_SCORES_DATA_FIELD_NUM, 1,
77 dst_size,
78 blast_scores_data_field_names,
79 dst_offset, field_type,
80 chunk_size, fill_data,
81 compress,
82 &p_data);
83
84 if (status < 0)
85 check_h5_error (__FILE__, __LINE__);
86
87 }
88
89 if ((i % 1000 == 0) && (i > 0))
90 {
91
92 herr_t status =
93 H5TBappend_records (file_id, "blast", 1000,
94 dst_size, dst_offset, dst_sizes,
95 &p_data[0]);
96 if(status < 0)
97 check_h5_error (__FILE__, __LINE__);
98
99 status = H5Fflush (file_id, H5F_SCOPE_GLOBAL);
100 if (status < 0)
101 check_h5_error (__FILE__, __LINE__);
102
103 printf ("Processed %i of records.\n", current_line);
104
105 i = -1;
106 }
107
108 if (running)
109 free (running);
110
111 } // End for each line of the input file.
112
113 if (line)
114 free (line);
115
116 fclose (dat);
117
118 return;
119}

Valid XHTML 1.0 Strict

Copyright © 2009 Don Pellegrino All Rights Reserved.