// $Id: sw_test.cs,v 1.8 2011/07/07 13:38:20 djg11 Exp $ // Basic, single-threaded sw code: hardwired input and no CRC on output. // using System; using System.Text; using KiwiSystem; namespace SmithWaterman { class Program { [Kiwi.OutputWordPort("phase")] static byte phase; [Kiwi.OutputWordPort("result")] static long result; [Kiwi.OutputWordPort("d_monitor")] static long d_monitor; [Kiwi.HardwareEntryPoint()] static void Main() { long i, j, d_loc, q_loc; long Ins_c, Del_c, H_temp; long[] d_index = new long[78]; long[] q_index = new long[78]; char [] aa = new char [] {'a','c','d','e','f','g','h','i','k','l','m','n','p','q','r','s','t','v','w','y'}; long[,] Ins = new long[78, 78]; long[,] Del = new long[78, 78]; long[,] H = new long[78, 78]; long[,] Hg = new long[78, 78]; /* Query Sequence = d1xpa_1 a.6.1.2 (134-210) from ASTRAL 1.67 40% */ char[] query = new char []{'d','k','h','k','l','i','t','k','t','e','a','k','q','e','y','l','l','k','d','c','d','l','e','k','r','e','p','p','l','k','f','i','v','k','k','n','p','h','h','s','q','w','g','d','m','k','l','y','l','k','l','q','i','v','k','r','s','l','e','v','w','g','s','q','e','a','l','e','e','a','k','e','v','r','q','e','n'}; /* Database Sequence = d1jjcb2 a.6.1.1 (B:400-474) from ASTRAL 1.67 40% */ char [] d = new char[] {'p','p','e','a','i','p','f','r','p','e','y','a','n','r','l','l','g','t','s','y','p','e','a','e','q','i','a','i','l','k','r','l','g','c','r','v','e','g','e','g','p','t','y','r','v','t','p','p','s','h','r','l','d','l','r','l','e','e','d','l','v','e','e','v','a','r','i','q','g','y','e','t','i','p','l'}; /* Scoring Matrix (PAM 250) */ int [,] S = new int [20,20] { { 2, -2, 0, 0, -4, 1, -1, -1, -1, -2, -1, 0, 1, 0, -2, 1, 1, 0, -1, -3}, {-2, 12, -5, -5, -4, -3, -3, -2, -5, -6, -5, -4, -3, -5, -4, 0, -2, -2, -8, 0}, { 0, -5, 4, 3, -6, 1, 1, -2, 0, -4, -3, 2, -1, 2, -1, 0, 0, -2, -7, -4}, { 0, -5, 3, 4, -5, 0, 1, -2, 0, -3, -2, 1, -1, 2, -1, 0, 0, -2, -7, -4}, {-4, -4, -6, -5, 9, -5, -2, 1, -5, 2, 0, -4, -5, -5, -4, -3, -3, -1, 0, 7}, { 1, -3, 1, 0, -5, 5, -2, -3, -2, -4, -3, 0, -1, -1, -3, 1, 0, -1, -7, -5}, {-1, -3, 1, 1, -2, -2, 6, -2, 0, -2, -2, 2, 0, 3, 2, -1, -1, -2, -3, 0}, {-1, -2, -2, -2, 1, -3, -2, 5, -2, 2, 2, -2, -2, -2, -2, -1, 0, 4, -5, -1}, {-1, -5, 0, 0, -5, -2, 0, -2, 5, -3, 0, 1, -1, 1, 3, 0, 0, -2, -3, -4}, {-2, -6, -4, -3, 2, -4, -2, 2, -3, 6, 4, -3, -3, -2, -3, -3, -2, 2, -2, -1}, {-1, -5, -3, -2, 0, -3, -2, 2, 0, 4, 6, -2, -2, -1, 0, -2, -1, 2, -4, -2}, { 0, -4, 2, 1, -4, 0, 2, -2, 1, -3, -2, 2, -1, 1, 0, 1, 0, -2, -4, -2}, { 1, -3, -1, -1, -5, -1, 0, -2, -1, -3, -2, -1, 6, 0, 0, 1, 0, -1, -6, -5}, { 0, -5, 2, 2, -5, -1, 3, -2, 1, -2, -1, 1, 0, 4, 1, -1, -1, -2, -5, -4}, {-2, -4, -1, -1, -4, -3, 2, -2, 3, -3, 0, 0, 0, 1, 6, 0, -1, -2, 2, -4}, { 1, 0, 0, 0, -3, 1, -1, -1, 0, -3, -2, 1, 1, -1, 0, 2, 1, -1, -2, -3}, { 1, -2, 0, 0, -3, 0, -1, 0, 0, -2, -1, 0, 0, -1, -1, 1, 3, 0, -5, -3}, { 0, -2, -2, -2, -1, -1, -2, 4, -2, 2, 2, -2, -1, -2, -2, -1, 0, 4, -6, -2}, {-6, -8, -7, -7, 0, -7, -3, -5, -3, -2, -4, -4, -6, -5, 2, -2, -5, -6, 17, 0}, {-3, 0, -4, -4, 7, -5, 0, -1, -4, -1, -2, -2, -5, -4, -4, -3, -3, -2, 0, 10}, }; phase = 2; /* Convert residue characters to indices */ for (d_loc=0; d_loc<75; d_loc++) { d_monitor = d_loc; for (j=0; j<20; j++) { Kiwi.Pause(); if (d[d_loc] == aa[j]) d_index[d_loc] = j; } for (q_loc=0; q_loc<77; q_loc++) for (j=0; j<20; j++) { Kiwi.Pause(); if (query[q_loc] == aa[j]) q_index[q_loc] = j; } } phase = 4; /* Perhapse 640000ate calculation enough times to get good timing results */ // for (i=1; i<640000; i++) /* Intialize Ins, Del, and H */ for (d_loc=0; d_loc<75+1; d_loc++) { Kiwi.Pause(); d_monitor = d_loc; Ins[d_loc,0] = 0; Del[d_loc,0] = 0; H[d_loc,0] = 0; Hg[d_loc,0] = - 10; } for (q_loc=1; q_loc<77+1; q_loc++) { Kiwi.Pause(); Ins[0,q_loc] = 0; Del[0,q_loc] = 0; H[0,q_loc] = 0; Hg[0,q_loc] = - 10; } phase = 4; /* Do scoring */ for (d_loc=0; d_loc<75; d_loc++) { d_monitor = d_loc; for (q_loc=0; q_loc<77; q_loc++) { Kiwi.Pause(); Ins_c = Ins[d_loc,q_loc+1] - 2; if (Hg[d_loc,q_loc+1] > Ins_c) Ins[d_loc+1,q_loc+1] = Hg[d_loc,q_loc+1]; else Ins[d_loc+1,q_loc+1] = Ins_c; Del_c = Del[d_loc+1,q_loc] - 2; if (Hg[d_loc+1,q_loc] > Del_c) Del[d_loc+1,q_loc+1] = Hg[d_loc+1,q_loc]; else Ins[d_loc+1,q_loc+1] = Del_c; if (Ins[d_loc,q_loc] > Del[d_loc,q_loc]) H_temp = Ins[d_loc,q_loc]; else H_temp = Del[d_loc,q_loc]; if (H_temp < H[d_loc,q_loc]) H_temp = H[d_loc,q_loc]; H[d_loc+1,q_loc+1] = H_temp + S[q_index[q_loc],d_index[d_loc]]; if (H[d_loc+1,q_loc+1] < 0) H[d_loc+1,q_loc+1] = 0; Hg[d_loc+1,q_loc+1] = H[d_loc+1,q_loc+1] - 10; } } phase = 6; Console.WriteLine("Scored h matrix"); for (i = 0; i < 75; i++) { for (j = 0; j < 77; j++) { Kiwi.Pause(); Console.Write("{0} {1} : {2} ", i, j, H[i,j]); Console.WriteLine(""); result = H[i,j]; } } phase = 8; } } } // eof