src/hg/lib/lsSnpPdbChimera.c 1.4

1.4 2009/05/13 19:05:17 markd
added prototype support for launching 3D structure browser on H1N1 predicted structures
Index: src/hg/lib/lsSnpPdbChimera.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/lib/lsSnpPdbChimera.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -b -B -U 4 -r1.3 -r1.4
--- src/hg/lib/lsSnpPdbChimera.c	5 Feb 2009 08:05:16 -0000	1.3
+++ src/hg/lib/lsSnpPdbChimera.c	13 May 2009 19:05:17 -0000	1.4
@@ -48,8 +48,27 @@
 fprintf(xfh, "(\"%s\", \"%c\", %d,%s), ", pdbSnp->snpId, pdbSnp->chain,
         pdbSnp->snpPdbLoc, (isPrimary ? " True" : ""));
 }
 
+static FILE *chimeraxBegin(char *outName)
+/* open chimerax file and write XML and python function definitions */
+{
+FILE *xfh = mustOpen(outName, "w");
+fputs(chimeraxHead, xfh);
+
+FILE *pxf = mustOpen(chimeraxPythonFile, "r");
+copyOpenFile(pxf, xfh);
+carefulClose(&pxf);
+return xfh;
+}
+
+static void chimeraxEnd(FILE **xfhPtr)
+/* finish writing XML and close chimerax function */
+{
+fputs(chimeraxTail, *xfhPtr);
+carefulClose(xfhPtr);
+}
+
 static void chimeraxGen(struct sqlConnection *conn,
                         char *pdbId, char *where,
                         char *primarySnpId,
                         char *outName)
@@ -57,14 +76,9 @@
  * primarySnpId differently.  The where arguments specifies which entries to
  * obtain from the lsSnpPdb table.
  */
 {
-FILE *xfh = mustOpen(outName, "w");
-fputs(chimeraxHead, xfh);
-
-FILE *pxf = mustOpen(chimeraxPythonFile, "r");
-copyOpenFile(pxf, xfh);
-carefulClose(&pxf);
+FILE *xfh = chimeraxBegin(outName);
 
 fprintf(xfh, "\ndisplayPdb(\"%s\", (", pdbId);
 
 struct lsSnpPdb *pdbSnp, *pdbSnps = NULL;
@@ -78,10 +92,9 @@
 lsSnpPdbFreeList(&pdbSnps);
 
 fprintf(xfh, "))\n");
 
-fputs(chimeraxTail, xfh);
-carefulClose(&xfh);
+chimeraxEnd(&xfh);
 }
 
 void lsSnpPdbChimeraSnpAnn(struct sqlConnection *conn,
                            char *pdbId, char *primarySnpId,
@@ -159,4 +172,24 @@
 if (snpId != NULL)
     safecat(url, sizeof(url), fmtParam(sep, "snpId", snpId));
 return cloneString(url);
 }
+
+void lsSnpPdbChimeraGenericLink(char *pdbSpec, char *script,
+                                char *trashDirName, char *trashBaseName,
+                                struct tempName *chimerax)
+/* Generate a chimerax file for the given pdbSpec, which can be a PDB id or a
+ * URL.  Copies in the lsSnpPdbChimera.py file and then adds optional script python code.
+ * Fills in chimerax structure.
+ * FIXME: This is an experiment for H1N1 flu browser, this function has
+ * nothing to do with LS/SNP.  If we decide to keep this, this should be
+ * split into a generic chimera module.
+ */
+{
+trashDirFile(chimerax, trashDirName, trashBaseName, ".chimerax");
+FILE *xfh = chimeraxBegin(chimerax->forCgi);
+fprintf(xfh, "\ndisplayPdb(\"%s\", ())\n", pdbSpec);
+if (script != NULL)
+    fputs(script, xfh);
+chimeraxEnd(&xfh);
+}
+