Skip to content

Commit

Permalink
Merge branch 'release/1.13.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
David Jones committed Feb 23, 2016
2 parents 96c3198 + 53d96d6 commit b8201e2
Show file tree
Hide file tree
Showing 18 changed files with 1,315 additions and 208 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 1.13.0
* bam_stats - Unit tests for C code
* bam_stats - Fix to median insert size calculation

### 1.11.0
* bam_stats - new rna switch to give more appropriate insert size stats
* bam_stats - more robust handling of optional RG header entries
Expand Down
10 changes: 10 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ bin/xml_to_bas.pl
c/bam_access.c
c/bam_access.h
c/bam_stats.c
c/bam_stats_calcs.c
c/bam_stats_calcs.h
c/bam_stats_output.c
c/bam_stats_output.h
c/c_tests/bam_access_tests.c
c/c_tests/bam_stats_calcs_tests.c
c/c_tests/bam_stats_output_tests.c
c/c_tests/minunit.h
c/c_tests/runtests.sh
c/dbg.h
c/khash.h
CHANGES.md
Expand Down Expand Up @@ -68,6 +77,7 @@ t/data/paired.bam
t/data/reconcile_bas.bam
t/data/Stats.bam
t/data/Stats.bam.bas
t/data/Stats.c.bam.bas
t/data/test.bam.bas
t/data/unpaired.bam
t/pcap.t
Expand Down
10 changes: 5 additions & 5 deletions c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ LFLAGS?= -L$(HTSTMP)
LIBS =-lhts -lpthread -lz -lm

# define the C source files
SRCS = ./bam_access.c ./bam_stats.c
SRCS = ./bam_access.c ./bam_stats_output.c ./bam_stats_calcs.c
#Define test sources
TEST_SRC=$(wildcard ./tests/*_tests.c)
TEST_SRC=$(wildcard ./c_tests/*_tests.c)
TESTS=$(patsubst %.c,%,$(TEST_SRC))

# define the C object files
Expand Down Expand Up @@ -60,17 +60,17 @@ BAM_STATS_TARGET=../bin/bam_stats

.NOTPARALLEL: test

all: clean make_htslib_tmp $(BAM_STATS_TARGET) remove_htslib_tmp
all: clean make_htslib_tmp $(BAM_STATS_TARGET) test remove_htslib_tmp
@echo bam_stats compiled.

$(BAM_STATS_TARGET): $(OBJS)
$(CC) $(CFLAGS) $(INCLUDES) -o $(BAM_STATS_TARGET) $(OBJS) $(LFLAGS) $(LIBS)
$(CC) $(CFLAGS) $(INCLUDES) -o $(BAM_STATS_TARGET) $(OBJS) $(LFLAGS) $(LIBS) ./bam_stats.c

#Unit Tests
test: $(BAM_STATS_TARGET)
test: CFLAGS += $(INCLUDES) $(OBJS) $(LFLAGS) $(LIBS)
test: $(TESTS)
sh ./tests/runtests.sh
sh ./c_tests/runtests.sh

#Unit tests with coverage
coverage: CFLAGS += --coverage
Expand Down
19 changes: 10 additions & 9 deletions c/bam_access.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* LICENCE
* PCAP - NGS reference implementations and helper code for the ICGC/TCGA Pan-Cancer Analysis Project
* Copyright (C) 2014 ICGC PanCancer Project
* Copyright (C) 2014-2016 ICGC PanCancer Project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -21,6 +21,7 @@
#include <stdio.h>
#include <string.h>
#include "bam_access.h"
#include "bam_stats_calcs.h"

int get_rg_index_from_rg_store(rg_info_t **grps, char *rg, int grps_size){
int i=0;
Expand All @@ -35,9 +36,9 @@ void parse_rg_line(char *tmp_line, rg_info_t *group) {
char *tag = strtok(tmp_line,"\t");
assert(strcmp(tag,"@RG")==0);
group->id = strdup("\0");
group->sample = strdup("\0");
group->platform = strdup("\0");
group->platform_unit = strdup("\0");
group->sample = strdup("\0");
group->platform = strdup("\0");
group->platform_unit = strdup("\0");
group->lib = strdup("\0");
tag = strtok(NULL,"\t");
while(tag != NULL){
Expand All @@ -55,7 +56,7 @@ void parse_rg_line(char *tmp_line, rg_info_t *group) {
return;
}

rg_info_t **parse_header(bam_hdr_t *head, int *grps_size, stats_rd_t ****grp_stats){
rg_info_t **bam_access_parse_header(bam_hdr_t *head, int *grps_size, stats_rd_t ****grp_stats){
assert(head != NULL);
char *line = NULL;
rg_info_t **groups;
Expand Down Expand Up @@ -150,7 +151,7 @@ rg_info_t **parse_header(bam_hdr_t *head, int *grps_size, stats_rd_t ****grp_sta
return NULL;
}

int process_reads(htsFile *input, bam_hdr_t *head, rg_info_t **grps, int grps_size, stats_rd_t ****grp_stats, int rna){
int bam_access_process_reads(htsFile *input, bam_hdr_t *head, rg_info_t **grps, int grps_size, stats_rd_t ****grp_stats, int rna){
assert(input != NULL);
assert(head != NULL);
assert(grps != NULL);
Expand Down Expand Up @@ -206,12 +207,12 @@ int process_reads(htsFile *input, bam_hdr_t *head, rg_info_t **grps, int grps_si
uint32_t nm_val = bam_aux2i(nm);
if(nm_val>0){
(*grp_stats)[rg_index][read]->divergent += nm_val;
(*grp_stats)[rg_index][read]->mapped_bases += get_mapped_base_count_from_cigar(b);
(*grp_stats)[rg_index][read]->mapped_bases += bam_access_get_mapped_base_count_from_cigar(b);
}else{
(*grp_stats)[rg_index][read]->mapped_bases += (bam_endpos(b) - b->core.pos) + 1;
}
}else{
(*grp_stats)[rg_index][read]->mapped_bases += get_mapped_base_count_from_cigar(b);
(*grp_stats)[rg_index][read]->mapped_bases += bam_access_get_mapped_base_count_from_cigar(b);
}

// Insert size can only be calculated based on reads that are on same chr
Expand All @@ -238,7 +239,7 @@ int process_reads(htsFile *input, bam_hdr_t *head, rg_info_t **grps, int grps_si
return -1;
}

uint64_t get_mapped_base_count_from_cigar(bam1_t *b){
uint64_t bam_access_get_mapped_base_count_from_cigar(bam1_t *b){
#define _cop(c) ((c)&BAM_CIGAR_MASK)
#define _cln(c) ((c)>>BAM_CIGAR_SHIFT)
assert(b != NULL);
Expand Down
10 changes: 5 additions & 5 deletions c/bam_access.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* LICENCE
* PCAP - NGS reference implementations and helper code for the ICGC/TCGA Pan-Cancer Analysis Project
* Copyright (C) 2014 ICGC PanCancer Project
* Copyright (C) 2014-2016 ICGC PanCancer Project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -25,8 +25,8 @@
#include <stdlib.h>
#include "htslib/sam.h"
#include "dbg.h"

#include "khash.h"

KHASH_MAP_INIT_INT(ins,uint64_t)
//KHASH_INIT2(ins,, khint32_t, uint64_t, 1, kh_int_hash_func, kh_int_hash_equal)

Expand All @@ -52,10 +52,10 @@ typedef struct{
char *sample;
} rg_info_t;

rg_info_t **parse_header(bam_hdr_t *head, int *grps_size, stats_rd_t ****grp_stats);
rg_info_t **bam_access_parse_header(bam_hdr_t *head, int *grps_size, stats_rd_t ****grp_stats);

int process_reads(htsFile *input, bam_hdr_t *head, rg_info_t **grps, int grps_size, stats_rd_t ****grp_stats, int rna);
int bam_access_process_reads(htsFile *input, bam_hdr_t *head, rg_info_t **grps, int grps_size, stats_rd_t ****grp_stats, int rna);

uint64_t get_mapped_base_count_from_cigar(bam1_t *b);
uint64_t bam_access_get_mapped_base_count_from_cigar(bam1_t *b);

#endif
Loading

0 comments on commit b8201e2

Please sign in to comment.