<commit_before>/*
 * rapi_bwa.c
 */

#include "aligner.h"


aln_kv* aln_kv_insert_char(const char* key, char value,           const aln_kv* tail);
aln_kv* aln_kv_insert_str( const char* key, const char* value,    const aln_kv* tail);
aln_kv* aln_kv_insert_long(const char* key, long value,           const aln_kv* tail);
aln_kv* aln_kv_insert_dbl( const char* key, double value,         const aln_kv* tail);
aln_kv* aln_kv_insert_ba(  const char* key, const uint8_t* value, const aln_kv* tail);
aln_kv* aln_kv_insert_la(  const char* key, const long* value,    const aln_kv* tail);

aln_kv_free_list(aln_kv* list);



/* Init Library */
int aln_init()
{
  // DO

  return ALN_NO_ERROR;
}

/* Init Library Options */
int aln_init_ops( aln_opts * my_opts )
{
	my_opts->_private = mem_opt_init();
	my_opts->ignore_unsupported = TRUE;
	my_opts->mapq_min     = 0;
	my_opts->trim_quality = 0;
	my_opts->isize_min    = 0;
	my_opts->isize_max    = my_opts->_private.max_ins;
	my_opts->n_parameters = 0;
	my_opts->parameters   = NULL;
	return ALN_NO_ERROR;
}

int aln_free_opts( aln_opts * my_opts ) {
	free(my_opts->_private);
	return ALN_NO_ERROR;
}

/* Load Reference */
const char * aln_version()
{
	return "my version!";
}

/* Load Reference */
int aln_load_ref( const char * reference, aln_ref * ref_struct )
{
  ref_struct->handle=bwa_idx_load(reference, BWA_IDX_ALL);
  if ( ref_struct->handle == 0 )
  {
    return ALN_REFERENCE_ERROR;
  }
 
  ref_struct->path=reference;
 
  /* Fill in Contig Information */
  ref_struct->n_contigs = reference->handle->bns->n_seqs;	/* Handle contains bnt_seq_t * bns holding contig information */
  ref_struct->contigs=calloc( ref_struct->n_contigs, sizeof(aln_contig) );
 
  if ( ref_struct->contigs == 0 )
  {
    return ALN_MEMORY_ERROR;
  }
 
  for ( int contig_loop=0, contig_loop < ref_struct->n; contig_loop++ )
  {
    /* Get Name */
    /* Each bns holds an array of bntann1_t *anns -> holding 	
     	int64_t offset;
	int32_t len;
	int32_t n_ambs;
	uint32_t gi;
	char *name, *anno;
    */
    ref_struct->contigs[ contig_loop ].name =  reference->handle->bns->anns[ contig_loop ].name;
    ref_struct->contigs[ contig_loop ].len =  reference->handle->bns->anns[ contig_loop ].len;

  }

  return ALN_NO_ERROR;
}

/* Free Reference */
int aln_free_ref( aln_ref * ref_struct )
{
  for ( int contig_loop=0, contig_loop < ref_struct->n; contig_loop++ )<commit_msg>Name changes and style issues<commit_after>/*
 * rapi_bwa.c
 */

#include "aligner.h"


aln_kv* aln_kv_insert_char(const char* key, char value,           const aln_kv* tail);
aln_kv* aln_kv_insert_str( const char* key, const char* value,    const aln_kv* tail);
aln_kv* aln_kv_insert_long(const char* key, long value,           const aln_kv* tail);
aln_kv* aln_kv_insert_dbl( const char* key, double value,         const aln_kv* tail);
aln_kv* aln_kv_insert_ba(  const char* key, const uint8_t* value, const aln_kv* tail);
aln_kv* aln_kv_insert_la(  const char* key, const long* value,    const aln_kv* tail);

aln_kv_free_list(aln_kv* list);


char* strdup(const char* str)
{
	if (NULL == str)
		return NULL;

	size_t len = strlen(str);
	char* new_str = malloc(len + 1);
	if (NULL == new_str)
		return NULL;
	return strcpy(new_str, str);
}

/* Init Library */
int aln_init()
{
	// no op
  return ALN_NO_ERROR;
}

/* Init Library Options */
int aln_init_ops( aln_opts * my_opts )
{
	// create a BWA opt structure and link it to the external one
	my_opts->_private = mem_opt_init();

	my_opts->ignore_unsupported = TRUE;
	my_opts->mapq_min     = 0;
	my_opts->trim_quality = 0;
	my_opts->isize_min    = 0;
	my_opts->isize_max    = my_opts->_private.max_ins;
	my_opts->n_parameters = 0;
	my_opts->parameters   = NULL;

	return ALN_NO_ERROR;
}

int aln_free_opts( aln_opts * my_opts )
{
	free(my_opts->_private);
	return ALN_NO_ERROR;
}

/* Load Reference */
const char * aln_version()
{
	return "my version!";
}

/* Load Reference */
int aln_load_ref( const char * reference_path, aln_ref * ref_struct )
{
	if ( NULL == ref_struct || NULL == reference_path )
		return ALN_PARAM_ERROR;

  ref_struct->_private = bwa_idx_load(reference, BWA_IDX_ALL);

  if ( NULL == ref_struct->_private )
    return ALN_REFERENCE_ERROR;
 
  ref_struct->path=reference;
 
  /* Fill in Contig Information */
  ref_struct->n_contigs = reference->handle->bns->n_seqs;	/* Handle contains bnt_seq_t * bns holding contig information */
  ref_struct->contigs = calloc( ref_struct->n_contigs, sizeof(aln_contig) );
 
  if ( NULL == ref_struct->contigs )
  {
    return ALN_MEMORY_ERROR;
  }
 
  for ( int contig_loop = 0, contig_loop < ref_struct->n_contigs; contig_loop++ )
  {
    /* Get Name */
    /* Each bns holds an array of bntann1_t *anns -> holding 	
     	int64_t offset;
	int32_t len;
	int32_t n_ambs;
	uint32_t gi;
	char *name, *anno;
    */
    ref_struct->contigs[ contig_loop ].name = reference->handle->bns->anns[ contig_loop ].name;
    ref_struct->contigs[ contig_loop ].len =  reference->handle->bns->anns[ contig_loop ].len;
  }

  return ALN_NO_ERROR;
}

/* Free Reference */
int aln_free_ref( aln_ref * ref_struct )
{
	free(ref_struct->path);

  for ( int contig_loop = 0, contig_loop < ref_struct->n_contigs; contig_loop++ )
{'fraction_non_alphanumeric': 0.12404287901990811, 'fraction_numerical': 0.006699846860643185, 'mean_word_length': 3.802389705882353, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 66, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4976449', 'n_tokens_mistral': 2117, 'n_tokens_neox': 2036, 'n_words': 465}