#include "error/check_error.h" #include "error/check_h5_error.h" #include "load_influenza_faa.h" #include "model/sequence_data.h" #include "model/sequence_data_init.h" #include #include #include void load_influenza_faa (hid_t file_id) { size_t dst_size; size_t dst_offset[SEQUENCE_DATA_FIELD_NUM]; size_t dst_sizes[SEQUENCE_DATA_FIELD_NUM]; hid_t field_type[SEQUENCE_DATA_FIELD_NUM]; sequence_data_init (&dst_size, dst_offset, dst_sizes, field_type); hsize_t chunk_size = 10; int *fill_data = NULL; int compress = 0; sequence_data p_data; FILE *dat = fopen ("/home/don/exp004/genomes/INFLUENZA/influenza.faa", "r"); if (dat == NULL) check_error (__FILE__, __LINE__); char *line = NULL; size_t len = 0; int current_line = 0; while (getline (&line, &len, dat) != -1) { current_line++; // Header line. if (line[0] == '>') { char *running = strdup (line); char *token = NULL; // Eat the ">gi". strsep (&running, "|"); // GI value. token = strsep (&running, "|"); p_data.gi = atoi (token); // Eat the "gb" strsep (&running, "|"); // GB value. strncpy (p_data.gb, strsep(&running, "|"), sizeof (p_data.gb)); // Description value. strncpy (p_data.description, strsep (&running, "|"), sizeof (p_data.description)); const char* sequence_data_field_names[SEQUENCE_DATA_FIELD_NUM] = SEQUENCE_DATA_FIELD_NAMES; if (current_line == 1) { herr_t status = H5TBmake_table ("influenza.faa", file_id, "influenza.faa", SEQUENCE_DATA_FIELD_NUM, 1, dst_size, sequence_data_field_names, dst_offset, field_type, chunk_size, fill_data, compress, &p_data); if (status < 0) check_h5_error (status, __FILE__, __LINE__); } else { herr_t status = H5TBappend_records (file_id, "influenza.faa", 1, dst_size, dst_offset, dst_sizes, &p_data); if (status < 0) check_h5_error (status, __FILE__, __LINE__); } if (running) free (running); } } if (line) free (line); fclose (dat); return; }