src/hg/hgTracks/bedTrack.c 1.14

1.14 2009/06/15 21:05:12 mikep
fixing - strandness problem with paired tag align data
Index: src/hg/hgTracks/bedTrack.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/hgTracks/bedTrack.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -b -B -U 4 -r1.13 -r1.14
--- src/hg/hgTracks/bedTrack.c	29 May 2009 17:28:25 -0000	1.13
+++ src/hg/hgTracks/bedTrack.c	15 Jun 2009 21:05:12 -0000	1.14
@@ -691,8 +691,10 @@
     AllocVar(lf);
     lf->start = lf->tallStart = b->chromStart;
     lf->end = lf->tallEnd = b->chromEnd;
     lf->components = NULL;
+    if (bedFields > 5) // need to know orientation before checking if paired
+	lf->orientation = (b->strand[0] == '+' ? 1 : (b->strand[0] == '-' ? -1 : 0)); 
     if (paired)
 	{
 	// Find seq1 & seq2, strip them from the name,
 	// add them as two blocks of simpleFeatures,
@@ -712,10 +714,17 @@
 	struct dyString *d = dyStringNew(l1+l2+1);
 	dyStringAppend(d, seq1);
 	dyStringAppend(d, seq2);
 	lf->extra = newDnaSeq(dyStringCannibalize(&d), l1+l2, lf->name);
-	addSimpleFeatures(&lf->components, lf->start, lf->start + l1, 0, everyBase);
-	addSimpleFeatures(&lf->components, lf->end - l2, lf->end, l1, everyBase);
+	// seq1 + seq2 are concatenated for drawing code
+	// in - orientation they are also reverse complemented, 
+	// and the query start is relative to the reverse complement, so:
+	// in + orientation first feature (f1) is seq1, second (f2) is seq2
+	// in - orientation first feature (f1) is seq2, second (f2) is seq1
+	int f1 = lf->orientation == -1 ? l2 : l1;
+	int f2 = lf->orientation == -1 ? l1 : l2;
+	addSimpleFeatures(&lf->components, lf->start, lf->start + f1, 0, everyBase);
+	addSimpleFeatures(&lf->components, lf->end - f2, lf->end, f1, everyBase);
 	}
     else
 	{
 	addSimpleFeatures(&lf->components, lf->start, lf->end, 0, everyBase);
@@ -724,10 +733,8 @@
     if (bedFields > 3)
 	safecpy(lf->name, sizeof(lf->name), b->name);
     if (bedFields > 4)
 	lf->score = b->score;
-    if (bedFields > 5)
-	lf->orientation = (b->strand[0] == '+' ? 1 : (b->strand[0] == '-' ? -1 : 0)); 
     lf->original = b;
     }
 return lf;
 }