JWS-112 Bumping version of ClustalO (src, binaries and windows) to version 1.2.4.
[jabaws.git] / binaries / src / clustalo / src / squid / a2m.c
index 35d4a37..b5032ff 100644 (file)
@@ -11,7 +11,7 @@
  * 
  * reading/writing A2M (aligned FASTA) files.
  * 
- * RCS $Id: a2m.c 242 2011-05-27 14:04:21Z andreas $ (Original squid RCS Id: a2m.c,v 1.1 1999/07/15 22:26:40 eddy Exp)
+ * RCS $Id: a2m.c 297 2014-10-31 13:02:37Z fabian $ (Original squid RCS Id: a2m.c,v 1.1 1999/07/15 22:26:40 eddy Exp)
  */
 
 #include <stdio.h>
@@ -91,44 +91,66 @@ ReadA2M(MSAFILE *afp)
  */
 void
 #ifdef CLUSTALO
-WriteA2M(FILE *fp, MSA *msa, int vienna)
+/*WriteA2M(FILE *fp, MSA *msa, int vienna)*/
+WriteA2M(FILE *fp, MSA *msa, int iWrap)
 #else
 WriteA2M(FILE *fp, MSA *msa)
 #endif
 {
   int  idx;                    /* sequence index */
   int  pos;                    /* position in sequence */
+#ifdef CLUSTALO
+  char  *buf;                   /* buffer for writing seq        */
+  int    cpl = msa->alen<iWrap ? msa->alen+10 : (iWrap > 0 ? iWrap : 60);          /* char per line (< 64)          */
+#else
   char buf[64];                        /* buffer for individual lines */
   int  cpl = 60;               /* char per line; must be < 64 unless buf is bigger */
-
+#endif
+  
+#ifdef CLUSTALO
+  if (NULL == (buf = (char *)malloc(cpl+20))){
+    Die("%s:%s:%d: could not malloc %d char for buffer",
+        __FUNCTION__, __FILE__, __LINE__, cpl+20);
+  }
+  else {
+    memset(buf, 0, cpl+20);
+  }
+#endif
+  
+  
   buf[cpl] = '\0';
   for (idx = 0; idx < msa->nseq; idx++)
     {
 #ifdef CLUSTALO
-               /* most fasta sequences don't have a description, which
-         * leads to a trailing white space in the original code 
-                */
-               fprintf(fp, ">%s",  msa->sqname[idx]);
-
-        if (msa->sqdesc != NULL && msa->sqdesc[idx] != NULL && !vienna) {
-            fprintf(fp, " %s", msa->sqdesc[idx]);
-        }
-        fprintf(fp, "\n");
+      /* most fasta sequences don't have a description, which
+       * leads to a trailing white space in the original code 
+       */
+      fprintf(fp, ">%s",  msa->sqname[idx]);
+      
+      if (msa->sqdesc != NULL && msa->sqdesc[idx] != NULL /*&& !vienna*/) {
+       fprintf(fp, " %s", msa->sqdesc[idx]);
+      }
+      fprintf(fp, "\n");
 #else
-        fprintf(fp, ">%s %s\n", 
-                msa->sqname[idx],
-                (msa->sqdesc != NULL && msa->sqdesc[idx] != NULL) ? msa->sqdesc[idx] : "");
+      fprintf(fp, ">%s %s\n", 
+             msa->sqname[idx],
+             (msa->sqdesc != NULL && msa->sqdesc[idx] != NULL) ? msa->sqdesc[idx] : "");
 #endif
-        for (pos = 0; pos < msa->alen; pos+=cpl)
+      for (pos = 0; pos < msa->alen; pos+=cpl)
         {
-            strncpy(buf, &(msa->aseq[idx][pos]), cpl);
-                       if (vienna)
-                           fprintf(fp, "%s", buf);
-                       else
-                               fprintf(fp, "%s\n", buf);
+         strncpy(buf, &(msa->aseq[idx][pos]), cpl);
+         /*if (vienna)
+           fprintf(fp, "%s", buf);
+           else*/
+         fprintf(fp, "%s\n", buf);
         }
-               if (vienna)
-                   fprintf(fp, "\n");
-
+      /*if (vienna)
+       fprintf(fp, "\n");*/
+      
     }
-}
+
+#ifdef CLUSTALO
+  free(buf); buf = NULL;
+#endif
+
+} /* this is the end of WriteA2M() */