Skip to content

Commit

Permalink
Merge pull request #50 from wtsi-npg/devel
Browse files Browse the repository at this point in the history
release 0.9.5 prep
  • Loading branch information
dozy authored Feb 2, 2017
2 parents 9304626 + bcc0f9a commit d76a149
Show file tree
Hide file tree
Showing 28 changed files with 1,327 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ matrix:
include:
- os: linux
compiler: clang
env: CFLAGS="-Wno-pointer-sign""
- os: linux
compiler: gcc
- os: linux
compiler: gcc
env: CFLAGS="-std=gnu99 -O0"

env:
global:
Expand Down
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ TESTS = test/t_array \
test/t_decode \
test/t_filterfile \
test/t_posfile \
test/t_i2b
test/t_i2b \
test/t_read2tags
SUBDIRS = src test
dist_doc_DATA = README.md LICENSE
AM_COLOR_TESTS=always
8 changes: 4 additions & 4 deletions src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
AM_CPPFLAGS = $(HTSLIB_CPPFLAGS) -std=gnu99
AM_CPPFLAGS = $(HTSLIB_CPPFLAGS) -std=gnu99 -Werror
AM_LDFLAGS = -rdynamic $(HTSLIB_LDFLAGS)

bin_PROGRAMS = bambi
bambi_SOURCES = bambi.c bclfile.c decode.c filterfile.c hts_addendum.c i2b.c posfile.c array.c select.c \
bambi.h bclfile.h filterfile.h hts_addendum.h posfile.h array.h \
parse.c bamit.c chrsplit.c\
bambi_SOURCES = bambi.c bclfile.c decode.c filterfile.c hts_addendum.c i2b.c posfile.c array.c select.c \
bambi.h bclfile.h filterfile.h hts_addendum.h posfile.h array.h \
parse.c bamit.c chrsplit.c read2tags.c \
parse.h bamit.h
nobase_include_HEADERS = cram/cram_samtools.h cram/pooled_alloc.h cram/sam_header.h cram/string_alloc.h
bambi_CFLAGS = -I/usr/include/libxml2
Expand Down
15 changes: 15 additions & 0 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ void va_free(va_t *va)
free(va);
}

/*
* join entries into a 'delim' separated list
* NB assumes that entries are strings
*/
char *va_join(va_t *va, char *delim)
{
int m = 64;
Expand All @@ -140,4 +144,15 @@ char *va_join(va_t *va, char *delim)
return s;
}

/*
* return array number containing 's', or -1 if not found
* NB assumes all entries are strings
*/
int va_contains(va_t *va, char *s)
{
for (int n=0; n < va->end; n++) {
if (strcmp(va->entries[n],s) == 0) return n;
}
return -1;
}

3 changes: 3 additions & 0 deletions src/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ va_t *va_init(int max, void(*free_entry)(void*));
void va_push(va_t *va, void *ent);
void va_free(va_t *va);
static inline bool va_isEmpty(va_t *va) { return va->end == 0; }

// NB these functions assume an array of strings
char *va_join(va_t *va, char *delim);
int va_contains(va_t *va, char *s);

#endif

3 changes: 3 additions & 0 deletions src/bambi.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ int main_decode(int argc, char *argv[]);
int main_i2b(int argc, char *argv[]);
int main_select(int argc, char *argv[]);
int main_chrsplit(int argc, char *argv[]);
int main_read2tags(int argc, char *argv[]);

const char *bambi_version()
{
Expand Down Expand Up @@ -83,6 +84,7 @@ static void usage(FILE *fp)
" i2b converts illumina files to SAM/BAM/CRAM files\n"
" select select reads by alignment\n"
" chrsplit split reads by chromosome\n"
" read2tags convert reads into tags\n"
"\n"
"bambi <command> for help on a particular command\n"
"\n");
Expand All @@ -107,6 +109,7 @@ int main(int argc, char *argv[])
else if (strcmp(argv[1], "i2b") == 0) ret = main_i2b(argc-1, argv+1);
else if (strcmp(argv[1], "select") == 0) ret = main_select(argc-1, argv+1);
else if (strcmp(argv[1], "chrsplit") == 0) ret = main_chrsplit(argc-1, argv+1);
else if (strcmp(argv[1], "read2tags") == 0) ret = main_read2tags(argc-1, argv+1);
else if (strcmp(argv[1], "--version") == 0) {
printf( "bambi %s\n"
"Using htslib %s\n"
Expand Down
38 changes: 38 additions & 0 deletions src/bamit.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>

#include "bamit.h"

BAMit_t *BAMit_init(samFile *f, bam_hdr_t *h)
Expand All @@ -30,6 +32,42 @@ BAMit_t *BAMit_init(samFile *f, bam_hdr_t *h)
return bit;
}

/*
* Open a BAM file
* arguments are: char *fname filename to open
* char mode 'r' or 'w'
* char *fmt format [bam,sam,cram]
* char compression level [0..9]
*/
BAMit_t *BAMit_open(char *fname, char mode, char *fmt, char compression_level)
{
samFile *f = NULL;
bam_hdr_t *h = NULL;
htsFormat *format = NULL;
char m[] = "xbC";

if (fmt) {
format = calloc(1,sizeof(htsFormat));
if (hts_parse_format(format, fmt) < 0) {
fprintf(stderr,"Unknown input format: %s\n", fmt);
exit(1);
}
}
m[0] = mode;
m[2] = compression_level;
f = hts_open_format(fname, m, format);
free(format);
if (!f) {
fprintf(stderr,"Could not open file (%s)\n", fname);
exit(1);
}

if (mode == 'r') h = sam_hdr_read(f);
else h = bam_hdr_init();

return BAMit_init(f,h);
}

void BAMit_free(void *ptr)
{
BAMit_t *bit = (BAMit_t *)ptr;
Expand Down
32 changes: 31 additions & 1 deletion src/bamit.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,41 @@ typedef struct {
bam1_t *nextRec;
} BAMit_t;

/*
* Open a BAM file
* arguments are: char *fname filename to open
* char mode 'r' or 'w'
* char *fmt format [bam,sam,cram] or NULL
* char compression level [0..9] or NULL
*/
BAMit_t *BAMit_open(char *fname, char mode, char *fmt, char compression_level);

/*
* initialise with open file pointer and header
*/
BAMit_t *BAMit_init(samFile *f, bam_hdr_t *h);
void BAMit_free(void *bit);

/*
* read next record and advance to next record
*/
bam1_t *BAMit_next(BAMit_t *bit);

/*
* read next record *without* advancing to next record
*/

bam1_t *BAMit_peek(BAMit_t *bit);

/*
* return true if there is a next record
*/

bool BAMit_hasnext(BAMit_t *bit);

/*
* free data and close file
*/
void BAMit_free(void *bit);

#endif

Loading

0 comments on commit d76a149

Please sign in to comment.