src/hg/lib/bamFile.c 1.10
1.10 2009/10/08 06:38:23 angie
Added support for bam as a custom track type.
Index: src/hg/lib/bamFile.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/lib/bamFile.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -b -B -U 4 -r1.9 -r1.10
--- src/hg/lib/bamFile.c 24 Sep 2009 04:33:50 -0000 1.9
+++ src/hg/lib/bamFile.c 8 Oct 2009 06:38:23 -0000 1.10
@@ -44,8 +44,23 @@
hFreeConn(&conn);
return fileName;
}
+boolean bamFileExists(char *bamFileName)
+/* Return TRUE if we can successfully open the bam file and its index file. */
+{
+samfile_t *fh = samopen(bamFileName, "rb", NULL);
+if (fh != NULL)
+ {
+ bam_index_t *idx = bam_index_load(bamFileName);
+ samclose(fh);
+ if (idx == NULL)
+ return FALSE;
+ return TRUE;
+ }
+return FALSE;
+}
+
void bamFetch(char *bamFileName, char *position, bam_fetch_f callbackFunc, void *callbackData)
/* Open the .bam file, fetch items in the seq:start-end position range,
* and call callbackFunc on each bam item retrieved from the file plus callbackData.
* Note: if sequences in .bam file don't begin with "chr" but cart position does, pass in
@@ -57,10 +72,10 @@
int chromId, start, end;
int ret = bam_parse_region(fh->header, position, &chromId, &start, &end);
if (ret != 0)
- errAbort("bam_parse_region(%s) failed (%d)", position, ret);
-//?? Could this happen if there is no data on some _random? can avoid with tdb chromosomes...
+ // If the bam file does not cover the current chromosome, OK
+ return;
bam_index_t *idx = bam_index_load(bamFileName);
if (idx == NULL)
errAbort("bam_index_load(%s) failed.", bamFileName);