/* * talign2fasta - this file contains code for converting a CASP2-style * TALIGN record into a FASTA-format alignment * * Update history: * 3/10/98 cline author */ #include #include #include #include #include "alignsummary.h" /* * #DEFINES */ #define DEFAULT_VERBOSE FALSE /* * These #defines control which row in the alignment the target goes in, * and which row the template goes in. This is to keep everything consistent. */ #define TARGET 0 #define TEMPLATE 1 /* * the #defines below are used for parsing the command line and looking * for the arguments. Note that they're given in alphabetical order. * The arguments are permitted to be abbreviated (eg -r for reference). * So, it's necessary to know when there's a potential abbreviation * conflict. */ #define TARGETA2M_STRING "-a2mtarget" #define TEMPLATEA2M_STRING "-a2mtemplate" #define TALIGN_STRING "-talign" #define PDBNUM_STRING "-pdbnum" #define OUTPUT_A2M_STRING "-output" #define VERBOSE_STRING "-verbose" #define TEMPLATE_SEQ_STRING "-templateseq" /* * this #define defines the smallest alignment we'd find interesting * in terms of number of aligned sequences. In this case, we might * be happy with a single sequence alignment. */ #define SINGLE_SEQ 1 /* * these #defines tell us how we're to copy new residues into an alignment: * as if they were in a match state, or as if they were in an insert state. */ #define INSERT 0 #define MATCH 1 /* * TYPEDEFS */ /* * the structure below holds the TALIGN records. The meaning of * the fields is to the best of my memory, as seen by the second * field name. * A linked list of these structures is used to hold the TALIGN * representation of a single alignment */ typedef struct talign_record { char target[MAX_LABEL_LENGTH]; /* name of the target seq */ int mysteryField; int targetStartPos; /* starting position in the * target sequence for the * next aligned segment */ int targetEndPos; /* ending position in the * target seqeunce for the * next aligned segment */ char templateCore[MAX_LABEL_LENGTH]; /* name of the template * sequence, minus chain * identifier */ char chainID; /* chain ID for the template * sequence, "-" if no * chain ID is needed */ int mysteryField2; char templateStartPos[MAX_LABEL_LENGTH]; /* starting position in the * template sequence for the * next aligned segment */ char templateEndPos[MAX_LABEL_LENGTH]; /* ending position in the * template seqeunce for the * next aligned segment */ float confidence; /* level of confidence given to * this alignment */ int alignmentNum; /* number given to this alignment * of template to target - there * can be more than one */ struct talign_record *next; /* pointer to the next TALIGN * record from this TALIGN file */ } talign; /* * PROTOTYPES */ void addToAlignment( int targetSeqStart, /* called with: index in the target * sequence that we start copying from. */ int targetSeqEnd, /* called with: last index position to * copy in the target sequence */ alignedSequence *target, /* called with: structure describing how * the target aligns in the next argument */ AlignSummary *alignWithTarget, /* called with: alignment containing * the target sequence */ int templateSeqStart, /* called with: index in the template * sequence that we start copying from */ int templateSeqEnd, /* called with: index in the template * sequence after which we stop copying */ alignedSequence *template, /* called with: structure describing how * the template sequence aligns in the * next argument */ AlignSummary *alignWithTemplate, /* called with: an alignment containing * the template sequence */ int mode, /* mode in which the residues are to * be copied into the new alignment: * insert or match */ int *alignColumnIdx, /* called with: current column in the * alignment. Return with: updated * current column, when we're done here */ AlignSummary *alignTargetTemplate); /* return with: updated alignment * of the target and template seqs, * reflecting this new segment */ int checkArguments( int haveTargetA2m, /* called with: flag indicating if an * alignment with the target sequence * was specified */ int haveTemplateA2m, /* called with: flag indicating if the * alignment with the template sequence * was specified */ int haveTalign, /* called with: flag indicating if the * talign file was specified */ int havePdbnum); /* called with: flag indicating if a * pdb number file was specified */ void createAlignSummary( char *targetName, /* called with: name of the target * sequence */ char *templateName, /* called with: name of the template * sequence */ int targetLength, /* called with: length of the target * sequence */ int templateLength, /* called with: length of the template * sequence */ AlignSummary **newAlign); /* return with: pointer to a pointer to * the new AlignSummary struct. */ void freePdbnumList( char **pdbList, /* called with: list of the pdb "numbers" */ int sequenceLength); /* called with: length of the sequence */ void freeTalignList( talign *firstTalign); /* called with: head of the linked list * to be freed */ int newAlignment( AlignSummary *alignWithTarget, /* called with: alignment * containing the target sequence */ AlignSummary *alignWithTemplate, /* called with: alignment * containing the template sequence */ alignedSequence *target, /* called with: structure describing * the alignment of the target * sequence */ alignedSequence *template, /* called with: structure describing * the alignment of the template * sequence */ char *targetName, /* called with: name of the target * sequence */ char *templateName, /* called with: name of the template * sequence */ char **pdbnumList, /* called with: list of the PDB * numbers, for each position in the * template sequence */ talign *taligns); /* called with: list of the TALIGN * records */ int parseCmdline( int argc, /* called with: number of command * line arguments */ char *argv[], /* called with: array containing the * command line arguments */ void usage(char *argv[]), /* called with: a function to print * a usage summary for the calling * program */ int checkCmdline(int a, int b, int c, int d), /* called with: a function to check * whether all the required arguments * are given */ char *targetA2mName, /* return with: the filename containing * the target sequence */ char *templateA2mName, /* return with: the filename containing * the reference alignment */ char *talignName, /* return with: filename for the * TALIGN representation of the alignment */ char *pdbnumName, /* return with: filename for a file * containing the pdb number for each * template sequence position */ char *templateSeqName, /* return with: name of the template * sequence (optional argument) */ int *haveTemplateSeq, /* return with: flag indicating if we * got the template sequence name */ int *verbose); /* return with: flag indicating if * verbose output should be seen */ int pdbnumToIndex( char *thisPdbnum, /* called with: pdb number we're * looking for */ int sequenceLength, /* called with: length of the sequence, * also length of the pdbnum array */ char **pdbList); /* called with: list of the pdb * numbes, by index position */ void printUsage(char *argv[]); int readPdbnumFile( char *pdbnumName, /* called with: name of the file */ int sequenceLength, /* called with: length of the template * sequence */ char ***pdbnumList); /* return with: pointer to an array * of the PDB "numbers" */ int readTalignFile( char *talignFileName, /* called with: filename with the TALIGN * records */ char *target, /* return with: name of the target seq */ char *template, /* return with: name of the template seq */ talign **talignList); /* return with: a linked list of the TALIGN * records from the file */ /* * parseCmdline - get the argument valus from the command line. * * This function takes as input the command line arguments in the * argc and argv variables. It looks for the arguments, parses * the argument value, checks to see if all required arguments * were given, and calls checkUsage if no arguments were given. * * What are the things we're looking for on this command line? * - a filename for an alignment containing the target sequence * - a filename for an alignment containing the template sequence * - a filename for the TALIGN record * - a filename for the PDBNUM file, a file listing the PDB * "numbers" (truly labels) for each position in the template * sequence. * - optionally, we're looking for an output file for the FASTA-format * alignment. If we don't find that, we'll send the alignment * to STDOUT. * * return value: TRUE if all the required arguments were present, * FALSE otherwise. */ int parseCmdline( int argc, /* called with: number of command * line arguments */ char *argv[], /* called with: array containing the * command line arguments */ void usage(char *argv[]), /* called with: a function to print * a usage summary for the calling * program */ int checkCmdline(int a, int b, int c, int d), /* called with: a function to check * whether all the required arguments * are given */ char *targetA2mName, /* return with: the filename containing * the target sequence */ char *templateA2mName, /* return with: the filename containing * the reference alignment */ char *talignName, /* return with: filename for the * TALIGN representation of the alignment */ char *pdbnumName, /* return with: filename for a file * containing the pdb number for each * template sequence position */ char *templateSeqName, /* return with: name of the template * sequence (optional argument) */ int *haveTemplateSeq, /* return with: flag indicating if we * got the template sequence name */ int *verbose) /* return with: flag indicating if * verbose output should be seen */ { int ii, jj; int is_okay = FALSE; int haveTargetA2m, haveTemplateA2m, haveTalignName, havePdbnumName; *haveTemplateSeq = FALSE; if (argc == 1) { (usage)(argv); } else { haveTargetA2m = haveTemplateA2m = haveTalignName = havePdbnumName = FALSE; *verbose = DEFAULT_VERBOSE; for (ii = 1; ii < argc; ii++) { if (strlen(argv[ii]) > 1) { if (ii < argc-1 && strncasecmp(TARGETA2M_STRING, argv[ii], strlen(argv[ii])) == 0) { haveTargetA2m = TRUE; strncpy(targetA2mName, argv[ii+1], FILENAME_LENGTH); } else if (ii < argc-1 && strncasecmp(TEMPLATEA2M_STRING, argv[ii], strlen(argv[ii])) == 0) { haveTemplateA2m = TRUE; strncpy(templateA2mName, argv[ii+1], FILENAME_LENGTH); } else if (ii < argc-1 && strncasecmp(TEMPLATE_SEQ_STRING, argv[ii], strlen(argv[ii])) == 0) { *haveTemplateSeq = TRUE; strncpy(templateSeqName, argv[ii+1], FILENAME_LENGTH); } else if (ii < argc-1 && strncasecmp(TALIGN_STRING, argv[ii], strlen(argv[ii])) == 0) { haveTalignName = TRUE; strncpy(talignName, argv[ii+1], MAX_LABEL_LENGTH); } else if (ii < argc-1 && strncasecmp(PDBNUM_STRING, argv[ii], strlen(argv[ii])) == 0) { havePdbnumName = TRUE; strncpy(pdbnumName, argv[ii+1], MAX_LABEL_LENGTH); } else if (strncasecmp(VERBOSE_STRING, argv[ii], strlen(argv[ii])) == 0) { *verbose = TRUE; } } } if ((*checkCmdline)(haveTargetA2m, haveTemplateA2m, haveTalignName, havePdbnumName)) { is_okay = TRUE; } } return(is_okay); } /* * checkArguments - check that all the required arguments were given * * Return value: TRUE if all the required arguments were specified, * FALSE otherwise */ int checkArguments( int haveTargetA2m, /* called with: flag indicating if an * alignment with the target sequence * was specified */ int haveTemplateA2m, /* called with: flag indicating if the * alignment with the template sequence * was specified */ int haveTalign, /* called with: flag indicating if the * talign file was specified */ int havePdbnum) /* called with: flag indicating if a * pdb number file was specified */ { int is_okay; if (haveTargetA2m && haveTemplateA2m && haveTalign && havePdbnum) { is_okay = TRUE; } else { is_okay = FALSE; fprintf(stderr, "Error: missing required argument(s) "); if (!haveTargetA2m) fprintf(stderr, "%s ", TARGETA2M_STRING); if (!haveTemplateA2m) fprintf(stderr, "%s ", TEMPLATEA2M_STRING); if (!haveTalign) fprintf(stderr, "%s ", TALIGN_STRING); if (!havePdbnum) fprintf(stderr, "%s ", PDBNUM_STRING); fprintf(stderr, "\n"); } return(is_okay); } /* * printUsage - print a usage summary */ void printUsage(char *argv[]) { printf( "Usage: %s <%s TargetA2m> <%s TemplateA2m> \\ \n", argv[0], TARGETA2M_STRING, TEMPLATEA2M_STRING); printf("\t<%s TalignFile> <%s PdbnumFile> \n", TALIGN_STRING, PDBNUM_STRING); printf("\t[%s]\n", VERBOSE_STRING); printf( "where:\tTargetA2m is some alignment containing the target sequence\n"); printf( "\tTemplateA2m is some alignment containing the template sequence\n"); printf("\tTalignFile is a file containing the TALIGN record\n"); printf("\tPdbnumFile is a file listing the PDB number for each position\n"); printf("\t\tin the template sequence\n"); printf("\t%s turns on verbose output\n\n", VERBOSE_STRING); } /* * readTalignFile - read the TALIGN file, returning with a linked list * of TALIGN records if successful. * * return value: flag set to TRUE if everything went okay, FALSE otherwise. */ int readTalignFile( char *talignFileName, /* called with: filename with the TALIGN * records */ char *target, /* return with: name of the target seq */ char *template, /* return with: name of the template seq */ talign **talignList) /* return with: a linked list of the TALIGN * records from the file */ { int isOkay = TRUE; FILE *fp; talign *firstTalign, *lastTalign, *nextTalign; firstTalign = NULL; fp = fopen(talignFileName, "r"); if (fp == NULL) { fprintf(stderr, "Error: could not open %s for reading!\n", talignFileName); isOkay = FALSE; } else { while (!feof(fp)) { nextTalign = malloc(sizeof(talign)); assert(nextTalign != NULL); fscanf(fp, "%s %d %d %d %s %c %d %s %s %f %d\n", nextTalign->target, &nextTalign->mysteryField, &nextTalign->targetStartPos, &nextTalign->targetEndPos, nextTalign->templateCore, &nextTalign->chainID, &nextTalign->mysteryField2, nextTalign->templateStartPos, nextTalign->templateEndPos, &nextTalign->confidence, &nextTalign->alignmentNum); nextTalign->next = NULL; if (firstTalign == NULL) { firstTalign = lastTalign = nextTalign; } else { lastTalign->next = nextTalign; lastTalign = lastTalign->next; } } strcpy(target, nextTalign->target); if (strlen(template) == 0) { if (isalnum(nextTalign->chainID)) { sprintf(template, "%s%c", nextTalign->templateCore, nextTalign->chainID); } else { strcpy(template, nextTalign->templateCore); } } fclose(fp); } *talignList = firstTalign; return(isOkay); } /* * readPdbnumFile - read the file listing the PDB numbers for the * template sequence * * return value: TRUE if the fiel was opened and read successfully, * FALSE if some error occurred. */ int readPdbnumFile( char *pdbnumName, /* called with: name of the file */ int sequenceLength, /* called with: length of the template * sequence */ char ***pdbnumList) /* return with: pointer to an array * of the PDB "numbers" */ { FILE *fp; int ii; char **localList = NULL; int isOkay = TRUE; char buffer[MAX_LABEL_LENGTH]; fp = fopen(pdbnumName, "r"); if (fp == NULL) { fprintf(stderr, "Error: could not open file %s for reading!\n", pdbnumName); isOkay = FALSE; } else { localList = calloc(sequenceLength, sizeof(char *)); assert(localList != NULL); for (ii = 0; ii < sequenceLength; ii++) { assert( !feof(fp) ); fscanf(fp, "%s ", buffer); localList[ii] = strdup(buffer); } fclose(fp); } *pdbnumList = localList; return (isOkay); } /* * freePdbnumList - free the list of pdb labels */ void freePdbnumList( char **pdbList, /* called with: list of the pdb "numbers" */ int sequenceLength) /* called with: length of the sequence */ { int ii; for (ii = 0; ii < sequenceLength; ii++) free(pdbList[ii]); free(pdbList); } /* * freeTalignList - free the linked list of TALIGN records */ void freeTalignList( talign *firstTalign) /* called with: head of the linked list * to be freed */ { talign *nextTalign, *lastTalign; nextTalign = firstTalign; while (nextTalign != NULL) { lastTalign = nextTalign; nextTalign = nextTalign->next; free(lastTalign); } } /* * pdbnumToIndex - given a PDB number, find the index position * it refers to * * This function takes a PDB number and finds which sequence * position has that PDB number. * * Return value: the index position with the specified PDB number, * if found. Else, it returns -1. */ int pdbnumToIndex( char *thisPdbnum, /* called with: pdb number we're * looking for */ int sequenceLength, /* called with: length of the sequence, * also length of the pdbnum array */ char **pdbList) /* called with: list of the pdb * numbes, by index position */ { int whereFound = -1; int ii; for (ii = 0; whereFound == -1 && ii < sequenceLength; ii++) { if (strcasecmp(thisPdbnum, pdbList[ii]) == 0) { whereFound = ii; } } return(whereFound); } /* * createAlignSummary - make an empty AlignSummary structure to hold * the new alignment. * * This function creates an empty AlignSummary structure for the * two sequences to be aligned: target and template. We cannot know * how long the alignment will be, so instead we use an upper bound: * it won't be longer than the sum of the length of the two sequences. */ void createAlignSummary( char *targetName, /* called with: name of the target * sequence */ char *templateName, /* called with: name of the template * sequence */ int targetLength, /* called with: length of the target * sequence */ int templateLength, /* called with: length of the template * sequence */ AlignSummary **newAlign) /* return with: pointer to a pointer to * the new AlignSummary struct. */ { AlignSummary *alignTargetTemplate = NULL; int ii; alignTargetTemplate = malloc(sizeof(AlignSummary)); assert(alignTargetTemplate != NULL); alignTargetTemplate->columns = targetLength + templateLength; alignTargetTemplate->rows = 2; alignTargetTemplate->label = calloc(alignTargetTemplate->rows, sizeof(char *)); assert(alignTargetTemplate->label != NULL); alignTargetTemplate->label[TARGET] = strdup(targetName); alignTargetTemplate->label[TEMPLATE] = strdup(templateName); alignTargetTemplate->sequence = calloc(alignTargetTemplate->columns, sizeof(char *)); assert(alignTargetTemplate->sequence != NULL); for (ii = 0; ii < alignTargetTemplate->columns; ii++) { alignTargetTemplate->sequence[ii] = calloc(alignTargetTemplate->rows, sizeof(char)); assert(alignTargetTemplate->sequence[ii] != NULL); } *newAlign = alignTargetTemplate; } /* * addToAlignment: copy the specified residues into the alignment, * in either insert states or in match states as indicated. * Return with an updated index on what alignment column we're on. * * Note that in this function, the sequence index parameters have a range * of 1 to seqlength, and we want to copy them into an array with index * 0 to seqlength-1. Hence, there's a lot of subtracting 1 from the index * positions. */ void addToAlignment( int targetSeqStart, /* called with: index in the target * sequence that we start copying from. */ int targetSeqEnd, /* called with: last index position to * copy in the target sequence */ alignedSequence *target, /* called with: structure describing how * the target aligns in the next argument */ AlignSummary *alignWithTarget, /* called with: alignment containing * the target sequence */ int templateSeqStart, /* called with: index in the template * sequence that we start copying from */ int templateSeqEnd, /* called with: index in the template * sequence after which we stop copying */ alignedSequence *template, /* called with: structure describing how * the template sequence aligns in the * next argument */ AlignSummary *alignWithTemplate, /* called with: an alignment containing * the template sequence */ int mode, /* mode in which the residues are to * be copied into the new alignment: * insert or match */ int *alignColumnIdx, /* called with: current column in the * alignment. Return with: updated * current column, when we're done here */ AlignSummary *alignTargetTemplate) /* return with: updated alignment * of the target and template seqs, * reflecting this new segment */ { int ii; int seqIndex; char nextResidue; int targetSegmentLength, templateSegmentLength; targetSegmentLength = targetSeqEnd - targetSeqStart + 1; templateSegmentLength = templateSeqEnd - templateSeqStart + 1; if (mode == MATCH) assert(targetSegmentLength == templateSegmentLength); /* * copy the residues from the target sequence into row TARGET. */ for (seqIndex = 0, ii = targetSeqStart - 1; ii < targetSeqEnd; ii++, seqIndex++) { nextResidue = alignWithTarget->sequence[target->seq_to_column[ii]][target->index]; assert(isalpha(nextResidue)); if (mode == MATCH) { alignTargetTemplate->sequence[*alignColumnIdx+seqIndex][TARGET] = toupper(nextResidue); } else { alignTargetTemplate->sequence[*alignColumnIdx+seqIndex][TARGET] = tolower(nextResidue); } } /* * If we're in insert mode, the two segments can be of different * lengths. If the target segment is shorter than the template * segment, we need to pad the target segment with dots to bring * it up to the same length as the template segment. */ if (mode == INSERT) { for (; seqIndex < templateSegmentLength; seqIndex++, ii++) { alignTargetTemplate->sequence[*alignColumnIdx+seqIndex][TARGET] = '.'; } } /* * copy the residues from the template sequence into row TEMPLATE. */ for (seqIndex = 0, ii = templateSeqStart - 1; ii < templateSeqEnd; ii++, seqIndex++) { nextResidue = alignWithTemplate->sequence[template->seq_to_column[ii]][template->index]; assert(isalpha(nextResidue)); if (mode == MATCH) { alignTargetTemplate->sequence[*alignColumnIdx+seqIndex][TEMPLATE] = toupper(nextResidue); } else { alignTargetTemplate->sequence[*alignColumnIdx+seqIndex][TEMPLATE] = tolower(nextResidue); } } if (mode == INSERT) { for (; seqIndex < targetSegmentLength; seqIndex++, ii++) { alignTargetTemplate->sequence[*alignColumnIdx+seqIndex][TEMPLATE] = '.'; } } if (targetSegmentLength > templateSegmentLength) { *alignColumnIdx += targetSegmentLength; } else { *alignColumnIdx += templateSegmentLength; } } /* * newAlignment - make a new alignment to contain this FASTA * version of the TALIGN alignment * * This function builds an AlignSummary to describe the alignment * from the TALIGN records. After building the alignment, it will * call another function to print it out. * * Return value: describes the status of the operation. If everything * goes okay, the function returns TRUE. Else, it returns FALSE. */ int newAlignment( AlignSummary *alignWithTarget, /* called with: alignment * containing the target sequence */ AlignSummary *alignWithTemplate, /* called with: alignment * containing the template sequence */ alignedSequence *target, /* called with: structure describing * the alignment of the target * sequence */ alignedSequence *template, /* called with: structure describing * the alignment of the template * sequence */ char *targetName, /* called with: name of the target * sequence */ char *templateName, /* called with: name of the template * sequence */ char **pdbnumList, /* called with: list of the PDB * numbers, for each position in the * template sequence */ talign *taligns) /* called with: list of the TALIGN * records */ { AlignSummary *alignTargetTemplate; int ii; int isOkay = TRUE; int alignColumnIdx = 0; talign *nextTalign; char nextTemplateName[MAX_LABEL_LENGTH]; int templateSegmentStart, templateSegmentEnd; int nextTargetStart, nextTemplateStart; int thisAlignmentNum; char a2mFilename[FILENAME_LENGTH]; int done = FALSE; int foundRecord = FALSE; createAlignSummary(targetName, templateName, target->sequence_length, template->sequence_length, &alignTargetTemplate); assert(alignTargetTemplate != NULL); nextTemplateStart = nextTargetStart = 1; thisAlignmentNum = taligns->alignmentNum; for (nextTalign = taligns; nextTalign != NULL && !done; nextTalign = nextTalign->next) { /* * skip over any TALIGNs that pertain to a different template seq. * If you reach a different alignment, as noted by a change in * the alingmentNum field, print out the current alignment * and recursively call this function for the next one. */ if (isalnum(nextTalign->chainID)) { sprintf(nextTemplateName, "%s%c", nextTalign->templateCore, nextTalign->chainID); } else { strcpy(nextTemplateName, nextTalign->templateCore); } if (strcasecmp(nextTemplateName, templateName) != 0) { continue; } else if (nextTalign->alignmentNum != thisAlignmentNum) { done = TRUE; newAlignment(alignWithTarget, alignWithTemplate, target, template, targetName, templateName, pdbnumList, nextTalign); } else { foundRecord = TRUE; templateSegmentStart = pdbnumToIndex(nextTalign->templateStartPos, template->sequence_length, pdbnumList) + 1; assert(templateSegmentStart > 0); templateSegmentEnd = pdbnumToIndex(nextTalign->templateEndPos, template->sequence_length, pdbnumList) + 1; assert(templateSegmentEnd > 0); /* * record the inserts preceding this aligned segment. Following * that, record the matches in the segment itself. */ addToAlignment(nextTargetStart, nextTalign->targetStartPos - 1, target, alignWithTarget, nextTemplateStart, templateSegmentStart - 1, template, alignWithTemplate, INSERT, &alignColumnIdx, alignTargetTemplate); addToAlignment(nextTalign->targetStartPos, nextTalign->targetEndPos, target, alignWithTarget, templateSegmentStart, templateSegmentEnd, template, alignWithTemplate, MATCH, &alignColumnIdx, alignTargetTemplate); nextTargetStart = nextTalign->targetEndPos + 1; nextTemplateStart = templateSegmentEnd + 1; } } if (foundRecord) { addToAlignment(nextTargetStart, target->sequence_length, target, alignWithTarget, nextTemplateStart, template->sequence_length, template, alignWithTemplate, INSERT, &alignColumnIdx, alignTargetTemplate); alignTargetTemplate->columns = alignColumnIdx + 1; /* sprintf(a2mFilename, "%s-%s.talign.1.a2m", targetName, templateName); */ sprintf(a2mFilename, "%s-%s.talign.%d.a2m", targetName, templateName, thisAlignmentNum); printAlign(alignTargetTemplate, a2mFilename); freeAlignSummary(alignTargetTemplate); } return(isOkay); } int main(int argc, char *argv[]) { char templateA2mName[FILENAME_LENGTH]; char targetA2mName[FILENAME_LENGTH]; char talignName[FILENAME_LENGTH]; char pdbnumName[FILENAME_LENGTH]; char targetName[MAX_LABEL_LENGTH]; char templateName[MAX_LABEL_LENGTH] = ""; char *buffer = NULL; int verbose; int isOkay; talign *talignRecords; AlignSummary *alignWithTarget, *alignWithTemplate; int gotField; int isTrue = TRUE; int haveTemplate; alignedSequence *target, *template; char **pdbnumList; FILE *outputFile = NULL; if (parseCmdline(argc, argv, &printUsage, &checkArguments, targetA2mName, templateA2mName, talignName, pdbnumName, templateName, &haveTemplate, &verbose)) { isOkay = readTalignFile(talignName, targetName, templateName, &talignRecords); if (isOkay) { isOkay = readAlignment(targetA2mName, (char **) &buffer, (char **) &targetName, SINGLE_SEQ, &alignWithTarget); if (isOkay) { target = alignedSequenceStruct(alignWithTarget, targetName); if (target == NULL) isOkay = FALSE; } } if (isOkay) { isOkay = readAlignment(templateA2mName, (char ** ) &templateName, (char **) &buffer, SINGLE_SEQ, &alignWithTemplate); if (isOkay) { template = alignedSequenceStruct(alignWithTemplate, templateName); if (template == NULL) isOkay = FALSE; } } if (isOkay) { isOkay = readPdbnumFile(pdbnumName, template->sequence_length, &pdbnumList); } if (isOkay) { newAlignment(alignWithTarget, alignWithTemplate, target, template, targetName, templateName, pdbnumList, talignRecords); } if (pdbnumList != NULL) freePdbnumList(pdbnumList, template->sequence_length); if (talignRecords != NULL) freeTalignList(talignRecords); if (alignWithTarget != NULL) freeAlignSummary(alignWithTarget); if (alignWithTemplate != NULL) freeAlignSummary(alignWithTemplate); if (target != NULL) freeAlignedSequence(target); if (template != NULL) freeAlignedSequence(template); } return(0); }