[Test] public void Align2() { string matrixPath = @"../../matrices/TEST1"; if (!File.Exists(matrixPath)) { matrixPath = @"TEST1"; } Matrix customMatrix = Matrix.Load(matrixPath); Sequence seq1 = Sequence.Parse(@"AACCC"); Sequence seq2 = Sequence.Parse(@"CCACC"); float opengap = 2.0f; float extendgap = 1.0f; Alignment alignment = SmithWatermanGotoh.Align(seq1, seq2, customMatrix, opengap, extendgap); Assert.AreEqual(alignment.Sequence1.Length, 3, "#A00 Unexpected aligment"); Assert.AreEqual(alignment.Sequence2.Length, 3, "#A01 Unexpected aligment"); Assert.AreEqual(alignment.Sequence1[0], 'A', "#A02 Unexpected alignement"); Assert.AreEqual(alignment.Sequence1[1], 'C', "#A03 Unexpected alignement"); Assert.AreEqual(alignment.Sequence1[2], 'C', "#A04 Unexpected alignement"); Assert.AreEqual(alignment.Sequence2[0], 'A', "#A05 Unexpected alignement"); Assert.AreEqual(alignment.Sequence2[1], 'C', "#A06 Unexpected alignement"); Assert.AreEqual(alignment.Sequence2[2], 'C', "#A07 Unexpected alignement"); Assert.AreEqual(15.0f, alignment.Score, "#A08 Unexpected score."); }
[Test] public void Align() { string matrixPath = @"../../matrices/PAM250"; if (!File.Exists(matrixPath)) { matrixPath = @"PAM250"; } Matrix pam250 = Matrix.Load(matrixPath); float opengap = 15.0f; float extendgap = 3.0f; string str1 = @">100K_RAT 100 kDa protein (EC 6.3.2.-)." + NL + "MMSARGDFLN YALSLMRSHN DEHSDVLPVL DVCSLKHVAY VFQALIYWIK AMNQQTTLDT" + "PQLERKRTRE LLELGIDNED SEHENDDDTS QSATLNDKDD ESLPAETGQN HPFFRRSDSM" + "TFLGCIPPNP FEVPLAEAIP LADQPHLLQP NARKEDLFGR PSQGLYSSSA GSGKCLVEVT" + "MDRNCLEVLP TKMSYAANLK NVMNMQNRQK KAGEDQSMLA EEADSSKPGP SAHDVAAQLK" + "SSLLAEIGLT ESEGPPLTSF RPQCSFMGMV ISHDMLLGRW RLSLELFGRV FMEDVGAEPG" + "SILTELGGFE VKESKFRREM EKLRNQQSRD LSLEVDRDRD LLIQQTMRQL NNHFGRRCAT" + "TPMAVHRVKV TFKDEPGEGS GVARSFYTAI AQAFLSNEKL PNLDCIQNAN KGTHTSLMQR" + "LRNRGERDRE REREREMRRS SGLRAGSRRD RDRDFRRQLS IDTRPFRPAS EGNPSDDPDP" + "LPAHRQALGE RLYPRVQAMQ PAFASKITGM LLELSPAQLL LLLASEDSLR ARVEEAMELI" + "VAHGRENGAD SILDLGLLDS SEKVQENRKR HGSSRSVVDM DLDDTDDGDD NAPLFYQPGK" + "RGFYTPRPGK NTEARLNCFR NIGRILGLCL LQNELCPITL NRHVIKVLLG RKVNWHDFAF" + "FDPVMYESLR QLILASQSSD ADAVFSAMDL AFAVDLCKEE GGGQVELIPN GVNIPVTPQN" + "VYEYVRKYAE HRMLVVAEQP LHAMRKGLLD VLPKNSLEDL TAEDFRLLVN GCGEVNVQML" + "ISFTSFNDES GENAEKLLQF KRWFWSIVER MSMTERQDLV YFWTSSPSLP ASEEGFQPMP" + "SITIRPPDDQ HLPTANTCIS RLYVPLYSSK QILKQKLLLA IKTKNFGFV"; string str2 = @">104K_THEPA 104 kDa microneme-rhoptry antigen." + NL + "MKFLILLFNI LCLFPVLAAD NHGVGPQGAS GVDPITFDIN SNQTGPAFLT AVEMAGVKYL" + "QVQHGSNVNI HRLVEGNVVI WENASTPLYT GAIVTNNDGP YMAYVEVLGD PNLQFFIKSG" + "DAWVTLSEHE YLAKLQEIRQ AVHIESVFSL NMAFQLENNK YEVETHAKNG ANMVTFIPRN" + "GHICKMVYHK NVRIYKATGN DTVTSVVGFF RGLRLLLINV FSIDDNGMMS NRYFQHVDDK" + "YVPISQKNYE TGIVKLKDYK HAYHPVDLDI KDIDYTMFHL ADATYHEPCF KIIPNTGFCI" + "TKLFDGDQVL YESFNPLIHC INEVHIYDRN NGSIICLHLN YSPPSYKAYL VLKDTGWEAT" + "THPLLEEKIE ELQDQRACEL DVNFISDKDL YVAALTNADL NYTMVTPRPH RDVIRVSDGS" + "EVLWYYEGLD NFLVCAWIYV SDGVASLVHL RIKDRIPANN DIYVLKGDLY WTRITKIQFT" + "QEIKRLVKKS KKKLAPITEE DSDKHDEPPE GPGASGLPPK APGDKEGSEG HKGPSKGSDS" + "SKEGKKPGSG KKPGPAREHK PSKIPTLSKK PSGPKDPKHP RDPKEPRKSK SPRTASPTRR" + "PSPKLPQLSK LPKSTSPRSP PPPTRPSSPE RPEGTKIIKT SKPPSPKPPF DPSFKEKFYD" + "DYSKAASRSK ETKTTVVLDE SFESILKETL PETPGTPFTT PRPVPPKRPR TPESPFEPPK" + "DPDSPSTSPS EFFTPPESKR TRFHETPADT PLPDVTAELF KEPDVTAETK SPDEAMKRPR" + "SPSEYEDTSP GDYPSLPMKR HRLERLRLTT TEMETDPGRM AKDASGKPVK LKRSKSFDDL" + "TTVELAPEPK ASRIVVDDEG TEADDEETHP PEERQKTEVR RRRPPKKPSK SPRPSKPKKP" + "KKPDSAYIPS ILAILVVSLI VGIL"; Sequence seq1 = Sequence.Parse(str1); Sequence seq2 = Sequence.Parse(str2); Alignment alignment = SmithWatermanGotoh.Align(seq1, seq2, pam250, opengap, extendgap); Assert.AreEqual(98.0f, alignment.Score, "Unexpected score."); }
/// <summary> Aligns two sequences by Smith-Waterman algorithm</summary> /// <param name="s1">sequene #1 </param> /// <param name="s2">sequene #2 </param> /// <param name="matrix">scoring matrix </param> /// <param name="o">open gap penalty </param> /// <param name="e">extend gap penalty </param> /// <returns> alignment object contains the two aligned sequences, /// the alignment score and alignment statistics</returns> /// <seealso cref="Sequence"/> /// <seealso cref="Matrix"/> public static Alignment Align(Sequence s1, Sequence s2, Matrix matrix, float o, float e) { float[,] scores = matrix.Scores; SmithWatermanGotoh sw = new SmithWatermanGotoh(); int m = s1.Length + 1; int n = s2.Length + 1; byte[] pointers = new byte[m * n]; // Initializes the boundaries of the traceback matrix to STOP. for (int i = 0, k = 0; i < m; i++, k += n) { pointers[k] = Directions.STOP; } for (int j = 1; j < n; j++) { pointers[j] = Directions.STOP; } short[] sizesOfVerticalGaps = new short[m * n]; short[] sizesOfHorizontalGaps = new short[m * n]; for (int i = 0, k = 0; i < m; i++, k += n) { for (int j = 0; j < n; j++) { sizesOfVerticalGaps[k + j] = sizesOfHorizontalGaps[k + j] = 1; } } Cell cell = sw.Construct(s1, s2, scores, o, e, pointers, sizesOfVerticalGaps, sizesOfHorizontalGaps); Alignment alignment = sw.Traceback(s1, s2, matrix, pointers, cell, sizesOfVerticalGaps, sizesOfHorizontalGaps); alignment.Name1 = s1.Id; alignment.Name2 = s2.Id; alignment.Matrix = matrix; alignment.Open = o; alignment.Extend = e; return alignment; }
/// <summary> Aligns two sequences by Smith-Waterman algorithm</summary> /// <param name="s1">sequene #1 </param> /// <param name="s2">sequene #2 </param> /// <param name="matrix">scoring matrix </param> /// <param name="o">open gap penalty </param> /// <param name="e">extend gap penalty </param> /// <returns> alignment object contains the two aligned sequences, /// the alignment score and alignment statistics</returns> /// <seealso cref="Sequence"/> /// <seealso cref="Matrix"/> public static Alignment Align(Sequence s1, Sequence s2, Matrix matrix, float o, float e) { float[,] scores = matrix.Scores; SmithWatermanGotoh sw = new SmithWatermanGotoh(); int m = s1.Length + 1; int n = s2.Length + 1; byte[] pointers = new byte[m * n]; // Initializes the boundaries of the traceback matrix to STOP. for (int i = 0, k = 0; i < m; i++, k += n) { pointers[k] = Directions.STOP; } for (int j = 1; j < n; j++) { pointers[j] = Directions.STOP; } short[] sizesOfVerticalGaps = new short[m * n]; short[] sizesOfHorizontalGaps = new short[m * n]; for (int i = 0, k = 0; i < m; i++, k += n) { for (int j = 0; j < n; j++) { sizesOfVerticalGaps[k + j] = sizesOfHorizontalGaps[k + j] = 1; } } Cell cell = sw.Construct(s1, s2, scores, o, e, pointers, sizesOfVerticalGaps, sizesOfHorizontalGaps); Alignment alignment = sw.Traceback(s1, s2, matrix, pointers, cell, sizesOfVerticalGaps, sizesOfHorizontalGaps); alignment.Name1 = s1.Id; alignment.Name2 = s2.Id; alignment.Matrix = matrix; alignment.Open = o; alignment.Extend = e; return(alignment); }
[Test] public void Align2() { string matrixPath = @"../../matrices/TEST1"; if (!File.Exists(matrixPath)) { matrixPath = @"TEST1"; } Matrix customMatrix = Matrix.Load(matrixPath); Sequence seq1 = Sequence.Parse(@"AACCC"); Sequence seq2 = Sequence.Parse(@"CCACC"); float opengap = 2.0f; float extendgap = 1.0f; Alignment alignment = SmithWatermanGotoh.Align(seq1, seq2, customMatrix, opengap, extendgap); Assert.AreEqual(14.0f, alignment.Score, "Unexpected score."); }