private void PDBSAlign(object o) { Params p = (Params)o; List <string> toRemove = new List <string>(); MAlignment align = new MAlignment(refSeq.Length); DebugClass.WriteMessage("Started"); foreach (var item in auxFiles[p.k]) { molDic[item].indexMol = new int[refSeq.Length]; MAlignment.alignSeq alignRes = align.Align(refSeq, molDic[item].mol.Chains[0].chainSequence); if (alignRes.seq1.Contains('-')) { ErrorBase.AddErrors("Reference structure " + refStuctName + " cannot be used as reference to " + item + " structure because after alignment gaps to referense structure must be added what is not allowed"); toRemove.Add(item); continue; } //string ss = align.Align(molDic[refStuctName].mol.Chains[0].chainSequence, molDic[item].mol.Chains[0].chainSequence).seq2; string ss = alignRes.seq2; for (int j = 0, count = 0; j < ss.Length; j++) { if (ss[j] != '-') { molDic[item].indexMol[j] = count++; } else { molDic[item].indexMol[j] = -1; } } } DebugClass.WriteMessage("Almost done"); foreach (var item in toRemove) { molDic.Remove(item); } resetEvents[p.k].Set(); }
private void AddAlignment(string item) { MAlignment align = new MAlignment(molDic[refStuctName].mol.Chains[0].chainSequence.Length); molDic[item].indexMol = new int[molDic[refStuctName].mol.Chains[0].chainSequence.Length]; string ss = align.Align(molDic[refStuctName].mol.Chains[0].chainSequence, molDic[item].mol.Chains[0].chainSequence).seq2; for (int j = 0, count = 0; j < ss.Length; j++) { if (ss[j] != '-') { molDic[item].indexMol[j] = count++; } else { molDic[item].indexMol[j] = -1; } } }
public void MakeAlignment(string alignFile) { List <string> toRemove = new List <string>(); if (molDic.Count == 0) { return; } if (molDic.Count == 1) { foreach (var item in molDic.Keys) { molDic[item].indexMol = new int[molDic[item].mol.Chains[0].chainSequence.Length]; for (int i = 0; i < molDic[item].indexMol.Length; i++) { molDic[item].indexMol[i] = i; } } } if (alignFile != null && alignFile.Length > 0) { Dictionary <string, string> al = Alignment.ReadAlignment(alignFile); foreach (var item in molDic.Keys) { string ss; if (al.ContainsKey(item)) { ss = al[item]; molDic[item].indexMol = new int[ss.Length]; for (int j = 0, count = 0; j < ss.Length; j++) { if (ss[j] != '-') { molDic[item].indexMol[j] = count++; } else { molDic[item].indexMol[j] = -1; } } } } } else if (molDic.Count == 2) { using (MAlignment align = new MAlignment(refSeq.Length)) { MAlignment.alignSeq alignRes; List <string> molItems = new List <string>(molDic.Keys); string str1, str2; if (molDic[molItems[0]].mol.Chains[0].chainSequence.Length > molDic[molItems[1]].mol.Chains[0].chainSequence.Length) { str1 = molItems[0]; str2 = molItems[1]; } else { str1 = molItems[1]; str2 = molItems[0]; } alignRes = align.Align(molDic[str1].mol.Chains[0].chainSequence, molDic[str2].mol.Chains[0].chainSequence); molDic[str1].indexMol = new int[alignRes.seq1.Length]; molDic[str2].indexMol = new int[alignRes.seq1.Length]; //string ss = align.Align(molDic[refStuctName].mol.Chains[0].chainSequence, molDic[item].mol.Chains[0].chainSequence).seq2; string ss = alignRes.seq2; for (int j = 0, count = 0; j < ss.Length; j++) { if (ss[j] != '-') { molDic[str2].indexMol[j] = count++; } else { molDic[str2].indexMol[j] = -1; } } ss = alignRes.seq1; for (int j = 0, count = 0; j < ss.Length; j++) { if (ss[j] != '-') { molDic[str1].indexMol[j] = count++; } else { molDic[str1].indexMol[j] = -1; } } } } else { Settings set = new Settings(); set.Load(); int threadNumbers = set.numberOfCores; //return; auxFiles = new List <string> [threadNumbers]; resetEvents = new ManualResetEvent[threadNumbers]; List <string> allFiles = new List <string>(molDic.Keys); for (int i = 0; i < threadNumbers; i++) { auxFiles[i] = new List <string>((i + 1) * molDic.Count / threadNumbers - i * molDic.Count / threadNumbers); for (int j = i * allFiles.Count / threadNumbers; j < (i + 1) * allFiles.Count / threadNumbers; j++) { auxFiles[i].Add(allFiles[j]); } } DebugClass.WriteMessage("Alignment start =" + threadNumbers); //PDBSAlign(auxFiles) for (int i = 0; i < threadNumbers; i++) { //PDBSAlign(auxFiles[i]); Params p = new Params(); p.k = i; resetEvents[p.k] = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(new WaitCallback(PDBSAlign), (object)p); // startProg = Task.Factory.StartNew(() => RunMakeProfiles(fileName,auxFiles,k)); // runnigTask[i] = startProg; } for (int i = 0; i < threadNumbers; i++) { resetEvents[i].WaitOne(); } //WaitHandle.WaitAll(resetEvents); DebugClass.WriteMessage("Alignment stop"); } }