File: fastq.h

package info (click to toggle)
skewer 0.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 272 kB
  • sloc: cpp: 5,384; makefile: 47
file content (144 lines) | stat: -rw-r--r-- 3,638 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**********************************************************************
 * Skewer - a fast and accurate adapter trimming tool
 *          using the bit-masked k-difference matching algorithm
 * Copyright (c) 2013-2014 by Hongshan Jiang
 * hongshan.jiang@gmail.com
 *
 * If you use this program, please cite the paper:
 * Jiang, H., Lei, R., Ding, S.W. and Zhu, S. (2014) Skewer: a fast and
 * accurate adapter trimmer for next-generation sequencing paired-end reads.
 * BMC Bioinformatics, 15, 182.
 * http://www.biomedcentral.com/1471-2105/15/182
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.

 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
#ifndef _FASTQ_H
#define _FASTQ_H

// standard libs
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <getopt.h>
#include <assert.h>
#include <math.h>
#include <sys/stat.h>
#include <search.h>
#include <limits.h>

#include <time.h>
#ifdef __MACH__
#include <mach/mach_time.h>
#define ORWL_NANO (+1.0E-9)
#define ORWL_GIGA UINT64_C(1000000000)
#endif

#include "common.h"

typedef struct tag_LINE {
	char *s;
	int n;
	size_t a;
}LINE;

typedef enum{
	TAG_NORMAL = 0,
	TAG_BLURRY = 1,
	TAG_BADQUAL = 2,
	TAG_EMPTY = 3,
	TAG_SHORT = 4,
	TAG_CONTAMINANT = 5,
	TAG_UNDETERMINED = 6,
	TAG_LONG = 7
}REC_TAG;

typedef struct tag_REC{
	uint32 tag:7; // REC_TAG
	uint32 bExchange:1;
	uint32 nCnt:24;
	INDEX idx;
	LINE id;
	LINE seq;
	LINE com;
	LINE qual;
}RECORD;

class cFQ
{
private:
//	int size;

public:
	char tag;

	RECORD rec;
//	RECORD *pBuffer;
//	int cnt;

	FILE * in;
	int64 offset;
	int64 next_pos;
	int rno;

private:
	inline int read_line(LINE &l);

public:
	cFQ();
	~cFQ();
//	bool InitBuffer(int nBuffSize=256);
//	void DestroyBuffer();
//	void clearBuffer();
	void associateFile(FILE * fp);
	int readRecord(RECORD *pRecord=NULL);
//	int readRecord2Buffer();
//	RECORD * getLastRecord();
	inline int64 tell(){ return offset; }
};

typedef struct tag_CFILE{
	FILE * fp;
	bool bGz;
}CFILE;

enum FASTQ_FORMAT{
	SANGER_FASTQ = 0,
	SOLEXA_FASTQ = 1,
	UNKNOWN_FASTQ = 2,
	CONTRADICT_FASTQ = 3,
	FASTA = 4,
	FASTQ_FORMAT_CNT = 5
};
extern const char * FASTQ_FORMAT_NAME[FASTQ_FORMAT_CNT];

// open a file, possibly gzipped, exit on failure
extern CFILE gzopen(const char * fileName, const char *mode);
extern int gzclose(CFILE *f);
extern int64 gzsize(const char * fileName);
extern enum FASTQ_FORMAT gzformat(char * fileNames[], int nFileCnt);
extern int gzreadlen(char * fileName);
extern void gzstrncpy (char * dest, const char * src, int n);

// time function
extern void versatile_gettime(struct timespec *tp);

#endif // _FASTQ_H