c086f66e9a26b985f97f473166189ed70301fc10
braney
  Tue Jun 13 11:42:10 2017 -0700
fix a bug where unaligned sequences were causing a crash

diff --git src/lib/bamFile.c src/lib/bamFile.c
index a70dfc8..a725ef8 100644
--- src/lib/bamFile.c
+++ src/lib/bamFile.c
@@ -577,30 +577,34 @@
     else if (type == 'f') { dyStringPrintf(dy, "%g", *(float*)s); s += 4; }
     else if (type == 'd') { dyStringPrintf(dy, "%lg", *(double*)s); s += 8; }
     else if (type == 'Z' || type == 'H')
 	{
 	dyStringAppend(dy, (char *)s);
 	s += strlen((char *)s) + 1;
 	}
     }
 }
 
 struct psl *bamToPslUnscored(const bam1_t *bam, const bam_hdr_t *hdr)
 /* Translate BAM's numeric CIGAR encoding into PSL sufficient for cds.c (just coords,
  * no scoring info) */
 {
 const bam1_core_t *core = &bam->core;
+
+if (core->tid == -1)
+    return NULL;
+
 struct psl *psl;
 AllocVar(psl);
 boolean isRc = (core->flag & BAM_FREVERSE);
 psl->strand[0] = isRc ? '-' : '+';
 psl->qName = cloneString(bam1_qname(bam));
 psl->tName = cloneString(hdr->target_name[core->tid]);
 unsigned blockCount = 0;
 unsigned *blockSizes, *qStarts, *tStarts;
 AllocArray(blockSizes, core->n_cigar);
 AllocArray(qStarts, core->n_cigar);
 AllocArray(tStarts, core->n_cigar);
 int tPos = core->pos, qPos = 0, qLength = 0;
 unsigned int *cigar = bam1_cigar(bam);
 int i;
 for (i = 0;  i < core->n_cigar;  i++)