Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

+ refactoring: movement of sff specific functions from main.c to sff.c

  - the functions identifying clipping points, fetching base strings, and
    quality array information from a read seemed more related to sff file
    specific features.
  • Loading branch information...
commit 6a93b400c08c94a69ab71e4bd5d6aa0b73999be5 1 parent 6c9edd3
@indraniel authored
Showing with 104 additions and 100 deletions.
  1. +1 −100 main.c
  2. +88 −0 sff.c
  3. +15 −0 sff.h
View
101 main.c
@@ -30,8 +30,6 @@
#define PRG_NAME "sff2fastq"
#define FASTQ_FILENAME_MAX_LENGTH 1024
#define SFF_FILENAME_MAX_LENGTH 1024
-#define min(a,b) ( (a) < (b) ? (a) : (b) )
-#define max(a,b) ( (a) > (b) ? (a) : (b) )
/* P R O T O T Y P E S *******************************************************/
void help_message(void);
@@ -45,19 +43,6 @@ void construct_fastq_entry(FILE *fp,
uint8_t *quality,
int nbases);
-void get_clip_values(sff_read_header rh,
- int trim_flag,
- int *left_clip,
- int *right_clip);
-
-char* get_read_bases(sff_read_data rd,
- int left_clip,
- int right_clip);
-
-uint8_t* get_read_quality_values(sff_read_data rd,
- int left_clip,
- int right_clip);
-
/* G L O B A L S *************************************************************/
char fastq_file[FASTQ_FILENAME_MAX_LENGTH] = { '\0' };
char sff_file[SFF_FILENAME_MAX_LENGTH] = { '\0' };
@@ -141,7 +126,7 @@ void process_options(int argc, char *argv[]) {
// /* just take the first passed in non-getopt argument as the sff file */
// strncpy(sff_file, argv[optind], SFF_FILENAME_MAX_LENGTH);
- /* ensure that an sff file was at least passed in! */
+ /* ensure that a sff file was at least passed in! */
if ( !strlen(sff_file) ) {
fprintf(stderr, "%s %s '%s %s' %s\n",
"[err] Need to specify a sff file!",
@@ -239,90 +224,6 @@ process_sff_to_fastq(char *sff_file, char *fastq_file, int trim_flag) {
fclose(sff_fp);
}
-/* as described in section 13.3.8.2 "Read Header Section" in the
- 454 Genome Sequencer Data Analysis Software Manual
- see (http://sequence.otago.ac.nz/download/GS_FLX_Software_Manual.pdf) */
-
-void get_clip_values(sff_read_header rh,
- int trim_flag,
- int *left_clip,
- int *right_clip) {
- if (trim_flag) {
- (*left_clip) =
- (int) max(1, max(rh.clip_qual_left, rh.clip_adapter_left));
-
- // account for the 1-based index value
- *left_clip = *left_clip - 1;
-
- (*right_clip) = (int) min(
- (rh.clip_qual_right == 0 ? rh.nbases : rh.clip_qual_right ),
- (rh.clip_adapter_right == 0 ? rh.nbases : rh.clip_adapter_right)
- );
- }
- else {
- (*left_clip) = 0;
- (*right_clip) = (int) rh.nbases;
- }
-}
-
-char* get_read_bases(sff_read_data rd,
- int left_clip,
- int right_clip) {
- char *bases;
-
- // account for NULL termination
- int bases_length = (right_clip - left_clip) + 1;
-
- // inititalize the bases string/array
- bases = (char *) malloc( bases_length * sizeof(char) );
- if (!bases) {
- fprintf(stderr, "Out of memory! For read bases string!\n");
- exit(1);
- }
- memset(bases, '\0', (size_t) bases_length);
-
- // copy the relative substring
- int start = left_clip;
- int stop = right_clip;
- int i, j = 0;
-
- for (i = start; i < stop; i++) {
- *(bases + j) = *(rd.bases + i);
- j++;
- }
-
- return bases;
-}
-
-uint8_t* get_read_quality_values(sff_read_data rd,
- int left_clip,
- int right_clip) {
- uint8_t* quality;
-
- // account for NULL termination
- int quality_length = (right_clip - left_clip) + 1;
-
- // inititalize the quality array
- quality = (uint8_t *) malloc( quality_length * sizeof(uint8_t) );
- if (!quality) {
- fprintf(stderr, "Out of memory! For read quality array!\n");
- exit(1);
- }
- memset(quality, '\0', (size_t) quality_length);
-
- // copy the relative substring
- int start = left_clip;
- int stop = right_clip;
- int i, j = 0;
-
- for (i = start; i < stop; i++) {
- *(quality + j) = *(rd.quality + i);
- j++;
- }
-
- return quality;
-}
-
void construct_fastq_entry(FILE *fp,
char *name,
char *bases,
View
88 sff.c
@@ -21,6 +21,7 @@
/* I N C L U D E S ***********************************************************/
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "sff.h"
/* F U N C T I O N S *********************************************************/
@@ -287,3 +288,90 @@ free_sff_read_data(sff_read_data *d) {
free(d->bases);
free(d->quality);
}
+
+/* as described in section 13.3.8.2 "Read Header Section" in the
+ 454 Genome Sequencer Data Analysis Software Manual
+ see (http://sequence.otago.ac.nz/download/GS_FLX_Software_Manual.pdf) */
+
+void
+get_clip_values(sff_read_header rh,
+ int trim_flag,
+ int *left_clip,
+ int *right_clip) {
+ if (trim_flag) {
+ (*left_clip) =
+ (int) max(1, max(rh.clip_qual_left, rh.clip_adapter_left));
+
+ // account for the 1-based index value
+ *left_clip = *left_clip - 1;
+
+ (*right_clip) = (int) min(
+ (rh.clip_qual_right == 0 ? rh.nbases : rh.clip_qual_right ),
+ (rh.clip_adapter_right == 0 ? rh.nbases : rh.clip_adapter_right)
+ );
+ }
+ else {
+ (*left_clip) = 0;
+ (*right_clip) = (int) rh.nbases;
+ }
+}
+
+char*
+get_read_bases(sff_read_data rd,
+ int left_clip,
+ int right_clip) {
+ char *bases;
+
+ // account for NULL termination
+ int bases_length = (right_clip - left_clip) + 1;
+
+ // inititalize the bases string/array
+ bases = (char *) malloc( bases_length * sizeof(char) );
+ if (!bases) {
+ fprintf(stderr, "Out of memory! For read bases string!\n");
+ exit(1);
+ }
+ memset(bases, '\0', (size_t) bases_length);
+
+ // copy the relative substring
+ int start = left_clip;
+ int stop = right_clip;
+ int i, j = 0;
+
+ for (i = start; i < stop; i++) {
+ *(bases + j) = *(rd.bases + i);
+ j++;
+ }
+
+ return bases;
+}
+
+uint8_t*
+get_read_quality_values(sff_read_data rd,
+ int left_clip,
+ int right_clip) {
+ uint8_t *quality;
+
+ // account for NULL termination
+ int quality_length = (right_clip - left_clip) + 1;
+
+ // inititalize the quality array
+ quality = (uint8_t *) malloc( quality_length * sizeof(uint8_t) );
+ if (!quality) {
+ fprintf(stderr, "Out of memory! For read quality array!\n");
+ exit(1);
+ }
+ memset(quality, '\0', (size_t) quality_length);
+
+ // copy the relative substring
+ int start = left_clip;
+ int stop = right_clip;
+ int i, j = 0;
+
+ for (i = start; i < stop; i++) {
+ *(quality + j) = *(rd.quality + i);
+ j++;
+ }
+
+ return quality;
+}
View
15 sff.h
@@ -85,6 +85,9 @@ extern "C" {
#define SFF_VERSION_LENGTH 4
#define PADDING_SIZE 8
+#define min(a,b) ( (a) < (b) ? (a) : (b) )
+#define max(a,b) ( (a) > (b) ? (a) : (b) )
+
/* This is the overall sff header file */
typedef struct {
@@ -142,6 +145,18 @@ void read_sff_read_data(FILE *fp,
void free_sff_read_header(sff_read_header *rh);
void free_sff_read_data(sff_read_data *d);
+void get_clip_values(sff_read_header rh,
+ int trim_flag,
+ int *left_clip,
+ int *right_clip);
+
+char* get_read_bases(sff_read_data rd,
+ int left_clip,
+ int right_clip);
+
+uint8_t* get_read_quality_values(sff_read_data rd,
+ int left_clip,
+ int right_clip);
#ifdef __cplusplus
}
Please sign in to comment.
Something went wrong with that request. Please try again.