src/lib/dnaMotif.c 1.5

1.5 2009/09/07 23:40:22 markd
added option to control minimum height of a sequence logo column
Index: src/lib/dnaMotif.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/dnaMotif.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -b -B -U 4 -r1.4 -r1.5
--- src/lib/dnaMotif.c	14 Sep 2006 21:08:24 -0000	1.4
+++ src/lib/dnaMotif.c	7 Sep 2009 23:40:22 -0000	1.5
@@ -385,10 +385,15 @@
 *retWidth = ceil(widthPerBase * motif->columnCount) + widthFudgeFactor;
 *retHeight = ceil(height) + heightFudgeFactor;
 }
 
-void dnaMotifToLogoPs(struct dnaMotif *motif, double widthPerBase, double height, char *fileName)
-/* Write logo corresponding to motif to postScript file. */
+void dnaMotifToLogoPs2(struct dnaMotif *motif, double widthPerBase, double height, 
+                       double minHeight, char *fileName)
+/* Write logo corresponding to motif to postScript file, with extended options. minHeight
+ * is the minimum height that is excluded from information content scaling.  This allows
+ * something to show up in columns with very little information content.  Setting this
+ * to be the same as height creates an frequency-based logo.
+ */
 {
 FILE *f = mustOpen(fileName, "w");
 int i;
 int xStart = 0;
@@ -406,15 +411,25 @@
 
 for (i=0; i<motif->columnCount; ++i)
     {
     double infoScale = dnaMotifBitsOfInfo(motif, i)/2.0;
-    psOneColumn(motif, i, xStart, 0, widthPerBase, infoScale * height, f);
+    // only scale part beyond minHeight
+    double useHeight = minHeight + (infoScale * (height - minHeight));
+    if (useHeight > height)
+        useHeight = height;
+    psOneColumn(motif, i, xStart, 0, widthPerBase, useHeight, f);
     xStart += widthPerBase;
     }
 fprintf(f, "showpage\n");
 carefulClose(&f);
 }
 
+void dnaMotifToLogoPs(struct dnaMotif *motif, double widthPerBase, double height, char *fileName)
+/* Write logo corresponding to motif to postScript file. */
+{
+dnaMotifToLogoPs2(motif, widthPerBase, height, 0.0, fileName);
+}
+
 void dnaMotifToLogoPng(
 	struct dnaMotif *motif,	/* Motif to draw. */
 	double widthPerBase, 	/* Width of each base. */
 	double height, 		/* Max height. */