static int treeGetCh (FILE *fp) /* get next nonblank, noncomment character */ { /* treeGetCh */ int ch; while ((ch = getc(fp)) != EOF) { if (whitechar(ch)) ; else if (ch == '[') { /* comment; find its end */ if ((ch = treeFinishCom(fp, (char **) NULL)) == EOF) break; } else break; } return ch; } /* treeGetCh */
static boolean lineContainsOnlyWhiteChars(char *line) { int i, n = strlen(line); if(n == 0) return TRUE; for(i = 0; i < n; i++) { if(!whitechar(line[i])) return FALSE; } return TRUE; }
static void treeEchoContext (FILE *fp1, FILE *fp2, int n) { /* treeEchoContext */ int ch; boolean waswhite; waswhite = TRUE; while (n > 0 && ((ch = getc(fp1)) != EOF)) { if (whitechar(ch)) { ch = waswhite ? '\0' : ' '; waswhite = TRUE; } else { waswhite = FALSE; } if (ch > '\0') {putc(ch, fp2); n--;} } } /* treeEchoContext */
FILE * collect(struct header *hp, int printheaders, struct message *mp, char *quotefile, int doprefix, int tflag) { FILE *fbuf; struct ignoretab *quoteig; int lc, cc, escape, eofcount; int c, t; char *linebuf = NULL, *cp, *quote = NULL; size_t linesize; char *tempMail = NULL; int getfields; sigset_t oset, nset; long count; enum sendaction action; sighandler_type savedtop; const char tildehelp[] = "-------------------- ~ ESCAPES ----------------------------\n\ ~~ Quote a single tilde\n\ ~@ [file ...] Edit attachment list\n\ ~b users Add users to \"blind\" cc list\n\ ~c users Add users to cc list\n\ ~d Read in dead.letter\n\ ~e Edit the message buffer\n\ ~f messages Read in messages without indenting lines\n\ ~F messages Same as ~f, but keep all header lines\n\ ~h Prompt for to list, subject, cc, and \"blind\" cc list\n\ ~r file Read a file into the message buffer\n\ ~p Print the message buffer\n\ ~q Abort message composition and save text to dead.letter\n\ ~m messages Read in messages with each line indented\n\ ~M messages Same as ~m, but keep all header lines\n\ ~s subject Set subject\n\ ~t users Add users to to list\n\ ~v Invoke display editor on message\n\ ~w file Write message onto file\n\ ~x Abort message composition and discard text written so far\n\ ~!command Invoke the shell\n\ ~:command Execute a regular command\n\ -----------------------------------------------------------\n"; (void) &escape; (void) &eofcount; (void) &getfields; (void) &tempMail; (void) &tflag; (void) "e; collf = NULL; /* * Start catching signals from here, but we're still die on interrupts * until we're in the main loop. */ sigemptyset(&nset); sigaddset(&nset, SIGINT); sigaddset(&nset, SIGHUP); sigprocmask(SIG_BLOCK, &nset, &oset); handlerpush(collint); if ((saveint = safe_signal(SIGINT, SIG_IGN)) != SIG_IGN) safe_signal(SIGINT, collint); if ((savehup = safe_signal(SIGHUP, SIG_IGN)) != SIG_IGN) safe_signal(SIGHUP, collhup); savetstp = safe_signal(SIGTSTP, collstop); savettou = safe_signal(SIGTTOU, collstop); savettin = safe_signal(SIGTTIN, collstop); if (sigsetjmp(collabort, 1)) { if (tempMail != NULL) { rm(tempMail); Ftfree(&tempMail); } goto err; } if (sigsetjmp(colljmp, 1)) { if (tempMail != NULL) { rm(tempMail); Ftfree(&tempMail); } goto err; } sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL); noreset++; if ((collf = Ftemp(&tempMail, "Rs", "w+", 0600, 1)) == NULL) { perror(catgets(catd, CATSET, 51, "temporary mail file")); goto err; } unlink(tempMail); Ftfree(&tempMail); if ((cp = value("MAILX_HEAD")) != NULL) { if (is_a_tty[0]) putesc(cp, stdout); putesc(cp, collf); } /* * If we are going to prompt for a subject, * refrain from printing a newline after * the headers (since some people mind). */ getfields = 0; if (!tflag) { t = GTO|GSUBJECT|GCC|GNL; if (value("fullnames")) t |= GCOMMA; if (hp->h_subject == NULL && value("interactive") != NULL && (value("ask") != NULL || value("asksub") != NULL)) t &= ~GNL, getfields |= GSUBJECT; if (hp->h_to == NULL && value("interactive") != NULL) t &= ~GNL, getfields |= GTO; if (value("bsdcompat") == NULL && value("askatend") == NULL && value("interactive")) { if (hp->h_bcc == NULL && value("askbcc")) t &= ~GNL, getfields |= GBCC; if (hp->h_cc == NULL && value("askcc")) t &= ~GNL, getfields |= GCC; } if (printheaders) { puthead(hp, stdout, t, SEND_TODISP, CONV_NONE, NULL, NULL); fflush(stdout); } } /* * Quote an original message */ if (mp != NULL && (doprefix || (quote = value("quote")) != NULL)) { quoteig = allignore; action = SEND_QUOTE; if (doprefix) { quoteig = fwdignore; if ((cp = value("fwdheading")) == NULL) cp = "-------- Original Message --------"; if (*cp) { fprintf(collf, "%s\n", cp); fprintf(stdout, "%s\n", cp); } } else if (strcmp(quote, "noheading") == 0) { /*EMPTY*/; } else if (strcmp(quote, "headers") == 0) { quoteig = ignore; } else if (strcmp(quote, "allheaders") == 0) { quoteig = NULL; action = SEND_QUOTE_ALL; } else { cp = hfield("from", mp); if (cp != NULL) { mime_write(cp, strlen(cp), collf, CONV_FROMHDR, TD_NONE, NULL, (size_t) 0, NULL, NULL); mime_write(cp, strlen(cp), stdout, CONV_FROMHDR, TD_NONE, NULL, (size_t) 0, NULL, NULL); fwrite(catgets(catd, CATSET, 52, " wrote:\n\n"), sizeof(char), 9, collf); fwrite(catgets(catd, CATSET, 52, " wrote:\n\n"), sizeof(char), 9, stdout); } } cp = value("indentprefix"); if (cp != NULL && *cp == '\0') cp = "\t"; send(mp, collf, quoteig, doprefix ? NULL : cp, action, NULL); send(mp, stdout, quoteig, doprefix ? NULL : cp, action, NULL); } if ((cp = value("escape")) != NULL) escape = *cp; else escape = ESCAPE; eofcount = 0; hadintr = 0; if (!sigsetjmp(colljmp, 1)) { if (getfields) grabh(hp, getfields, 1); if (quotefile != NULL) { if (include_file(NULL, quotefile, &lc, &cc, 1) != 0) goto err; } } else { /* * Come here for printing the after-signal message. * Duplicate messages won't be printed because * the write is aborted if we get a SIGTTOU. */ cont: if (hadintr) { fflush(stdout); fprintf(stderr, catgets(catd, CATSET, 53, "\n(Interrupt -- one more to kill letter)\n")); } else { printf(catgets(catd, CATSET, 54, "(continue)\n")); fflush(stdout); } } if (value("interactive") == NULL && tildeflag <= 0 && !is_a_tty[0] && !tflag) { /* * No tilde escapes, interrupts not expected. Copy * standard input the simple way. */ linebuf = srealloc(linebuf, linesize = BUFSIZ); while ((count = fread(linebuf, sizeof *linebuf, linesize, stdin)) > 0) { if (fwrite(linebuf, sizeof *linebuf, count, collf) != count) goto err; } goto out; } for (;;) { colljmp_p = 1; count = readline(stdin, &linebuf, &linesize); colljmp_p = 0; if (count < 0) { if (value("interactive") != NULL && value("ignoreeof") != NULL && ++eofcount < 25) { printf(catgets(catd, CATSET, 55, "Use \".\" to terminate letter\n")); continue; } break; } if (tflag && count == 0) { rewind(collf); if (makeheader(collf, hp) != OKAY) goto err; rewind(collf); tflag = 0; continue; } eofcount = 0; hadintr = 0; if (linebuf[0] == '.' && linebuf[1] == '\0' && value("interactive") != NULL && (value("dot") != NULL || value("ignoreeof") != NULL)) break; if (linebuf[0] != escape || (value("interactive") == NULL && tildeflag == 0 || tildeflag < 0)) { if (putline(collf, linebuf, count) < 0) goto err; continue; } c = linebuf[1]; switch (c) { default: /* * On double escape, just send the single one. * Otherwise, it's an error. */ if (c == escape) { if (putline(collf, &linebuf[1], count - 1) < 0) goto err; else break; } printf(catgets(catd, CATSET, 56, "Unknown tilde escape.\n")); break; #ifdef DEBUG_COMMANDS case 'C': /* * Dump core. */ core(NULL); break; #endif /* DEBUG_COMMANDS */ case '!': /* * Shell escape, send the balance of the * line to sh -c. */ shell(&linebuf[2]); break; case ':': case '_': /* * Escape to command mode, but be nice! */ inhook = 0; execute(&linebuf[2], 1, count - 2); goto cont; case '.': /* * Simulate end of file on input. */ goto out; case 'x': /* * Same as 'q', but no dead.letter saving. */ hadintr++; collint(0); exit(1); /*NOTREACHED*/ case 'q': /* * Force a quit of sending mail. * Act like an interrupt happened. */ hadintr++; collint(SIGINT); exit(1); /*NOTREACHED*/ case 'h': /* * Grab a bunch of headers. */ do grabh(hp, GTO|GSUBJECT|GCC|GBCC, value("bsdcompat") != NULL && value("bsdorder") != NULL); while (hp->h_to == NULL); goto cont; case 'H': /* * Grab extra headers. */ do grabh(hp, GEXTRA, 0); while (check_from_and_sender(hp->h_from, hp->h_sender)); goto cont; case 't': /* * Add to the To list. */ while ((hp->h_to = checkaddrs(cat(hp->h_to, sextract(&linebuf[2], GTO|GFULL)))) == NULL); break; case 's': /* * Set the Subject list. */ cp = &linebuf[2]; while (whitechar(*cp & 0377)) cp++; hp->h_subject = savestr(cp); break; case '@': /* * Edit the attachment list. */ if (linebuf[2] != '\0') hp->h_attach = append_attachments(hp->h_attach, &linebuf[2]); else hp->h_attach = edit_attachments(hp->h_attach); break; case 'c': /* * Add to the CC list. */ hp->h_cc = checkaddrs(cat(hp->h_cc, sextract(&linebuf[2], GCC|GFULL))); break; case 'b': /* * Add stuff to blind carbon copies list. */ hp->h_bcc = checkaddrs(cat(hp->h_bcc, sextract(&linebuf[2], GBCC|GFULL))); break; case 'd': strncpy(linebuf + 2, getdeadletter(), linesize - 2); linebuf[linesize-1]='\0'; /*FALLTHRU*/ case 'r': case '<': /* * Invoke a file: * Search for the file name, * then open it and copy the contents to collf. */ cp = &linebuf[2]; while (whitechar(*cp & 0377)) cp++; if (*cp == '\0') { printf(catgets(catd, CATSET, 57, "Interpolate what file?\n")); break; } if (*cp == '!') { insertcommand(collf, cp + 1); break; } cp = expand(cp); if (cp == NULL) break; if (is_dir(cp)) { printf(catgets(catd, CATSET, 58, "%s: Directory\n"), cp); break; } if ((fbuf = Fopen(cp, "r")) == NULL) { perror(cp); break; } printf(catgets(catd, CATSET, 59, "\"%s\" "), cp); fflush(stdout); if (include_file(fbuf, cp, &lc, &cc, 0) != 0) goto err; printf(catgets(catd, CATSET, 60, "%d/%d\n"), lc, cc); break; case 'i': /* * Insert an environment variable into the file. */ cp = &linebuf[2]; while (whitechar(*cp & 0377)) cp++; if ((cp = value(cp)) == NULL || *cp == '\0') break; if (is_a_tty[0]) putesc(cp, stdout); putesc(cp, collf); break; case 'a': case 'A': /* * Insert the contents of a signature variable. */ if ((cp = value(c == 'a' ? "sign" : "Sign")) != NULL && *cp != '\0') { if (is_a_tty[0]) putesc(cp, stdout); putesc(cp, collf); } break; case 'w': /* * Write the message on a file. */ cp = &linebuf[2]; while (blankchar(*cp & 0377)) cp++; if (*cp == '\0') { fprintf(stderr, catgets(catd, CATSET, 61, "Write what file!?\n")); break; } if ((cp = expand(cp)) == NULL) break; rewind(collf); exwrite(cp, collf, 1); break; case 'm': case 'M': case 'f': case 'F': /* * Interpolate the named messages, if we * are in receiving mail mode. Does the * standard list processing garbage. * If ~f is given, we don't shift over. */ if (forward(linebuf + 2, collf, c) < 0) goto err; goto cont; case '?': fputs(tildehelp, stdout); break; case 'p': /* * Print out the current state of the * message without altering anything. */ print_collf(collf, hp); goto cont; case '|': /* * Pipe message through command. * Collect output as new message. */ rewind(collf); mespipe(&linebuf[2]); goto cont; case 'v': case 'e': /* * Edit the current message. * 'e' means to use EDITOR * 'v' means to use VISUAL */ rewind(collf); mesedit(c, value("editheaders") ? hp : NULL); goto cont; } } goto out; err: if (collf != NULL) { Fclose(collf); collf = NULL; } out: if (collf != NULL) { if ((cp = value("MAILX_TAIL")) != NULL) { if (is_a_tty[0]) putesc(cp, stdout); fflush(collf); putesc(cp, collf); } rewind(collf); } handlerpop(); noreset--; sigemptyset(&nset); sigaddset(&nset, SIGINT); sigaddset(&nset, SIGHUP); #ifndef OLDBUG sigprocmask(SIG_BLOCK, &nset, (sigset_t *)NULL); #else sigprocmask(SIG_BLOCK, &nset, &oset); #endif safe_signal(SIGINT, saveint); safe_signal(SIGHUP, savehup); safe_signal(SIGTSTP, savetstp); safe_signal(SIGTTOU, savettou); safe_signal(SIGTTIN, savettin); sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL); return collf; }
void handleExcludeFile(tree *tr, analdef *adef, rawdata *rdta) { FILE *f; char buf[256]; int ch, j, value, i, state = 0, numberOfModels = 0, l = -1, excludeRegion = 0, excludedColumns = 0, modelCounter = 1; int *excludeArray, *countArray, *modelList; int **partitions; printf("\n\n"); f = myfopen(excludeFileName, "rb"); while((ch = getc(f)) != EOF) { if(ch == '-') numberOfModels++; } excludeArray = (int*)malloc(sizeof(int) * (rdta->sites + 1)); countArray = (int*)malloc(sizeof(int) * (rdta->sites + 1)); modelList = (int *)malloc((rdta->sites + 1)* sizeof(int)); partitions = (int **)malloc(sizeof(int *) * numberOfModels); for(i = 0; i < numberOfModels; i++) partitions[i] = (int *)malloc(sizeof(int) * 2); rewind(f); while((ch = getc(f)) != EOF) { switch(state) { case 0: /* get first number */ if(!whitechar(ch)) { if(!isNum(ch)) { printf("exclude file must have format: number-number [number-number]*\n"); exit(-1); } l = 0; buf[l++] = ch; state = 1; } break; case 1: /*get the number or detect - */ if(!isNum(ch) && ch != '-') { printf("exclude file must have format: number-number [number-number]*\n"); exit(-1); } if(isNum(ch)) { buf[l++] = ch; } else { buf[l++] = '\0'; value = atoi(buf); partitions[excludeRegion][0] = value; state = 2; } break; case 2: /*get second number */ if(!isNum(ch)) { printf("exclude file must have format: number-number [number-number]*\n"); exit(-1); } l = 0; buf[l++] = ch; state = 3; break; case 3: /* continue second number or find end */ if(!isNum(ch) && !whitechar(ch)) { printf("exclude file must have format: number-number [number-number]*\n"); exit(-1); } if(isNum(ch)) { buf[l++] = ch; } else { buf[l++] = '\0'; value = atoi(buf); partitions[excludeRegion][1] = value; excludeRegion++; state = 0; } break; default: assert(0); } } if(state == 3) { buf[l++] = '\0'; value = atoi(buf); partitions[excludeRegion][1] = value; excludeRegion++; } assert(excludeRegion == numberOfModels); for(i = 0; i <= rdta->sites; i++) { excludeArray[i] = -1; countArray[i] = 0; modelList[i] = -1; } for(i = 0; i < numberOfModels; i++) { int lower = partitions[i][0]; int upper = partitions[i][1]; if(lower > upper) { printf("Misspecified exclude region %d\n", i); printf("lower bound %d is greater than upper bound %d\n", lower, upper); exit(-1); } if(lower == 0) { printf("Misspecified exclude region %d\n", i); printf("lower bound must be greater than 0\n"); exit(-1); } if(upper > rdta->sites) { printf("Misspecified exclude region %d\n", i); printf("upper bound %d must be smaller than %d\n", upper, (rdta->sites + 1)); exit(-1); } for(j = lower; j <= upper; j++) { if(excludeArray[j] != -1) { printf("WARNING: Exclude regions %d and %d overlap at position %d (already excluded %d times)\n", excludeArray[j], i, j, countArray[j]); } excludeArray[j] = i; countArray[j] = countArray[j] + 1; } } for(i = 1; i <= rdta->sites; i++) { if(excludeArray[i] != -1) excludedColumns++; else { modelList[modelCounter] = tr->model[i]; modelCounter++; } } printf("You have excluded %d out of %d columns\n", excludedColumns, rdta->sites); if(excludedColumns == rdta->sites) { printf("Error: You have excluded all sites\n"); exit(-1); } if(adef->useSecondaryStructure && (excludedColumns > 0)) { char mfn[2048]; int countColumns; FILE *newFile; assert(adef->useMultipleModel); strcpy(mfn, secondaryStructureFileName); strcat(mfn, "."); strcat(mfn, excludeFileName); newFile = myfopen(mfn, "wb"); printBothOpen("\nA secondary structure file with analogous structure assignments for non-excluded columns is printed to file %s\n", mfn); for(i = 1, countColumns = 0; i <= rdta->sites; i++) { if(excludeArray[i] == -1) fprintf(newFile, "%c", tr->secondaryStructureInput[i - 1]); else countColumns++; } assert(countColumns == excludedColumns); fprintf(newFile,"\n"); fclose(newFile); } if(adef->useMultipleModel && (excludedColumns > 0)) { char mfn[2048]; FILE *newFile; strcpy(mfn, modelFileName); strcat(mfn, "."); strcat(mfn, excludeFileName); newFile = myfopen(mfn, "wb"); printf("\nA partition file with analogous model assignments for non-excluded columns is printed to file %s\n", mfn); for(i = 0; i < tr->NumberOfModels; i++) { boolean modelStillExists = FALSE; for(j = 1; (j <= rdta->sites) && (!modelStillExists); j++) { if(modelList[j] == i) modelStillExists = TRUE; } if(modelStillExists) { int k = 1; int lower, upper; int parts = 0; switch(tr->partitionData[i].dataType) { case AA_DATA: { char AAmodel[1024]; strcpy(AAmodel, protModels[tr->partitionData[i].protModels]); if(tr->partitionData[i].protFreqs) strcat(AAmodel, "F"); fprintf(newFile, "%s, ", AAmodel); } break; case DNA_DATA: fprintf(newFile, "DNA, "); break; case BINARY_DATA: fprintf(newFile, "BIN, "); break; case GENERIC_32: fprintf(newFile, "MULTI, "); break; case GENERIC_64: fprintf(newFile, "CODON, "); break; default: assert(0); } fprintf(newFile, "%s = ", tr->partitionData[i].partitionName); while(k <= rdta->sites) { if(modelList[k] == i) { lower = k; while((modelList[k + 1] == i) && (k <= rdta->sites)) k++; upper = k; if(lower == upper) { if(parts == 0) fprintf(newFile, "%d", lower); else fprintf(newFile, ",%d", lower); } else { if(parts == 0) fprintf(newFile, "%d-%d", lower, upper); else fprintf(newFile, ",%d-%d", lower, upper); } parts++; } k++; } fprintf(newFile, "\n"); } } fclose(newFile); } { FILE *newFile; char mfn[2048]; strcpy(mfn, seq_file); strcat(mfn, "."); strcat(mfn, excludeFileName); newFile = myfopen(mfn, "wb"); printf("\nAn alignment file with excluded columns is printed to file %s\n\n\n", mfn); fprintf(newFile, "%d %d\n", tr->mxtips, rdta->sites - excludedColumns); for(i = 1; i <= tr->mxtips; i++) { unsigned char *tipI = &(rdta->y[i][1]); fprintf(newFile, "%s ", tr->nameList[i]); for(j = 0; j < rdta->sites; j++) { if(excludeArray[j + 1] == -1) fprintf(newFile, "%c", getInverseMeaning(tr->dataVector[j + 1], tipI[j])); } fprintf(newFile, "\n"); } fclose(newFile); } fclose(f); for(i = 0; i < numberOfModels; i++) free(partitions[i]); free(partitions); free(excludeArray); free(countArray); free(modelList); }
void parseSecondaryStructure(tree *tr, analdef *adef, int sites) { if(adef->useSecondaryStructure) { FILE *f = myfopen(secondaryStructureFileName, "rb"); int i, k, countCharacters = 0, ch, *characters, **brackets, opening, closing, depth, numberOfSymbols, numSecondaryColumns; unsigned char bracketTypes[4][2] = {{'(', ')'}, {'<', '>'}, {'[', ']'}, {'{', '}'}}; numberOfSymbols = 4; tr->secondaryStructureInput = (char*)malloc(sizeof(char) * sites); while((ch = fgetc(f)) != EOF) { if(ch == '(' || ch == ')' || ch == '<' || ch == '>' || ch == '[' || ch == ']' || ch == '{' || ch == '}' || ch == '.') countCharacters++; else { if(!whitechar(ch)) { printf("Secondary Structure file %s contains character %c at position %d\n", secondaryStructureFileName, ch, countCharacters + 1); printf("Allowed Characters are \"( ) < > [ ] { } \" and \".\" \n"); errorExit(-1); } } } if(countCharacters != sites) { printf("Error: Alignment length is: %d, secondary structure file has length %d\n", sites, countCharacters); errorExit(-1); } characters = (int*)malloc(sizeof(int) * countCharacters); brackets = (int **)malloc(sizeof(int*) * numberOfSymbols); for(k = 0; k < numberOfSymbols; k++) brackets[k] = (int*)calloc(countCharacters, sizeof(int)); rewind(f); countCharacters = 0; while((ch = fgetc(f)) != EOF) { if(!whitechar(ch)) { tr->secondaryStructureInput[countCharacters] = ch; characters[countCharacters++] = ch; } } assert(countCharacters == sites); for(k = 0; k < numberOfSymbols; k++) { for(i = 0, opening = 0, closing = 0, depth = 0; i < countCharacters; i++) { if((characters[i] == bracketTypes[k][0] || characters[i] == bracketTypes[k][1]) && (tr->extendedDataVector[i+1] == AA_DATA || tr->extendedDataVector[i+1] == BINARY_DATA || tr->extendedDataVector[i+1] == GENERIC_32 || tr->extendedDataVector[i+1] == GENERIC_64)) { printf("Secondary Structure only for DNA character positions \n"); printf("I am at position %d of the secondary structure file and this is not part of a DNA partition\n", i+1); errorExit(-1); } if(characters[i] == bracketTypes[k][0]) { depth++; /*printf("%d %d\n", depth, i);*/ brackets[k][i] = depth; opening++; } if(characters[i] == bracketTypes[k][1]) { brackets[k][i] = depth; /*printf("%d %d\n", depth, i); */ depth--; closing++; } if(closing > opening) { printf("at position %d there is a closing bracket too much\n", i+1); errorExit(-1); } } assert(depth == 0 && countCharacters == sites); if(closing != opening) { printf("Number of opening brackets %d should be equal to number of closing brackets %d\n", opening, closing); errorExit(-1); } } for(i = 0, numSecondaryColumns = 0; i < countCharacters; i++) { int checkSum = 0; for(k = 0; k < numberOfSymbols; k++) { if(brackets[k][i] > 0) { checkSum++; switch(tr->secondaryStructureModel) { case SEC_16: case SEC_16_A: case SEC_16_B: case SEC_16_C: case SEC_16_D: case SEC_16_E: case SEC_16_F: case SEC_16_I: case SEC_16_J: case SEC_16_K: tr->extendedDataVector[i+1] = SECONDARY_DATA; break; case SEC_6_A: case SEC_6_B: case SEC_6_C: case SEC_6_D: case SEC_6_E: tr->extendedDataVector[i+1] = SECONDARY_DATA_6; break; case SEC_7_A: case SEC_7_B: case SEC_7_C: case SEC_7_D: case SEC_7_E: case SEC_7_F: tr->extendedDataVector[i+1] = SECONDARY_DATA_7; break; default: assert(0); } numSecondaryColumns++; } } assert(checkSum <= 1); } assert(numSecondaryColumns % 2 == 0); /*printf("Number of secondary columns: %d merged columns: %d\n", numSecondaryColumns, numSecondaryColumns / 2);*/ tr->numberOfSecondaryColumns = numSecondaryColumns; if(numSecondaryColumns > 0) { int model = tr->NumberOfModels; int countPairs; pInfo *partBuffer = (pInfo*)malloc(sizeof(pInfo) * tr->NumberOfModels); for(i = 1; i <= sites; i++) { for(k = 0; k < numberOfSymbols; k++) { if(brackets[k][i-1] > 0) tr->model[i] = model; } } /* now make a copy of partition data */ for(i = 0; i < tr->NumberOfModels; i++) { partBuffer[i].partitionName = (char*)malloc((strlen(tr->extendedPartitionData[i].partitionName) + 1) * sizeof(char)); strcpy(partBuffer[i].partitionName, tr->extendedPartitionData[i].partitionName); partBuffer[i].dataType = tr->extendedPartitionData[i].dataType; partBuffer[i].protModels= tr->extendedPartitionData[i].protModels; partBuffer[i].protFreqs= tr->extendedPartitionData[i].protFreqs; } for(i = 0; i < tr->NumberOfModels; i++) free(tr->extendedPartitionData[i].partitionName); free(tr->extendedPartitionData); tr->extendedPartitionData = (pInfo*)malloc(sizeof(pInfo) * (tr->NumberOfModels + 1)); for(i = 0; i < tr->NumberOfModels; i++) { tr->extendedPartitionData[i].partitionName = (char*)malloc((strlen(partBuffer[i].partitionName) + 1) * sizeof(char)); strcpy(tr->extendedPartitionData[i].partitionName, partBuffer[i].partitionName); tr->extendedPartitionData[i].dataType = partBuffer[i].dataType; tr->extendedPartitionData[i].protModels= partBuffer[i].protModels; tr->extendedPartitionData[i].protFreqs= partBuffer[i].protFreqs; free(partBuffer[i].partitionName); } free(partBuffer); tr->extendedPartitionData[i].partitionName = (char*)malloc(64 * sizeof(char)); switch(tr->secondaryStructureModel) { case SEC_16: case SEC_16_A: case SEC_16_B: case SEC_16_C: case SEC_16_D: case SEC_16_E: case SEC_16_F: case SEC_16_I: case SEC_16_J: case SEC_16_K: strcpy(tr->extendedPartitionData[i].partitionName, "SECONDARY STRUCTURE 16 STATE MODEL"); tr->extendedPartitionData[i].dataType = SECONDARY_DATA; break; case SEC_6_A: case SEC_6_B: case SEC_6_C: case SEC_6_D: case SEC_6_E: strcpy(tr->extendedPartitionData[i].partitionName, "SECONDARY STRUCTURE 6 STATE MODEL"); tr->extendedPartitionData[i].dataType = SECONDARY_DATA_6; break; case SEC_7_A: case SEC_7_B: case SEC_7_C: case SEC_7_D: case SEC_7_E: case SEC_7_F: strcpy(tr->extendedPartitionData[i].partitionName, "SECONDARY STRUCTURE 7 STATE MODEL"); tr->extendedPartitionData[i].dataType = SECONDARY_DATA_7; break; default: assert(0); } tr->extendedPartitionData[i].protModels= -1; tr->extendedPartitionData[i].protFreqs= -1; tr->NumberOfModels++; if(adef->perGeneBranchLengths) { if(tr->NumberOfModels > NUM_BRANCHES) { printf("You are trying to use %d partitioned models for an individual per-gene branch length estimate.\n", tr->NumberOfModels); printf("Currently only %d are allowed to improve efficiency.\n", NUM_BRANCHES); printf("Note that the number of partitions has automatically been incremented by one to accomodate secondary structure models\n"); printf("\n"); printf("In order to change this please replace the line \"#define NUM_BRANCHES %d\" in file \"axml.h\" \n", NUM_BRANCHES); printf("by \"#define NUM_BRANCHES %d\" and then re-compile RAxML.\n", tr->NumberOfModels); exit(-1); } else { tr->multiBranch = 1; tr->numBranches = tr->NumberOfModels; } } assert(countCharacters == sites); tr->secondaryStructurePairs = (int*)malloc(sizeof(int) * countCharacters); for(i = 0; i < countCharacters; i++) tr->secondaryStructurePairs[i] = -1; /* for(i = 0; i < countCharacters; i++) printf("%d", brackets[i]); printf("\n"); */ countPairs = 0; for(k = 0; k < numberOfSymbols; k++) { i = 0; while(i < countCharacters) { int j = i, bracket, openBracket, closeBracket; while(j < countCharacters && ((bracket = brackets[k][j]) == 0)) { i++; j++; } if(j == countCharacters) { assert(bracket == 0); break; } openBracket = j; j++; while(bracket != brackets[k][j] && j < countCharacters) j++; assert(j < countCharacters); closeBracket = j; assert(closeBracket < countCharacters && openBracket < countCharacters); assert(brackets[k][closeBracket] > 0 && brackets[k][openBracket] > 0); /*printf("%d %d %d\n", openBracket, closeBracket, bracket);*/ brackets[k][closeBracket] = 0; brackets[k][openBracket] = 0; countPairs++; tr->secondaryStructurePairs[closeBracket] = openBracket; tr->secondaryStructurePairs[openBracket] = closeBracket; } assert(i == countCharacters); } assert(countPairs == numSecondaryColumns / 2); /*for(i = 0; i < countCharacters; i++) printf("%d ", tr->secondaryStructurePairs[i]); printf("\n");*/ adef->useMultipleModel = TRUE; } for(k = 0; k < numberOfSymbols; k++) free(brackets[k]); free(brackets); free(characters); fclose(f); } }
/* * Get the last, possibly quoted part of linebuf. */ char * laststring(char *linebuf, int *flag, int strip) { char *cp, *p; char quoted; *flag = 1; cp = strlen(linebuf) + linebuf - 1; /* * Strip away trailing blanks. */ while (cp > linebuf && whitechar(*cp & 0377)) cp--; *++cp = 0; if (cp == linebuf) { *flag = 0; return NULL; } /* * Now search for the beginning of the command name. */ quoted = *(cp - 1); if (quoted == '\'' || quoted == '\"') { cp--; if (strip) *cp = '\0'; cp--; while (cp > linebuf) { if (*cp != quoted) { cp--; } else if (*(cp - 1) != '\\') { break; } else { p = --cp; do { *p = *(p + 1); } while (*p++); cp--; } } if (cp == linebuf) *flag = 0; if (*cp == quoted) { if (strip) *cp++ = 0; } else *flag = 0; } else { while (cp > linebuf && !whitechar(*cp & 0377)) cp--; if (whitechar(*cp & 0377)) *cp++ = 0; else *flag = 0; } if (*cp == '\0') { return(NULL); } return(cp); }