/*------------------------------------------------------------- Copyright (C) 2000 Rolf Backofen, Peter Clote. All Rights Reserved. Permission to use, copy, modify, and distribute this software and its documentation for NON-COMMERCIAL purposes and without fee is hereby granted provided that this copyright notice appears in all copies. THE AUTHOR AND PUBLISHER MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THE AUTHORS AND PUBLISHER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. -------------------------------------------------------------*/ /**************************************************************************** * general.c: Implementation of general support functions for the project * * "Error optimized genetic code". * ****************************************************************************/ /* Programmed by S. Schoenauer in spring 1997, modified by P. Clote in fall '97 */ /* Include section */ #include #include "general.h" /* This is a table to convert the number of an amino acid into the three-letter code plus a symbol for the start and the stop codon. The ordering of amino-acid number are aplphabetical */ char *num2triple[NUM_ACIDS_SS] = { "Ala", "Arg", "Asn", "Asp", "Cys", "Gln", "Glu", "Gly", "His", "Ile", "Leu", "Lys", "Met", "Phe", "Pro", "Ser", "Thr", "Trp", "Tyr", "Val", "Stop" }; ; /* numbering of blocks (= consecutive odering) */ gcode block_code = { { {0, 5, 9, 16}, {0, 5, 9, 16}, {1, 5, STOP, STOP}, {1, 5, STOP, 17} }, { {1, 6, 10, 18}, {1, 6, 10, 18}, {1, 6, 11, 18}, {1, 6, 11, 18} }, { {2, 7, 12, 5}, {2, 7, 12, 5}, {2, 7, 13, 18}, {3, 7, 13, 18} }, { {4, 8, 14, 19}, {4, 8, 14, 19}, {4, 8, 15, 19}, {4, 8, 15, 19} } }; /* translates a block number (as given by block_code) into and amino-acid number (as given by the alphabetical ordering in num2triple) for the natural code */ int block_alpha[NUM_ACIDS_SS] = { 13, 10, 9, 12, 19, 15, 14, 16, 0, 18, 8, 5, 2, 11, 3, 6, 4, 17, 1, 7}; /* backward translation: aminoacid-number (alphabetical order) to block number for the natural code */ int alpha_block[NUM_ACIDS_SS] = { 8, 18, 12, 14, 16, 11, 15, 19, 10, 2, 1, 13, 3, 0, 6, 5, 7, 17, 9, 4}; /* polar requirement for natural code (for the amino-acids in alphabetical ordering */ float alpha_PC[NUM_ACIDS] = { 7.0, 9.1, 10.0, 13.0, 4.8, 8.6, 12.5, 7.9, 8.4, 4.9, 4.9, 10.1, 5.3, 5.0, 6.6, 7.5, 6.6, 5.2, 5.4, 5.6 }; /* for test purposes: std_code using natural code and alphabetical order. we have std_code[i][j] = block_alpha[block_code[i][j]] */ gcode std_code = { { {13, 15, 18, 4}, {13, 15, 18, 4}, {10, 15, 20, 20}, {10, 15, 20, 17} }, { {10, 14, 8, 1}, {10, 14, 8, 1}, {10, 14, 5, 1}, {10, 14, 5, 1} }, { {9, 16, 2, 15}, {9, 16, 2, 15}, {9, 16, 11, 1}, {12, 16, 11, 1} }, { {19, 0, 3, 7}, {19, 0, 3, 7}, {19, 0, 6, 7}, {19, 0, 6, 7} } }; /* This is a table to convert the number of an amino acid (in alphabetical ordering into one-letter. */ unsigned char num2char[NUM_ACIDS_SS] = { 'A', 'R', 'N', 'D', 'C', 'Q', 'E', 'G', 'H', 'I', 'L', 'K', 'M', 'F', 'P', 'S', 'T', 'W', 'Y', 'V', '#' }; /**************************************************************************** read_matrix(): function to read a soring matrix from disk. Input is a 20 x 20 floating pt similarity matrix, where the amino acids 0..19 are in alphabetical order for 3-letter codes, separated by blanks. input: 1. name of the matrix file output: 0 == Everything O.K. != 0 Error ocurred ****************************************************************************/ int read_matrix(char *filename, float matrix[NUM_ACIDS][NUM_ACIDS]) { float temp = 0; /* contains the last value read */ FILE *fp = fopen(filename, "r"); int i,j; /* counters for loops */ if (fp == NULL) { fprintf(stderr, "Could not open scoring matrix file!\n"); return 1; } for (i = 0; i < NUM_ACIDS; i++) { for (j = i; j < NUM_ACIDS; j++) { if (fscanf(fp, "%f ", &temp) == EOF) { fprintf(stderr, "File contains no scoring matrix!\n"); fclose(fp); return 1; } matrix[i][j] = temp; matrix[j][i] = temp; } } return 0; }