MSA_MST.c
上传用户:szpanda
上传日期:2016-03-09
资源大小:9k
文件大小:3k
- /* File: MSA_MST.c */
- /* Author:Qichan Ma, Student No.:250494898 */
- #include "globals.h"
- #include "readInput.h"
- #include "multiAlign.h"
- int main(int argc, char *argv[]) {
- /* read the residues, substitution score matrix & gap penalty from the input file */
- readScore();
- printf("n");
- /* read the sequences from the input file */
- readSeq();
- printf("n");
-
- /* the option for the output; 1 reprents output to the screen, 2 reprents output to the file */
- printf("Please choose the option for the output; 1 reprents output to the screen, 2 reprents output to the file: ");
- scanf("%d", &opt1);
- if(opt1 == 1)
- out = stdout;
- else if (opt1 == 2) {
- char *outfile="MultlipleAlignment.txt";
- if((out = fopen(outfile, "w")) == NULL) {
- printf("cannot open the outfilen");
- exit(0);
- }
- }
- else {
- printf("wrong inputn");
- exit(0);
- }
- printf("n");
- /* the option for the output result; 1 reprents output the final alignment,
- 2 reprents output both the final alignment and intermediate result */
- printf("Please choose the option for the output result; 1 reprents output the final alignment, 2 reprents output both the final alignment and intermediate result: ");
- scanf("%d", &opt2);
- if(opt2 != 1 && opt2 != 2) {
- printf("wrong inputn");
- exit(0);
- }
- printf("n");
-
- int i;
- /* the maximal pairwise alignment's length is no more than 2*maximal sequence length */
- int maxPairAlignLen = 2*seqLen[0];
- for(i=0; i<numOfSeq; i++) {
- if(maxPairAlignLen < 2*seqLen[i])
- maxPairAlignLen = 2*seqLen[i];
- }
- align1 = (char *)malloc(maxPairAlignLen*sizeof(char));
- align2 = (char *)malloc(maxPairAlignLen*sizeof(char));
- /* do the multiple sequence alignment using Kruskal's maximum spanning tree algorithm */
- MST_Kruskal();
- /* output the multiple alignment & SP score */
- printMultiAlign();
-
- /* free score */
- for(i=0; i<residuesLen; i++)
- free(score[i]);
- free(score);
- /* free seqName */
- for(i=0;i<numOfSeq;i++)
- free(seqName[i]);
- free(seqName);
- /* free seq */
- for(i=0;i<numOfSeq;i++)
- free(seq[i]);
- free(seq);
- /* free seqLen */
- free(seqLen);
- /* free multiAlign */
- for(i=0;i<numOfSeq;i++)
- free(multiAlign[i]);
- free(multiAlign);
- /* free the temporary pairwise alignment */
- free(align1);
- free(align2);
-
- /* close the output file */
- if(opt1 == 2)
- fclose(out);
- return 0;
- }