[med-svn] [libqes] 01/07: New upstream version 0.2.5
Kevin Murray
daube-guest at moszumanska.debian.org
Tue Nov 15 08:52:46 UTC 2016
This is an automated email from the git hooks/post-receive script.
daube-guest pushed a commit to branch master
in repository libqes.
commit 771cf16fddde90bc624136d90ebab74fcb69f4f0
Author: Kevin Murray <spam at kdmurray.id.au>
Date: Tue Nov 15 19:41:58 2016 +1100
New upstream version 0.2.5
---
.travis.yml | 29 +++++++++++--------------
CMakeLists.txt | 49 ++++++++++++++++++------------------------
src/CMakeLists.txt | 14 ++++++++++--
src/qes_config.h.in | 2 +-
src/qes_file.c | 10 ++++++++-
src/qes_log.h | 4 ++--
src/qes_seq.c | 35 ++++++++++++++++++++++--------
src/qes_seq.h | 25 +++++++++++++++++----
src/qes_seqfile.c | 16 ++++----------
src/qes_str.c | 2 +-
src/qes_str.h | 43 ++++++++++++++++++++++++++++++------
src/qes_util.h | 4 +---
test/CMakeLists.txt | 9 ++++++++
test/data/test_large.fasta.gz | Bin 0 -> 317571 bytes
test/kseqcat.c | 41 +++++++++++++++++++++++++++++++++++
test/qes_seqcat.c | 30 ++++++++++++++++++++++++++
test/qes_seqprint.c | 21 ++++++++++++++++++
test/test_seq.c | 8 +++----
test/test_seqcats.sh | 34 +++++++++++++++++++++++++++++
test/test_seqfile.c | 2 +-
20 files changed, 288 insertions(+), 90 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index aa41a19..89c69e9 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,26 +1,24 @@
language: c
+sudo: required
+dist: trusty
+
env:
- - BUILD_TYPE=Release
- - BUILD_TYPE=Debug
- - BUILD_TYPE=Coverage
+ - BUILD_TYPE=Release
+ - BUILD_TYPE=Debug
+ - BUILD_TYPE=Coverage
compiler:
- - clang
- - gcc
+ - clang
+ - gcc
+
+notifications:
+ email:
+ - kdmfoss at gmail.com
install:
- - sudo apt-get install lcov python-pip
- - mkdir zlib && cd zlib
- - wget http://zlib.net/zlib-1.2.8.tar.gz
- - tar xvxf zlib-1.2.8.tar.gz
- - cd zlib-1.2.8
- - ./configure
- - make
- - sudo make install
- - cd ../..
+ - sudo apt-get install lcov python-pip zlib1g-dev
- sudo pip install cpp-coveralls
- - git submodule update --init
- mkdir build
- mkdir target
- cd build
@@ -31,7 +29,6 @@ script:
- ctest --verbose
- make install
- test -f ../target/include/qes.h
- - if [ $static == "TRUE" ] ; then test -f ../target/lib/libqes.a; else test -f ../target/lib/libqes.so ; fi
after_success:
- cd ..
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bb91d87..1fb3d6c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -61,6 +61,19 @@ ENABLE_TESTING()
SET(CPACK_GENERATOR "TGZ;TBZ2")
INCLUDE(CPack)
+##########################
+## Set Compiler Options ##
+##########################
+
+
+SET(WARN_FLAGS "${WARN_FLAGS} -Wall -Wextra -Wpedantic")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -D_GNU_SOURCE ${WARN_FLAGS}")
+
+SET(CMAKE_C_FLAGS_DEBUG "-ggdb")
+SET(CMAKE_C_FLAGS_RELEASE "-O3")
+
+
###############################
## Find Packages and Headers ##
###############################
@@ -77,7 +90,7 @@ CHECK_SYMBOL_EXISTS(getline stdio.h GETLINE_FOUND)
CHECK_SYMBOL_EXISTS(strndup string.h STRNDUP_FOUND)
IF (NOT ${NO_ZLIB})
- FIND_PACKAGE(ZLIB 1.2.1 REQUIRED)
+ FIND_PACKAGE(ZLIB 1.2.5 REQUIRED)
CHECK_LIBRARY_EXISTS(${ZLIB_LIBRARIES} gzbuffer "" GZBUFFER_FOUND)
ELSE()
SET(ZLIB_FOUND FALSE)
@@ -108,34 +121,12 @@ SET(LIBQES_DEPENDS_CFLAGS
${ZLIB_CFLAGS}
${OpenMP_C_FLAGS})
-##########################
-## Set Compiler Options ##
-##########################
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBQES_DEPENDS_CFLAGS}")
-# Set GCC-specific options
-IF (CMAKE_COMPILER_IS_GNUCC)
- SET(WEXTRA_FLAGS "${WEXTRA_FLAGS} -Woverride-init -Wnormalized=id -Wlogical-op")
- EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
- IF (${GCC_VERSION} VERSION_GREATER 4.9 OR ${GCC_VERSION} VERSION_EQUAL 4.9)
- SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-color=always")
- ENDIF()
-ENDIF()
-# Set CFLAGS
-SET(WEXTRA_FLAGS "${WEXTRA_FLAGS} -Wstack-protector -Wfloat-equal")
-SET(WEXTRA_FLAGS "${WEXTRA_FLAGS} -Wundef -Wpointer-arith -Wstrict-prototypes")
-SET(WEXTRA_FLAGS "${WEXTRA_FLAGS} -Wmissing-prototypes -Wwrite-strings -Wredundant-decls")
-SET(WEXTRA_FLAGS "${WEXTRA_FLAGS} -Wchar-subscripts -Wcomment -Wformat=2 -Wwrite-strings")
-SET(WEXTRA_FLAGS "${WEXTRA_FLAGS} -Wmissing-declarations -Wredundant-decls -Wnested-externs")
-SET(WEXTRA_FLAGS "${WEXTRA_FLAGS} -Wbad-function-cast -Wswitch-enum -Winit-self")
-SET(WEXTRA_FLAGS "${WEXTRA_FLAGS} -Wmissing-field-initializers -Wdeclaration-after-statement")
-SET(WEXTRA_FLAGS "${WEXTRA_FLAGS} -Wold-style-definition -Waddress -Wmissing-noreturn ")
-SET(WEXTRA_FLAGS "${WEXTRA_FLAGS} -Wstrict-overflow=1 -Wextra -Warray-bounds -Wall")
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBQES_DEPENDS_CFLAGS} -std=gnu99 ${WEXTRA_FLAGS}")
-
-SET(CMAKE_C_FLAGS_DEBUG "-ggdb")
-SET(CMAKE_C_FLAGS_RELEASE "-O3")
+#####################
+## Set CMake Paths ##
+#####################
# Set include dirs
INCLUDE_DIRECTORIES(
@@ -151,4 +142,6 @@ LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/lib)
# Traverse to library source and tests
ADD_SUBDIRECTORY(src)
-ADD_SUBDIRECTORY(test)
+if (NOT LIBQES_AS_SUBMODULE)
+ ADD_SUBDIRECTORY(test)
+endif()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index bc90804..5e818d1 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,12 +1,22 @@
file(GLOB LIBQES_SOURCES qes_*.c)
# Targets
-ADD_LIBRARY(qes_static STATIC ${LIBQES_SOURCES})
+if(LIBQES_DONT_INSTALL)
+ ADD_LIBRARY(qes_static STATIC EXCLUDE_FROM_ALL ${LIBQES_SOURCES})
+ ADD_LIBRARY(qes SHARED EXCLUDE_FROM_ALL ${LIBQES_SOURCES})
+else()
+ ADD_LIBRARY(qes_static STATIC ${LIBQES_SOURCES})
+ ADD_LIBRARY(qes SHARED ${LIBQES_SOURCES})
+endif()
+
+
SET_TARGET_PROPERTIES(qes_static PROPERTIES OUTPUT_NAME qes)
TARGET_LINK_LIBRARIES(qes_static ${LIBQES_DEPENDS_LIBS})
-ADD_LIBRARY(qes SHARED ${LIBQES_SOURCES})
+target_include_directories(qes_static PUBLIC ${LIBQES_DEPENDS_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
+
SET_TARGET_PROPERTIES(qes PROPERTIES SONAME_VERSION 0 VERSION 0)
TARGET_LINK_LIBRARIES(qes ${LIBQES_DEPENDS_LIBS})
+target_include_directories(qes PUBLIC ${LIBQES_DEPENDS_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
CONFIGURE_FILE(qes_config.h.in ${CMAKE_BINARY_DIR}/qes_config.h)
FILE(GLOB LIBQES_HEADERS ${CMAKE_SOURCE_DIR}/src/*.h ${CMAKE_BINARY_DIR}/qes_config.h)
diff --git a/src/qes_config.h.in b/src/qes_config.h.in
index fc08cd5..a3ae570 100644
--- a/src/qes_config.h.in
+++ b/src/qes_config.h.in
@@ -33,7 +33,7 @@
#ifndef QES_CONFIG_H
#define QES_CONFIG_H
-#define LIBQES_VERSION "${LIBQES_VERSION}";
+#define LIBQES_VERSION "${LIBQES_VERSION}"
#cmakedefine GETLINE_FOUND
#cmakedefine STRNDUP_FOUND
#cmakedefine ZLIB_FOUND
diff --git a/src/qes_file.c b/src/qes_file.c
index 1e14280..93fee0f 100644
--- a/src/qes_file.c
+++ b/src/qes_file.c
@@ -73,7 +73,15 @@ qes_file_open_ (const char *path, const char *mode, qes_errhandler_func onerr,
/* create file struct */
qf = qes_calloc(1, sizeof(*qf));
/* Open file, handling any errors */
- qf->fp = QES_ZOPEN(path, mode);
+ if (strcmp(path, "-") == 0) {
+ if (tolower(mode[0]) == 'r') {
+ qf->fp = QES_ZDOPEN(STDIN_FILENO, mode);
+ } else {
+ qf->fp = QES_ZDOPEN(STDOUT_FILENO, mode);
+ }
+ } else {
+ qf->fp = QES_ZOPEN(path, mode);
+ }
if (qf->fp == NULL) {
(*onerr)("Opening file %s failed:\n%s\n", file, line,
path, strerror(errno));
diff --git a/src/qes_log.h b/src/qes_log.h
index 7f96e2e..fe81088 100644
--- a/src/qes_log.h
+++ b/src/qes_log.h
@@ -110,7 +110,7 @@ int qes_logger_add_destination_formatted(struct qes_logger *logger,
qes_logger_add_destination_formatted(log, stream, level, \
&qes_log_formatter_plain)
void _qes_logger_destroy(struct qes_logger *logger);
-#define qes_logger_destroy(l) ({ _qes_logger_destroy(l); l = NULL; })
+#define qes_logger_destroy(l) STMT_BEGIN _qes_logger_destroy(l); l = NULL; STMT_END
struct qes_log_entry *qes_log_entry_create(void);
@@ -129,7 +129,7 @@ int qes_log_entry_format_va(struct qes_log_entry *entry,
int qes_logger_write_entry(struct qes_logger *logger,
struct qes_log_entry *entry);
void _qes_log_entry_destroy(struct qes_log_entry *log_entry);
-#define qes_log_entry_destroy(l) ({ _qes_log_entry_destroy(l); l = NULL; })
+#define qes_log_entry_destroy(l) STMT_BEGIN _qes_log_entry_destroy(l); l = NULL; STMT_END
int qes_log_message(struct qes_logger *logger, enum qes_log_level level,
diff --git a/src/qes_seq.c b/src/qes_seq.c
index 726a5df..f9e8e61 100644
--- a/src/qes_seq.c
+++ b/src/qes_seq.c
@@ -186,29 +186,46 @@ qes_seq_destroy_(struct qes_seq *seq)
}
}
+static inline void
+_printstr_linewrap(const struct qes_str *str, size_t linelen, FILE *stream)
+{
+
+ for (size_t i = 0; i < str->len; i += linelen) {
+ const size_t remaining = str->len - i;
+ const size_t towrite = remaining < linelen ? remaining : linelen;
+ fwrite(str->str + i, towrite, 1, stream);
+ fputc('\n', stream);
+ }
+}
+
int
-qes_seq_print(const struct qes_seq *seq, FILE *stream)
+qes_seq_print(const struct qes_seq *seq, FILE *stream, bool fasta, int tag)
{
if (!qes_seq_ok(seq)) return 1;
if (stream == NULL) return 1;
+ size_t linelen = fasta ? 79 : SIZE_MAX - 1;
- if (seq->qual.len > 0) {
- fputc('@', stream);
- } else {
+ if (fasta) {
fputc('>', stream);
+ } else {
+ fputc('@', stream);
}
fputs(seq->name.str, stream);
+ if (tag > 0) {
+ // Add tag only if read is not already tagged.
+ if (seq->name.len > 2 && seq->name.str[seq->name.len - 2] != '/') {
+ fprintf(stream, "/%d", tag);
+ }
+ }
if (seq->comment.str) {
fputc(' ', stream);
fputs(seq->comment.str, stream);
}
fputc('\n', stream);
- fputs(seq->seq.str, stream);
- fputc('\n', stream);
- if (seq->qual.len > 0) {
+ _printstr_linewrap(&seq->seq, linelen, stream);
+ if (!fasta) {
fputs("+\n", stream);
- fputs(seq->qual.str, stream);
- fputc('\n', stream);
+ _printstr_linewrap(&seq->qual, linelen, stream);
}
fflush(stream);
return 0;
diff --git a/src/qes_seq.h b/src/qes_seq.h
index 5555368..f2a1b46 100644
--- a/src/qes_seq.h
+++ b/src/qes_seq.h
@@ -29,6 +29,7 @@
#ifndef QES_SEQ_H
#define QES_SEQ_H
+#include <stdbool.h>
#include <qes_util.h>
#include <qes_str.h>
@@ -133,6 +134,19 @@ qes_seq_n_bytes (const struct qes_seq *seq)
qes_seq_has_qual(seq) ? 2 + seq->qual.len + 1 : 0;
}
+static inline int
+qes_seq_truncate (struct qes_seq *seq, const size_t at)
+{
+ if (!qes_seq_ok(seq)) return -1;
+
+ int res = 0;
+ res = qes_str_truncate(&seq->seq, at);
+ if (res != 0) return res;
+
+ res = qes_str_truncate(&seq->qual, at);
+ return res;
+}
+
/*=== FUNCTION ============================================================*
Name: qes_seq_fill_header
Parameters: struct qes_seq *seqobj: Seq object that will receive the header.
@@ -166,14 +180,17 @@ extern int qes_seq_fill(struct qes_seq *seqobj, const char *name,
/*=== FUNCTION ============================================================*
Name: qes_seq_print
-Parameters: const struct qes_seq *: seq to print
- qes_seqfile_format_t: file format to print in.
- FILE *: open file stream to print to.
+Parameters: const struct qes_seq *seq: seq to print
+ FILE *stream: open file stream to print to.
+ bool fasta: Print as fasta?
+ int tag: Tag read name with /%d. use 0 to disable.
Description: Print ``seq`` in formatted per ``format`` to ``stream``.
Returns: int: 1 on success, 0 on failure.
*===========================================================================*/
int qes_seq_print (const struct qes_seq *seq,
- FILE *stream);
+ FILE *stream,
+ bool fasta,
+ int tag);
/*=== FUNCTION ============================================================*
Name: qes_seq_destroy
diff --git a/src/qes_seqfile.c b/src/qes_seqfile.c
index cccdd8d..469ec3b 100644
--- a/src/qes_seqfile.c
+++ b/src/qes_seqfile.c
@@ -126,23 +126,15 @@ read_fasta_seqfile(struct qes_seqfile *seqfile, struct qes_seq *seq)
/* we need to nullify seq, as we rely on seq.len being 0 as we enter this
* while loop */
qes_str_nullify(&seq->seq);
+ qes_str_nullify(&seqfile->scratch);
/* While the next char is not a '>', i.e. until next header line */
while ((next = qes_file_peek(seqfile->qf)) != EOF && next != FASTA_DELIM) {
- len = qes_file_readline(seqfile->qf, seq->seq.str + seq->seq.len,
- seq->seq.capacity - seq->seq.len - 1);
+ len = qes_file_readline_str(seqfile->qf, &seqfile->scratch);
+ CHECK_AND_TRIM(seqfile->scratch)
if (len < 0) {
goto error;
}
- seq->seq.len += len - 1;
- seq->seq.str[seq->seq.len] = '\0';
- if (seq->seq.capacity - 1 <= seq->seq.len) {
- seq->seq.capacity = qes_roundupz(seq->seq.capacity);
- seq->seq.str = qes_realloc(seq->seq.str,
- sizeof(*seq->seq.str) * seq->seq.capacity);
- if (seq->seq.str == NULL) {
- goto error;
- }
- }
+ qes_str_cat(&seq->seq, &seqfile->scratch);
}
seq->seq.str[seq->seq.len] = '\0';
/* return seq len */
diff --git a/src/qes_str.c b/src/qes_str.c
index 1483ef7..6f173a1 100644
--- a/src/qes_str.c
+++ b/src/qes_str.c
@@ -33,7 +33,7 @@ void
qes_str_print (const struct qes_str *str, FILE *stream)
{
if (qes_str_ok(str)) {
- fprintf(stream, "%s", str->str);
+ fwrite(str->str, 1, str->len, stream);
}
}
diff --git a/src/qes_str.h b/src/qes_str.h
index 1b55370..79fed96 100644
--- a/src/qes_str.h
+++ b/src/qes_str.h
@@ -88,19 +88,26 @@ qes_str_create (size_t capacity)
}
static inline int
-qes_str_fill_charptr (struct qes_str *str, const char *cp, size_t len)
+qes_str_resize (struct qes_str *str, size_t len)
{
- if (str == NULL || cp == NULL) return 0;
- if (len == 0) {
- len = strlen(cp);
- }
+ if (str == NULL) return 0;
if (str->capacity < len + 1) {
while (str->capacity < len + 1) {
str->capacity = qes_roundupz(str->capacity);
}
str->str = qes_realloc(str->str, str->capacity * sizeof(*str->str));
}
- /* FIXME: check for null after realloc */
+ return 1;
+}
+
+static inline int
+qes_str_fill_charptr (struct qes_str *str, const char *cp, size_t len)
+{
+ if (str == NULL || cp == NULL) return 0;
+ if (len == 0) {
+ len = strlen(cp);
+ }
+ qes_str_resize(str, len);
memcpy(str->str, cp, len);
str->str[len] = '\0';
str->len = len;
@@ -127,10 +134,34 @@ qes_str_copy (struct qes_str *dest, const struct qes_str *src)
{
if (!qes_str_ok(src) || dest == NULL) return 1;
if (!qes_str_ok(dest)) qes_str_init(dest, src->capacity);
+ else qes_str_resize(dest, src->capacity);
memcpy(dest->str, src->str, src->capacity);
return 0;
}
+static inline int
+qes_str_cat (struct qes_str *dest, const struct qes_str *src)
+{
+ if (!qes_str_ok(src) || dest == NULL) return 1;
+ if (!qes_str_ok(dest)) qes_str_init(dest, src->capacity);
+ else qes_str_resize(dest, dest->len + src->len);
+
+ memcpy(dest->str + dest->len, src->str, src->len);
+ dest->len += src->len;
+ dest->str[dest->len] = '\0';
+ return 0;
+}
+
+static inline int
+qes_str_truncate (struct qes_str *str, const size_t at)
+{
+ if (!qes_str_ok(str)) return 1;
+ if (at >= str->len) return 0;
+ str->str[at] = '\0';
+ str->len = at;
+ return 0;
+}
+
extern void qes_str_print (const struct qes_str *str, FILE *stream);
/*=== FUNCTION ============================================================*
diff --git a/src/qes_util.h b/src/qes_util.h
index 30217bb..8e01ce1 100644
--- a/src/qes_util.h
+++ b/src/qes_util.h
@@ -41,8 +41,6 @@
#include <string.h>
#include <strings.h>
#include "qes_config.h"
-#include "qes_compat.h"
-#include "qes_libgnu.h"
/*
@@ -84,7 +82,7 @@ extern const char *libqes_version;
/* STMT_BEGIN and STMT_END are used to wrap blocks inside macros so that
* the macro can be used as if it were a single C statement. */
#ifdef __GNUC__
- #define STMT_BEGIN (void) ({
+ #define STMT_BEGIN (void) __extension__ ({
#define STMT_END })
#elif defined(sun) || defined(__sun__)
#define STMT_BEGIN if (1) {
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index fdf2ed1..845853d 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -10,6 +10,15 @@ ENDIF()
ADD_TEST(NAME run_test_libqes
COMMAND ${CMAKE_BINARY_DIR}/bin/test_libqes ${CMAKE_BINARY_DIR})
+ADD_EXECUTABLE(qes_seqcat ${CMAKE_CURRENT_SOURCE_DIR}/qes_seqcat.c)
+TARGET_LINK_LIBRARIES(qes_seqcat qes ${LIBQES_DEPENDS_LIBS})
+
+ADD_EXECUTABLE(qes_seqprint ${CMAKE_CURRENT_SOURCE_DIR}/qes_seqprint.c)
+TARGET_LINK_LIBRARIES(qes_seqprint qes ${LIBQES_DEPENDS_LIBS})
+
+ADD_EXECUTABLE(kseqcat ${CMAKE_CURRENT_SOURCE_DIR}/kseqcat.c)
+TARGET_LINK_LIBRARIES(kseqcat qes ${LIBQES_DEPENDS_LIBS})
+
# Demos
ADD_EXECUTABLE(log_demo ${CMAKE_CURRENT_SOURCE_DIR}/logdemo.c)
TARGET_LINK_LIBRARIES(log_demo qes ${LIBQES_DEPENDS_LIBS})
diff --git a/test/data/test_large.fasta.gz b/test/data/test_large.fasta.gz
new file mode 100644
index 0000000..7921c84
Binary files /dev/null and b/test/data/test_large.fasta.gz differ
diff --git a/test/kseqcat.c b/test/kseqcat.c
new file mode 100644
index 0000000..f6d38ce
--- /dev/null
+++ b/test/kseqcat.c
@@ -0,0 +1,41 @@
+#include "qes_config.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <zlib.h>
+
+#include "kseq.h"
+
+#ifdef ZLIB_FOUND
+# include <zlib.h>
+ KSEQ_INIT(gzFile, gzread)
+#else
+# include <sys/stat.h>
+# include <fcntl.h>
+ KSEQ_INIT(int, read)
+#endif
+
+int main(int argc, char *argv[])
+{
+ if (argc < 2) return 1;
+ const char *fname = argv[1];
+ gzFile fp = gzopen(fname, "r");
+ kseq_t *kseq = kseq_init(fp);
+ ssize_t res = 0;
+ while((res = kseq_read(kseq)) > 0) {
+ if (kseq->qual.l < 1) {
+ // fasta
+ printf(">%s %s\n", kseq->name.s, kseq->comment.s);
+ puts(kseq->seq.s);
+ } else {
+ // fastq
+ printf("@%s %s\n", kseq->name.s, kseq->comment.s);
+ puts(kseq->seq.s);
+ puts("+");
+ puts(kseq->qual.s);
+ }
+ }
+ kseq_destroy(kseq);
+ gzclose(fp);
+ return 0;
+}
diff --git a/test/qes_seqcat.c b/test/qes_seqcat.c
new file mode 100644
index 0000000..4b1aade
--- /dev/null
+++ b/test/qes_seqcat.c
@@ -0,0 +1,30 @@
+#include "qes_config.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <qes_seqfile.h>
+
+int main(int argc, char *argv[])
+{
+ if (argc < 2) return 1;
+ const char *fname = argv[1];
+ struct qes_seq *seq = qes_seq_create();
+ struct qes_seqfile *sf = qes_seqfile_create(fname, "r");
+ ssize_t res = 0;
+ while((res = qes_seqfile_read(sf, seq)) > 0) {
+ if (seq->qual.len < 1) {
+ // fasta
+ printf(">%s %s\n", seq->name.str, seq->comment.str);
+ puts(seq->seq.str);
+ } else {
+ // fastq
+ printf("@%s %s\n", seq->name.str, seq->comment.str);
+ puts(seq->seq.str);
+ puts("+");
+ puts(seq->qual.str);
+ }
+ }
+ qes_seqfile_destroy(sf);
+ qes_seq_destroy(seq);
+ return 0;
+}
diff --git a/test/qes_seqprint.c b/test/qes_seqprint.c
new file mode 100644
index 0000000..773550c
--- /dev/null
+++ b/test/qes_seqprint.c
@@ -0,0 +1,21 @@
+#include "qes_config.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <qes_seqfile.h>
+
+int main(int argc, char *argv[])
+{
+ if (argc < 2) return 1;
+ const char *fname = argv[1];
+ struct qes_seq *seq = qes_seq_create();
+ struct qes_seqfile *sf = qes_seqfile_create(fname, "r");
+ ssize_t res = 0;
+ while((res = qes_seqfile_read(sf, seq)) > 0) {
+ int fasta = seq->qual.len < 1;
+ qes_seq_print(seq, stdout, fasta, 0);
+ }
+ qes_seqfile_destroy(sf);
+ qes_seq_destroy(seq);
+ return 0;
+}
diff --git a/test/test_seq.c b/test/test_seq.c
index 5494aa5..c9dca23 100644
--- a/test/test_seq.c
+++ b/test/test_seq.c
@@ -260,7 +260,7 @@ test_qes_seq_print(void *ptr)
res = qes_seq_fill(seq, "TEST", "Comment 1", "AGCT", "IIII");
tt_int_op(res, ==, 0);
/* Print the seq to the output file */
- res = qes_seq_print(seq, fp);
+ res = qes_seq_print(seq, fp, false, 0);
tt_int_op(res, ==, 0);
/* Check printing */
truthfile = find_data_file("truth/qes_seq_print.fq");
@@ -280,7 +280,7 @@ test_qes_seq_print(void *ptr)
res = qes_seq_fill(seq, "TEST", "Comment 1", "AGCT", "");
tt_int_op(res, ==, 0);
/* Print the seq to the output file */
- res = qes_seq_print(seq, fp);
+ res = qes_seq_print(seq, fp, true, 0);
tt_int_op(res, ==, 0);
/* Check printing */
truthfile = find_data_file("truth/qes_seq_print.fa");
@@ -292,8 +292,8 @@ test_qes_seq_print(void *ptr)
fp = NULL;
/* error cases */
- tt_int_op(qes_seq_print(NULL, stdout), ==, 1);
- tt_int_op(qes_seq_print(seq, NULL), ==, 1);
+ tt_int_op(qes_seq_print(NULL, stdout, false, 0), ==, 1);
+ tt_int_op(qes_seq_print(seq, NULL, false, 0), ==, 1);
end:
qes_seq_destroy(seq);
diff --git a/test/test_seqcats.sh b/test/test_seqcats.sh
new file mode 100644
index 0000000..120bc92
--- /dev/null
+++ b/test/test_seqcats.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+if [ $# -lt 1 ]
+then
+ files=("data/test.fasta")
+else
+ files=( "$@" )
+fi
+
+for file in "${files[@]}"
+do
+ kseq_m5=$(bin/kseqcat $file | md5sum | awk '{print $1}')
+ qseq_m5=$(bin/qes_seqcat $file | md5sum | awk '{print $1}')
+ kprint_m5=$(bin/kseqcat $file | seqtk seq -l 79 | md5sum | awk '{print $1}')
+ qprint_m5=$(bin/qes_seqprint $file | md5sum | awk '{print $1}')
+
+ if [ "$kseq_m5" != "$qseq_m5" ]
+ then
+ echo "TEST (seq) FAILED: $file"
+ echo " kseq: $kseq_m5"
+ echo " qes: $qseq_m5"
+ else
+ echo "TEST (seq) PASSED: $file"
+ fi
+
+ if [ "$kprint_m5" != "$qprint_m5" ]
+ then
+ echo "TEST (print) FAILED: $file"
+ echo " kseq: $kprint_m5"
+ echo " qes: $qprint_m5"
+ else
+ echo "TEST (print) PASSED: $file"
+ fi
+done
diff --git a/test/test_seqfile.c b/test/test_seqfile.c
index 759275f..710ea60 100644
--- a/test/test_seqfile.c
+++ b/test/test_seqfile.c
@@ -309,7 +309,7 @@ test_qes_seqfile_read_vs_kseq (void *ptr)
free(fname);
/* Try again, with fasta */
seq = qes_seq_create();
- fname = find_data_file("test.fasta");
+ fname = find_data_file("test_large.fasta.gz");
tt_assert(fname != NULL);
sf = qes_seqfile_create(fname, "r");
#ifdef ZLIB_FOUND
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/libqes.git
More information about the debian-med-commit
mailing list