From: Heng Li Date: Fri, 27 Nov 2009 15:44:56 +0000 (+0000) Subject: * samtools-0.1.7-1 (r515) X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=9215c0998a15d7ebc82baf78ded2443c55a1bc93;p=samtools.git * samtools-0.1.7-1 (r515) * report an error when .fai contains duplicated names, instead of segfault --- diff --git a/bam_import.c b/bam_import.c index 9d463d1..3a4a5cd 100644 --- a/bam_import.c +++ b/bam_import.c @@ -116,7 +116,7 @@ static bam_header_t *hash2header(const kh_ref_t *hash) bam_header_t *sam_header_read2(const char *fn) { bam_header_t *header; - int c, dret, ret; + int c, dret, ret, error = 0; gzFile fp; kstream_t *ks; kstring_t *str; @@ -135,6 +135,10 @@ bam_header_t *sam_header_read2(const char *fn) ks_getuntil(ks, 0, str, &dret); len = atoi(str->s); k = kh_put(ref, hash, s, &ret); + if (ret == 0) { + fprintf(stderr, "[sam_header_read2] duplicated sequence name: %s\n", s); + error = 1; + } kh_value(hash, k) = (uint64_t)len<<32 | i; if (dret != '\n') while ((c = ks_getc(ks)) != '\n' && c != -1); @@ -143,6 +147,7 @@ bam_header_t *sam_header_read2(const char *fn) gzclose(fp); free(str->s); free(str); fprintf(stderr, "[sam_header_read2] %d sequences loaded.\n", kh_size(hash)); + if (error) return 0; header = hash2header(hash); kh_destroy(ref, hash); return header; diff --git a/bamtk.c b/bamtk.c index 48ac76b..2c7e4f0 100644 --- a/bamtk.c +++ b/bamtk.c @@ -9,7 +9,7 @@ #endif #ifndef PACKAGE_VERSION -#define PACKAGE_VERSION "0.1.7 (r510)" +#define PACKAGE_VERSION "0.1.7-1 (r515)" #endif int bam_taf2baf(int argc, char *argv[]); diff --git a/misc/wgsim_eval.pl b/misc/wgsim_eval.pl index 01038f1..d3d9c61 100755 --- a/misc/wgsim_eval.pl +++ b/misc/wgsim_eval.pl @@ -12,9 +12,9 @@ exit; sub wgsim_eval { my %opts = (g=>5); - getopts('pcg:', \%opts); - die("Usage: wgsim_eval.pl [-pc] [-g $opts{g}] \n") if (@ARGV == 0 && -t STDIN); - my (@c0, @c1); + getopts('pcag:', \%opts); + die("Usage: wgsim_eval.pl [-pca] [-g $opts{g}] \n") if (@ARGV == 0 && -t STDIN); + my (@c0, @c1, %fnfp); my ($max_q, $flag) = (0, 0); my $gap = $opts{g}; $flag |= 1 if (defined $opts{p}); @@ -66,14 +66,26 @@ sub wgsim_eval { } ++$c0[$q]; ++$c1[$q] unless ($is_correct); + @{$fnfp{$t[4]}} = (0, 0) unless (defined $fnfp{$t[4]}); + ++$fnfp{$t[4]}[0]; + ++$fnfp{$t[4]}[1] unless ($is_correct); print STDERR $line if (($flag&1) && !$is_correct && $q > 0); } # print my ($cc0, $cc1) = (0, 0); - for (my $i = $max_q; $i >= 0; --$i) { - $c0[$i] = 0 unless (defined $c0[$i]); - $c1[$i] = 0 unless (defined $c1[$i]); - $cc0 += $c0[$i]; $cc1 += $c1[$i]; - printf("%.2dx %12d / %-12d %12d %.3e\n", $i, $c1[$i], $c0[$i], $cc0, $cc1/$cc0); + if (!defined($opts{a})) { + for (my $i = $max_q; $i >= 0; --$i) { + $c0[$i] = 0 unless (defined $c0[$i]); + $c1[$i] = 0 unless (defined $c1[$i]); + $cc0 += $c0[$i]; $cc1 += $c1[$i]; + printf("%.2dx %12d / %-12d %12d %.3e\n", $i, $c1[$i], $c0[$i], $cc0, $cc1/$cc0); + } + } else { + for (reverse(sort {$a<=>$b} (keys %fnfp))) { + next if ($_ == 0); + $cc0 += $fnfp{$_}[0]; + $cc1 += $fnfp{$_}[1]; + print join("\t", $_, $cc0, $cc1), "\n"; + } } } diff --git a/sam.c b/sam.c index ad4325b..ecdee02 100644 --- a/sam.c +++ b/sam.c @@ -55,6 +55,7 @@ samfile_t *samopen(const char *fn, const char *mode, const void *aux) if (aux) { // check if aux is present bam_header_t *textheader = fp->header; fp->header = sam_header_read2((const char*)aux); + if (fp->header == 0) goto open_err_ret; append_header_text(fp->header, textheader->text, textheader->l_text); bam_header_destroy(textheader); }