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"); } }
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; 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"); } }
public override void RunThreads(string fileName) { List<string> files = CheckFile(fileName); if (files.Count == 0) return; //Task[] runnigTask = new Task[threadNumbers]; //Task startProg; maxV = files.Count*2; ReadPdbs(files); if (pdbs.molDic.Count == 0) return; string aux = Path.GetDirectoryName(files[0]).TrimEnd(Path.DirectorySeparatorChar); string refSeqFile = aux+".ref"; if(File.Exists(refSeqFile)) pdbs.ReadRefSeq(refSeqFile); else pdbs.FindReferenceSeq(); pdbs.MakeAlignment(null); if (contOne == null) { string molDicKey=""; foreach (var item in pdbs.molDic.Keys) { molDicKey = item; break; } int len = pdbs.molDic[molDicKey].indexMol.Length; contOne = new int[len * (len + 1) / 2]; contact = new byte[threadNumbers][]; contactToString=new char [threadNumbers][]; for(int i=0;i<threadNumbers;i++) { contact[i]=new byte [len * (len + 1) / 2]; contactToString[i]=new char [len * (len + 1)]; } for (int i = 0; i < contOne.Length; i++) contOne[i] =0; for (int i = 0; i < threadNumbers; i++) for (int j = 0; j < contOne.Length; j++) contact[i][j] = 0; } auxFiles =new List<string>[threadNumbers]; List<string> allFiles = new List<string>(pdbs.molDic.Keys); for (int i = 0; i < threadNumbers; i++) { auxFiles[i] = new List<string>((i + 1) * pdbs.molDic.Count / threadNumbers - i * pdbs.molDic.Count / threadNumbers); for (int j = i * allFiles.Count / threadNumbers; j < (i + 1) * allFiles.Count / threadNumbers; j++) auxFiles[i].Add(files[j]); } for (int i = 0; i < threadNumbers; i++) { Params p = new Params(); p.fileName = fileName; p.k = i; resetEvents[p.k] = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(new WaitCallback(RunMakeProfiles), (object)p); } for (int i = 0; i < threadNumbers; i++) resetEvents[i].WaitOne(); //JoinFiles(fileName); CuttProfiles(fileName); currentProgress = maxV; }