| 1 | #include "muscle.h" |
|---|
| 2 | #include "tree.h" |
|---|
| 3 | #include "profile.h" |
|---|
| 4 | #include "msa.h" |
|---|
| 5 | #include "seqvect.h" |
|---|
| 6 | #include "pwpath.h" |
|---|
| 7 | |
|---|
| 8 | static void DoSeq(Seq &s, unsigned uSeqIndex, const ProfPos *RootProf, |
|---|
| 9 | unsigned uRootProfLength, MSA &msaOut) |
|---|
| 10 | { |
|---|
| 11 | MSA msaSeq; |
|---|
| 12 | msaSeq.FromSeq(s); |
|---|
| 13 | const unsigned uSeqLength = s.Length(); |
|---|
| 14 | |
|---|
| 15 | MSA msaDummy; |
|---|
| 16 | msaDummy.SetSize(1, uRootProfLength); |
|---|
| 17 | msaDummy.SetSeqId(0, 0); |
|---|
| 18 | msaDummy.SetSeqName(0, "Dummy0"); |
|---|
| 19 | for (unsigned uColIndex = 0; uColIndex < uRootProfLength; ++uColIndex) |
|---|
| 20 | msaDummy.SetChar(0, uColIndex, '?'); |
|---|
| 21 | |
|---|
| 22 | ProfPos *SeqProf = ProfileFromMSA(msaSeq); |
|---|
| 23 | for (unsigned uColIndex = 0; uColIndex < uSeqLength; ++uColIndex) |
|---|
| 24 | { |
|---|
| 25 | ProfPos &PP = SeqProf[uColIndex]; |
|---|
| 26 | PP.m_scoreGapOpen = MINUS_INFINITY; |
|---|
| 27 | PP.m_scoreGapClose = MINUS_INFINITY; |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | ProfPos *ProfOut; |
|---|
| 31 | unsigned uLengthOut; |
|---|
| 32 | PWPath Path; |
|---|
| 33 | AlignTwoProfs(SeqProf, uSeqLength, 1.0, RootProf, uRootProfLength, 1.0, |
|---|
| 34 | Path, &ProfOut, &uLengthOut); |
|---|
| 35 | assert(uLengthOut = uRootProfLength); |
|---|
| 36 | delete[] ProfOut; |
|---|
| 37 | |
|---|
| 38 | MSA msaCombined; |
|---|
| 39 | AlignTwoMSAsGivenPath(Path, msaSeq, msaDummy, msaCombined); |
|---|
| 40 | |
|---|
| 41 | msaCombined.LogMe(); |
|---|
| 42 | msaOut.SetSeqName(uSeqIndex, s.GetName()); |
|---|
| 43 | msaOut.SetSeqId(uSeqIndex, s.GetId()); |
|---|
| 44 | for (unsigned uColIndex = 0; uColIndex < uRootProfLength; ++uColIndex) |
|---|
| 45 | msaOut.SetChar(uSeqIndex, uColIndex, msaCombined.GetChar(0, uColIndex)); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | // Steven Brenner's O(NL^2) proposal for creating a root alignment |
|---|
| 49 | // Align each sequence to the profile at the root. |
|---|
| 50 | // Compare the e-string solution, which is O(NL log N). |
|---|
| 51 | void MakeRootMSABrenner(SeqVect &v, const Tree &GuideTree, ProgNode Nodes[], |
|---|
| 52 | MSA &a) |
|---|
| 53 | { |
|---|
| 54 | const unsigned uSeqCount = v.Length(); |
|---|
| 55 | const unsigned uRootNodeIndex = GuideTree.GetRootNodeIndex(); |
|---|
| 56 | const ProfPos *RootProfile = Nodes[uRootNodeIndex].m_Prof; |
|---|
| 57 | const unsigned uRootColCount = Nodes[uRootNodeIndex].m_uLength; |
|---|
| 58 | a.SetSize(uSeqCount, uRootColCount); |
|---|
| 59 | |
|---|
| 60 | for (unsigned uSeqIndex = 0; uSeqIndex < uSeqCount; ++uSeqIndex) |
|---|
| 61 | DoSeq(*v[uSeqIndex], uSeqIndex, RootProfile, uRootColCount, a); |
|---|
| 62 | } |
|---|