Input reads

This commit is contained in:
Haoyu Cheng
2019-05-10 00:11:19 -04:00
parent 8d7672e708
commit 0b209dd1e9
9 changed files with 399 additions and 0 deletions
Binary file not shown.
+32
View File
@@ -0,0 +1,32 @@
#include "Assembly.h"
#include <stdio.h>
#include <stdlib.h>
#include "Process_Read.h"
void Counting()
{
Read r;
init_Read(&r);
long long read_number = 0;
while (inputRead(&r))
{
fprintf(stderr,"%s\n",r.name);
fprintf(stderr,"%s\n",r.seq);
fprintf(stderr,"+\n");
fprintf(stderr,"%s\n",r.qual);
read_number++;
clear_read(&r);
}
fprintf(stdout, "read_number: %lld\n",read_number);
}
+8
View File
@@ -0,0 +1,8 @@
#ifndef __ASSEMBLY__
#define __ASSEMBLY__
void Counting();
#endif
+63
View File
@@ -0,0 +1,63 @@
#include "CommandLines.h"
#include <stdlib.h>
#include <getopt.h>
#include <stdio.h>
char* read_file_name = NULL;
char* output_file_name = NULL;
int thread_num = 1;
void Print_H()
{
fprintf(stderr, "Incorrect options.\n");
}
int CommandLine_process (int argc, char *argv[])
{
int o;
int index;
static struct option longOptions[] =
{
{"seq", required_argument, 0, 'q'},
{"threads", required_argument, 0, 't'},
{"threads", required_argument, 0, 'o'},
{0, 0, 0, 0},
};
while ( (o = getopt_long ( argc, argv, "q:t:o:", longOptions, &index)) != -1 )
{
switch (o)
{
case 'q':
read_file_name = optarg;
break;
case 'o':
output_file_name = optarg;
break;
case 't':
thread_num = atoi(optarg);
break;
case '?':
fprintf(stderr, "Unrecognized option!\n" );
return 0;
break;
default:
Print_H();
return 0;
}
}
if (argc == 1)
{
Print_H();
return 0;
}
return 1;
}
+10
View File
@@ -0,0 +1,10 @@
#ifndef __COMMAND_LINE_PARSER__
#define __COMMAND_LINE_PARSER__
extern char* read_file_name;
extern char* output_file_name;
extern int thread_num;
int CommandLine_process (int argc, char *argv[]);
#endif
+18
View File
@@ -0,0 +1,18 @@
CC=g++
CFLAGS = -w -c -msse4.2 -mpopcnt -fomit-frame-pointer -Winline -O3 -lz
LDFLAGS = -lm -lz -lpthread -O3 -mpopcnt -msse4.2 -lz -w
SOURCES = main.cpp CommandLines.cpp Process_Read.cpp Assembly.cpp
OBJECTS = $(SOURCES:.c=.o)
EXECUTABLE = ccs_assembly
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(OBJECTS) -o $@ $(LDFLAGS)
.c.o:
$(CC) $(CFLAGS) $< -o $@
clean:
rm -f *.o *~ \#* ccs_assembly
+164
View File
@@ -0,0 +1,164 @@
#include "Process_Read.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <zlib.h>
#include <fcntl.h>
int format = -1;
FILE *_r_fp = NULL;
gzFile g_r_fp;
int check_file_format(char *fileName)
{
int i = 0;
char* file_extention;
i = strlen(fileName) - 1;
while (i >= 0 && fileName[i] != '.')
{
i--;
}
if (i < 0)
{
fprintf(stderr,
"ERROR: the input read files must be FASTQ format (file extension: .fq or .fastq) or compressed FASTQ format (file extension: .fq.gz or .fastq.gz)!\n");
exit(0);
}
if ((strcmp(".fq", fileName+i) == 0)
||
strcmp(".fastq", fileName + i) == 0)
{
return FASTQ;
}
else if (strcmp(".gz", fileName + i) == 0)
{
i--;
while (i >= 0 && fileName[i] != '.')
{
i--;
}
if (i < 0)
{
fprintf(stderr,
"ERROR: the input read files must be FASTQ format (file extension: .fq or .fastq) or compressed FASTQ format (file extension: .fq.gz or .fastq.gz)!\n");
exit(0);
}
if ((strcmp(".fq.gz", fileName + i) == 0)
||
strcmp(".fastq.gz", fileName + i) == 0)
{
return FASTQGZ;
}
else
{
fprintf(stderr,
"ERROR: the input read files must be FASTQ format (file extension: .fq or .fastq) or compressed FASTQ format (file extension: .fq.gz or .fastq.gz)!\n");
exit(0);
}
}
fprintf(stderr,
"ERROR: the input read files must be FASTQ format (file extension: .fq or .fastq) or compressed FASTQ format (file extension: .fq.gz or .fastq.gz)!\n");
exit(0);
}
int initiReadAllReads(char *fileName)
{
format = check_file_format(fileName);
if (format == FASTQ)
{
_r_fp = fopen(fileName, "r");
if (_r_fp == NULL)
{
return 0;
}
fprintf(stdout,
" Read files are in FASTQ format...\n");
}
else if (format == FASTQGZ)
{
int fd = open(fileName, O_CREAT | O_RDONLY, 0666);
g_r_fp = gzdopen(fd, "rb");
fprintf(stdout,
" Read files are in compressed FASTQ format...\n");
}
else
{
fprintf(stderr,
"ERROR: the input read files must be FASTQ format (file extension: .fq or .fastq) or compressed FASTQ format (file extension: .fq.gz or .fastq.gz)!\n");
exit(0);
}
}
#define BUFFER_SIZE 20000
char Read_Buffer[BUFFER_SIZE];
char true_flag[2];
inline char *Input_line_from_file(char *seq)
{
if (format == FASTQ)
{
return fgets(Read_Buffer, BUFFER_SIZE, _r_fp);
}
else
{
seq = gzgets(g_r_fp, seq, BUFFER_SIZE);
return (!gzeof(g_r_fp)) ? true_flag : NULL;
}
}
inline int get_whole_line(str_v* line)
{
while(Input_line_from_file(Read_Buffer))
{
append_str(line, Read_Buffer);
if (line->centext[line->length - 1] == '\n')
{
line->length--;
line->centext[line->length] = '\0';
return 1;
}
}
return 0;
}
int inputRead(Read *read)
{
int buffer_length;
if (get_whole_line(&read->name))
{
get_whole_line(&read->seq);
Input_line_from_file(Read_Buffer);
get_whole_line(&read->qual);
return 1;
}
return 0;
}
+76
View File
@@ -0,0 +1,76 @@
#ifndef __READ__
#define __READ__
#include<stdint.h>
#include <string.h>
#include <stdlib.h>
#define FASTQ 1
#define FASTQGZ 2
#define NAME_SZIE 25
#define SEQ_SZIE 20000
typedef struct
{
char* centext;
uint32_t length;
uint32_t size;
}str_v;
inline void init_str_v(str_v* buf, uint32_t length)
{
buf->size = length + 1;
buf->length = 0;
buf->centext = (char*)malloc(sizeof(char)*buf->size);
}
inline void append_str(str_v* buf, char* input)
{
int length = strlen(input);
buf->length = buf->length + length;
if (buf->length > buf->size)
{
buf->centext = (char*)realloc(buf->centext, buf->length + 1);
}
memcpy(buf->centext + buf->length - length, input, length);
buf->centext[buf->length] = '\0';
}
inline void clear_str(str_v* buf)
{
buf->length = 0;
}
typedef struct
{
str_v name;
str_v seq;
str_v qual;
} Read;
inline void init_Read(Read* r)
{
init_str_v(&r->name, NAME_SZIE);
init_str_v(&r->seq, SEQ_SZIE);
init_str_v(&r->qual, SEQ_SZIE);
}
inline void clear_read(Read* r)
{
clear_str(&r->name);
clear_str(&r->seq);
clear_str(&r->qual);
}
int initiReadAllReads(char *fileName);
int inputRead(Read *read);
#endif
+28
View File
@@ -0,0 +1,28 @@
#include <stdio.h>
#include <stdlib.h>
#include "CommandLines.h"
#include "Process_Read.h"
#include "Assembly.h"
int main(int argc, char *argv[])
{
if (!CommandLine_process(argc, argv))
return 1;
if (!initiReadAllReads(read_file_name))
{
fprintf(stdout, "Cannot open read files. \n");
return 1;
}
Counting();
return 1;
}