Exemplo n.º 1
0
GT_INLINE void gt_sam_attribute_func_params_set_sam_flags(
    gt_sam_attribute_func_params* const func_params,const bool not_passing_QC,const bool PCR_duplicate) {
  GT_NULL_CHECK(func_params);
  GT_NULL_CHECK(func_params->alignment_info);
  func_params->alignment_info->not_passing_QC = not_passing_QC;
  func_params->alignment_info->PCR_duplicate = PCR_duplicate;
}
Exemplo n.º 2
0
GT_INLINE void gt_sam_attribute_set_fvalue(gt_sam_attribute* const sam_attribute,char* const tag,char type_id,const float value) {
  GT_NULL_CHECK(sam_attribute); // TODO: type checking of i,Z,etc
  GT_NULL_CHECK(tag);
  GT_ATTRIBUTE_SAM_COPY_TAG(sam_attribute,tag);
  sam_attribute->attribute_type = SAM_ATTR_FLOAT_VALUE;
  sam_attribute->type_id = type_id;
  sam_attribute->f_value = value;
}
Exemplo n.º 3
0
GT_INLINE void gt_sam_attributes_add_sfunc(gt_sam_attributes* const sam_attributes,char* const tag,char type_id,gt_status (*s_func)(gt_sam_attribute_func_params*)){
  GT_SAM_ATTRIBUTES_CHECK(sam_attributes);
  GT_NULL_CHECK(tag);
  GT_NULL_CHECK(s_func);
  gt_sam_attribute* const sam_attribute = gt_alloc(gt_sam_attribute);
  gt_sam_attribute_set_sfunc(sam_attribute,tag,type_id,s_func);
  gt_sam_attributes_add_attribute(sam_attributes,sam_attribute);
}
Exemplo n.º 4
0
GT_INLINE void gt_sam_attribute_set_sfunc(gt_sam_attribute* const sam_attribute,char* const tag,char type_id,gt_status (*s_func)(gt_sam_attribute_func_params*)) {
  GT_NULL_CHECK(sam_attribute); // TODO: type checking of i,Z,etc
  GT_NULL_CHECK(tag);
  GT_NULL_CHECK(s_func);
  GT_ATTRIBUTE_SAM_COPY_TAG(sam_attribute,tag);
  sam_attribute->attribute_type = SAM_ATTR_STRING_FUNC;
  sam_attribute->type_id = type_id;
  sam_attribute->s_func = s_func;
}
Exemplo n.º 5
0
GT_INLINE void gt_sam_attribute_set_svalue(gt_sam_attribute* const sam_attribute,char* const tag,char type_id,gt_string* const string) {
  GT_NULL_CHECK(sam_attribute); // TODO: type checking of i,Z,etc
  GT_NULL_CHECK(tag);
  GT_STRING_CHECK(string);
  GT_ATTRIBUTE_SAM_COPY_TAG(sam_attribute,tag);
  sam_attribute->attribute_type = SAM_ATTR_STRING_VALUE;
  sam_attribute->type_id = type_id;
  sam_attribute->s_value = string;
}
Exemplo n.º 6
0
GT_INLINE void gt_sam_attributes_add_fvalue(gt_sam_attributes* const sam_attributes,char* const tag,char type_id,const float value){
  GT_SAM_ATTRIBUTES_CHECK(sam_attributes);
  GT_NULL_CHECK(tag);
  gt_sam_attribute* const sam_attribute = gt_alloc(gt_sam_attribute);
  gt_sam_attribute_set_fvalue(sam_attribute,tag,type_id,value);
  gt_sam_attributes_add_attribute(sam_attributes,sam_attribute);
}
Exemplo n.º 7
0
GT_INLINE void gt_generic_printer_attributes_delete(gt_generic_printer_attributes* const attributes) {
  GT_NULL_CHECK(attributes);
  if (attributes->output_sam_attributes!=NULL) gt_output_sam_attributes_delete(attributes->output_sam_attributes);
  if (attributes->output_fasta_attributes!=NULL) gt_output_fasta_attributes_delete(attributes->output_fasta_attributes);
  if (attributes->output_map_attributes!=NULL) gt_output_map_attributes_delete(attributes->output_map_attributes);
  gt_free(attributes);
}
Exemplo n.º 8
0
/*
 * Basic I/O functions
 */
gt_input_file* gt_input_stream_open(FILE* stream) {
    GT_NULL_CHECK(stream);
    // Allocate handler
    gt_input_file* input_file = gt_alloc(gt_input_file);
    // Input file
    input_file->file_name = GT_STREAM_FILE_NAME;
    input_file->file_type = STREAM;
    input_file->file = stream;
    input_file->fildes = -1;
    input_file->eof = feof(stream);
    input_file->file_size = UINT64_MAX;
    input_file->file_format = FILE_FORMAT_UNKNOWN;
    gt_cond_fatal_error(pthread_mutex_init(&input_file->input_mutex, NULL),SYS_MUTEX_INIT);
    // Auxiliary Buffer (for synch purposes)
    input_file->file_buffer = gt_malloc(GT_INPUT_BUFFER_SIZE);
    input_file->buffer_size = 0;
    input_file->buffer_begin = 0;
    input_file->buffer_pos = 0;
    input_file->global_pos = 0;
    input_file->processed_lines = 0;
    // ID generator
    input_file->processed_id = 0;
    // Detect file format
    gt_input_file_detect_file_format(input_file);
    return input_file;
}
Exemplo n.º 9
0
GT_INLINE void gt_sam_attributes_add_svalue(gt_sam_attributes* const sam_attributes,char* const tag,char type_id,gt_string* const string){
  GT_SAM_ATTRIBUTES_CHECK(sam_attributes);
  GT_NULL_CHECK(tag);
  GT_STRING_CHECK(string);
  gt_sam_attribute* const sam_attribute = gt_alloc(gt_sam_attribute);
  gt_sam_attribute_set_svalue(sam_attribute,tag,type_id,string);
  gt_sam_attributes_add_attribute(sam_attributes,sam_attribute);
}
Exemplo n.º 10
0
GT_INLINE void gt_sam_attribute_func_params_delete(gt_sam_attribute_func_params* const func_params) {
  GT_NULL_CHECK(func_params);
  /* String (gt_string) buffer */
  if (func_params->return_s!=NULL) gt_string_delete(func_params->return_s);
  /* Attributes */
  gt_attributes_delete(func_params->attributes);
  gt_free(func_params);
}
Exemplo n.º 11
0
GT_INLINE gt_status gt_qualities_deduce_offset(gt_string* const qualities,gt_qualities_offset_t* qualities_offset_type) {
  GT_STRING_CHECK(qualities);
  GT_NULL_CHECK(qualities_offset_type);
  uint8_t min, max;
  gt_qualities_get_min__max(qualities,&min,&max);
  if (min >= 64) {*qualities_offset_type=GT_QUALS_OFFSET_64; return GT_STATUS_OK;}
  if (min >= 33) {*qualities_offset_type=GT_QUALS_OFFSET_33; return GT_STATUS_OK;}
  return GT_STATUS_FAIL;
}
Exemplo n.º 12
0
GT_INLINE void gt_sam_attribute_func_params_clear(gt_sam_attribute_func_params* const func_params) {
  GT_NULL_CHECK(func_params);
  /* Return Values */
  if (func_params->return_s!=NULL) gt_string_clear(func_params->return_s);
  /* Sequence Archive */
  func_params->sequence_archive = NULL;
  /* Template/Alignment source */
  func_params->alignment_info=NULL;
  /* Placeholder Vector */
  func_params->mmap_placeholder = NULL;
}
Exemplo n.º 13
0
/*
 * Constructors
 */
GT_INLINE gt_stats_vector* gt_stats_vector_customed_range_new(
    const uint64_t* const customed_range_values,const uint64_t num_values,
    const uint64_t out_of_range_bucket_size) {
  GT_NULL_CHECK(customed_range_values);
  gt_cond_fatal_error(num_values>=2,INVALID_VALUE,"'num_values'",">2");
  GT_ZERO_CHECK(out_of_range_bucket_size);
  // Allocate handler
  gt_stats_vector* const stats_vector = gt_alloc(gt_stats_vector);
  // Init
  stats_vector->type = GT_STATS_VECTOR_CUSTOMED_RANGE;
  stats_vector->counters = gt_calloc(num_values,uint64_t,true);
  // Customed range vetor
  GT_NULL_CHECK(customed_range_values);
  stats_vector->customed_range_values = customed_range_values;
  stats_vector->num_values = num_values-1;
  stats_vector->out_of_range_bucket_size = out_of_range_bucket_size;
  stats_vector->out_values = gt_ihash_new();
  // Nested
  stats_vector->template_vector = NULL;
  stats_vector->nested_vectors = NULL;
  return stats_vector;
}
Exemplo n.º 14
0
/*
 * Compact DNA String Sequence Iterator
 */
GT_INLINE void gt_cdna_string_new_iterator(
    gt_compact_dna_string* const cdna_string,const uint64_t position,gt_string_traversal const direction,
    gt_compact_dna_sequence_iterator* const cdna_string_iterator) {
  GT_COMPACT_DNA_STRING_CHECK(cdna_string);
  GT_NULL_CHECK(cdna_string_iterator);
  // Initialize the iterator
  cdna_string_iterator->cdna_string = cdna_string;
  // Seek to the current position
  if (position<cdna_string->length) {
    gt_cdna_string_iterator_seek(cdna_string_iterator,position,direction);
  } else {
    cdna_string_iterator->current_pos=cdna_string->length;
  }
}
Exemplo n.º 15
0
/*
 * Buffered map file handlers
 */
gt_buffered_input_file* gt_buffered_input_file_new(gt_input_file* const input_file) {
  GT_NULL_CHECK(input_file);
  gt_buffered_input_file* buffered_input_file = gt_alloc(gt_buffered_input_file);
  /* Input file */
  buffered_input_file->input_file = input_file;
  /* Block buffer and cursors */
  buffered_input_file->block_id = UINT32_MAX;
  buffered_input_file->block_buffer = gt_vector_new(GT_BMI_BUFFER_SIZE,sizeof(uint8_t));
  buffered_input_file->cursor = (char*) gt_vector_get_mem(buffered_input_file->block_buffer,uint8_t);
  buffered_input_file->current_line_num = UINT64_MAX;
  /* Attached output buffer */
  buffered_input_file->attached_buffered_output_file = gt_vector_new(2,sizeof(gt_buffered_output_file*));
  return buffered_input_file;
}
Exemplo n.º 16
0
GT_INLINE void gt_cdna_string_iterator_seek(
    gt_compact_dna_sequence_iterator* const cdna_string_iterator,
    const uint64_t position,gt_string_traversal const direction) {
  GT_NULL_CHECK(cdna_string_iterator);
  GT_NULL_CHECK(cdna_string_iterator->cdna_string);
  register gt_compact_dna_string* const cdna_string = cdna_string_iterator->cdna_string;
  GT_COMPACT_DNA_STRING_POSITION_CHECK(cdna_string,position);
  // Set the iterator
  cdna_string_iterator->current_pos = position;
  cdna_string_iterator->current_pos_mod = position%GT_CDNA_BLOCK_CHARS;
  cdna_string_iterator->direction = direction;
  // Set the current bitmap and seek to current position
  register uint64_t block_num, block_pos;
  GT_CDNA_GET_BLOCK_POS(position,block_num,block_pos);
  cdna_string_iterator->current_bitmap = GT_CDNA_GET_MEM_BLOCK(cdna_string->bitmaps,block_num);
  GT_CDNA_GET_BLOCKS(cdna_string->bitmaps,block_num,cdna_string_iterator->bm_0,cdna_string_iterator->bm_1,cdna_string_iterator->bm_2);
  if (cdna_string_iterator->direction==GT_ST_FORWARD) {
    GT_CDNA_SHIFT_FORWARD_CHARS(block_pos,
        cdna_string_iterator->bm_0,cdna_string_iterator->bm_1,cdna_string_iterator->bm_2);
  } else if (block_pos < GT_CDNA_BLOCK_CHARS-1) { // GT_ST_BACKWARD
    GT_CDNA_SHIFT_BACKWARD_CHARS((GT_CDNA_BLOCK_CHARS-1-block_pos),
        cdna_string_iterator->bm_0,cdna_string_iterator->bm_1,cdna_string_iterator->bm_2);
  }
}
Exemplo n.º 17
0
GT_INLINE void gt_generic_printer_attributes_set_format(
    gt_generic_printer_attributes* const attributes,const gt_file_format file_format) {
  GT_NULL_CHECK(attributes);
  switch (file_format) {
    case SAM:
      attributes->output_format = SAM;
      attributes->output_sam_attributes = gt_output_sam_attributes_new();
      break;
    case FASTA:
      attributes->output_format = FASTA;
      attributes->output_fasta_attributes = gt_output_fasta_attributes_new();
      break;
    case MAP:
    default:
      attributes->output_format = MAP;
      attributes->output_map_attributes = gt_output_map_attributes_new();
      break;
  }
}
Exemplo n.º 18
0
GT_INLINE gt_status gt_output_generic_gprint_alignment(gt_generic_printer* const gprinter,
    gt_alignment* const alignment,gt_generic_printer_attributes* const attributes) {
  GT_GENERIC_PRINTER_CHECK(gprinter);
  GT_ALIGNMENT_CHECK(alignment);
  GT_NULL_CHECK(attributes);
  switch (attributes->output_format) {
    case SAM:
      gt_output_sam_gprint_alignment(gprinter,alignment,attributes->output_sam_attributes);
      break;
    case FASTA:
      gt_output_fasta_gprint_alignment(gprinter,alignment,attributes->output_fasta_attributes);
      break;
    case MAP:
    default:
      gt_output_map_gprint_alignment(gprinter,alignment,attributes->output_map_attributes);
      break;
  }
  return 0;
}
Exemplo n.º 19
0
GT_INLINE bool gt_stats_vector_iterator_next(gt_stats_vector_iterator* const stats_vector_iterator) {
  GT_NULL_CHECK(stats_vector_iterator);
  GT_STATS_VECTOR_CHECK(stats_vector_iterator->stats_vector);
}
Exemplo n.º 20
0
GT_INLINE void gt_stats_vector_iterator_delete(gt_stats_vector_iterator* const stats_vector_iterator) {
  GT_NULL_CHECK(stats_vector_iterator);
  GT_STATS_VECTOR_CHECK(stats_vector_iterator->stats_vector);

}
Exemplo n.º 21
0
GT_INLINE void gt_dna_read_set_qualities(gt_dna_read* read,char* const text) {
  GT_DNA_READ_CHECK(read);
  GT_NULL_CHECK(text);
  gt_string_set_string(read->qualities,text);
}
Exemplo n.º 22
0
GT_INLINE uint64_t gt_buffered_input_file_get_cursor_pos(gt_buffered_input_file* const buffered_input_file) {
  GT_BUFFERED_INPUT_FILE_CHECK(buffered_input_file);
  GT_NULL_CHECK(buffered_input_file->cursor);
  return buffered_input_file->cursor-gt_vector_get_mem(buffered_input_file->block_buffer,char);
}
Exemplo n.º 23
0
GT_INLINE void gt_sam_attributes_add_attribute(gt_sam_attributes* const sam_attributes,gt_sam_attribute* const sam_attribute) {
  GT_SAM_ATTRIBUTES_CHECK(sam_attributes);
  GT_NULL_CHECK(sam_attribute);
  GT_NULL_CHECK(sam_attribute->tag);
  gt_shash_insert(sam_attributes,sam_attribute->tag,sam_attribute,gt_sam_attribute);
}
Exemplo n.º 24
0
GT_INLINE void gt_sam_attribute_func_params_set_alignment_info(gt_sam_attribute_func_params* const func_params,gt_map_placeholder* const map_placeholder) {
  GT_NULL_CHECK(func_params);
  func_params->alignment_info = map_placeholder;
}
Exemplo n.º 25
0
GT_INLINE gt_map_placeholder* gt_sam_attribute_func_params_get_alignment_info(gt_sam_attribute_func_params* const func_params) {
  GT_NULL_CHECK(func_params);
  return func_params->alignment_info;
}
Exemplo n.º 26
0
gt_input_file* gt_input_file_open(char* const file_name,const bool mmap_file) {
    GT_NULL_CHECK(file_name);
    // Allocate handler
    gt_input_file* input_file = gt_alloc(gt_input_file);
    // Input file
    struct stat stat_info;
    unsigned char tbuf[4];
    int i;
    gt_cond_fatal_error(stat(file_name,&stat_info)==-1,FILE_STAT,file_name);
    input_file->file_name = file_name;
    input_file->file_size = stat_info.st_size;
    input_file->eof = (input_file->file_size==0);
    input_file->file_format = FILE_FORMAT_UNKNOWN;
    gt_cond_fatal_error(pthread_mutex_init(&input_file->input_mutex,NULL),SYS_MUTEX_INIT);
    if (mmap_file) {
        input_file->file = NULL;
        input_file->fildes = open(file_name,O_RDONLY,0); // TODO: O_NOATIME condCompl (Thanks Jordi Camps)
        gt_cond_fatal_error(input_file->fildes==-1,FILE_OPEN,file_name);
        input_file->file_buffer =
            (uint8_t*) mmap(0,input_file->file_size,PROT_READ,MAP_PRIVATE,input_file->fildes,0);
        gt_cond_fatal_error(input_file->file_buffer==MAP_FAILED,SYS_MMAP_FILE,file_name);
        input_file->file_type = MAPPED_FILE;
    } else {
        input_file->fildes = -1;
        gt_cond_fatal_error(!(input_file->file=fopen(file_name,"r")),FILE_OPEN,file_name);
        input_file->file_type = REGULAR_FILE;
        if(S_ISREG(stat_info.st_mode)) {
            // Regular file - check if gzip or bzip compressed
            i=(int)fread(tbuf,(size_t)1,(size_t)4,input_file->file);
            if(tbuf[0]==0x1f && tbuf[1]==0x8b && tbuf[2]==0x08) {
                input_file->file_type=GZIPPED_FILE;
                fclose(input_file->file);
#ifdef HAVE_ZLIB
                gt_cond_fatal_error(!(input_file->file=(void *)gzopen(file_name,"r")),FILE_GZIP_OPEN,file_name);
#else
                gt_fatal_error(FILE_GZIP_NO_ZLIB,file_name);
#endif
            } else if(tbuf[0]=='B' && tbuf[1]=='Z' && tbuf[2]=='h' && tbuf[3]>='0' && tbuf[3]<='9') {
                fseek(input_file->file,0L,SEEK_SET);
                input_file->file_type=BZIPPED_FILE;
#ifdef HAVE_BZLIB
                input_file->file=BZ2_bzReadOpen(&i,input_file->file,0,0,NULL,0);
                gt_cond_fatal_error(i!=BZ_OK,FILE_BZIP2_OPEN,file_name);
#else
                gt_fatal_error(FILE_BZIP2_NO_BZLIB,file_name);
#endif
            } else {
                fseek(input_file->file,0L,SEEK_SET);
            }
        } else {
            input_file->eof=0;
        }
        input_file->file_buffer = gt_malloc(GT_INPUT_BUFFER_SIZE);
    }
    // Auxiliary Buffer (for synch purposes)
    input_file->buffer_size = 0;
    input_file->buffer_begin = 0;
    input_file->buffer_pos = 0;
    input_file->global_pos = 0;
    input_file->processed_lines = 0;
    // ID generator
    input_file->processed_id = 0;
    // Detect file format
    gt_input_file_detect_file_format(input_file);
    return input_file;
}
Exemplo n.º 27
0
GT_INLINE uint64_t gt_stats_vector_iterator_get_count(gt_stats_vector_iterator* const stats_vector_iterator) {
  GT_NULL_CHECK(stats_vector_iterator);
  GT_STATS_VECTOR_CHECK(stats_vector_iterator->stats_vector);
}
Exemplo n.º 28
0
GT_INLINE void gt_stats_vector_iterator_get_range(
    gt_stats_vector_iterator* const stats_vector_iterator,
    uint64_t* const lo_value,uint64_t* const hi_value) {
  GT_NULL_CHECK(stats_vector_iterator);
  GT_STATS_VECTOR_CHECK(stats_vector_iterator->stats_vector);
}
Exemplo n.º 29
0
GT_INLINE void gt_sam_attribute_func_params_set_sequence_archive(
    gt_sam_attribute_func_params* const func_params,gt_sequence_archive* const sequence_archive) {
  GT_NULL_CHECK(func_params);
  func_params->sequence_archive = sequence_archive;
}