Beispiel #1
0
        public void MyAlign(string alignFile)
        {
            bool test = false;

            //Check if there is sequence that could be aligned
            align = new Dictionary <string, Dictionary <string, string> >();
            foreach (var item in r.profiles)
            {
                align.Add(item.Key, new Dictionary <string, string>());

                if ((alignFile == null || alignFile.Length == 0))
                {
                    refSeq = "";
                    foreach (var pp in item.Value)
                    {
                        if (pp.Value.profile == null)
                        {
                            throw new Exception("For " + pp.Key + " no profile has been found!");
                        }

                        if (refSeq == null || pp.Value.sequence.Length > refSeq.Length)
                        {
                            refSeq = pp.Value.sequence;
                        }
                    }
                    MAlignment al = new MAlignment(refSeq.Length);
                    foreach (var pp in item.Value)
                    {
                        if (pp.Value.sequence != null && refSeq.Length != pp.Value.sequence.Length)
                        {
                            string seq = (al.Align(refSeq, pp.Value.sequence)).seq2;
                            if (seq.Length > 0)
                            {
                                align[item.Key][pp.Key] = seq;
                            }
                        }
                    }
                }
                if (align.Count == 0)
                {
                    throw new Exception("There is no alignment");
                }
            }
            try
            {
                if (dirSettings.mode != INPUTMODE.USER_DEFINED)
                {
                    AlignProfiles();
                }
                else
                {
                    OmitAlignProfiles();
                }
            }
            catch (Exception)
            {
                throw new Exception("Combining alignments went wrong!");
            }
        }
Beispiel #2
0
        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");
                }
        }
Beispiel #3
0
        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();
        }
Beispiel #4
0
        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;
            }

        }
Beispiel #5
0
		public void MyAlign(string alignFile)
		{
            bool test=false;
            //Check if there is sequence that could be aligned            
            foreach (var item in r.profiles)
            {

                foreach (var pp in item.Value)
                {
                    if (pp.Value.profile == null)
                        throw new Exception("No profile has been found!");
                    if (pp.Value.sequence == null || pp.Value.sequence.Length != pp.Value.profile.Count)
                        test = true;
                    break;
                }
                break;
            }
            if ((alignFile!=null && alignFile.Length > 0) || test)
            {
               // align = ReadAlignment(alignFile);

               
                foreach (var item in r.profiles)
                {
                    
                    align = new Dictionary<string, string>(item.Value.Keys.Count);
                    foreach (var pp in item.Value)
                    {
                        string alignProf;
                        char []aux = new char[pp.Value.profile.Count];
                        for(int i=0;i<pp.Value.profile.Count;i++)
                        {                         
                                aux[i]= 'C';
                        }
                        alignProf = new string(aux);
                        align.Add(pp.Key, alignProf);
                    }
                    break;
                }

            }
            else
            {
                    foreach (var item in r.profiles)
                    {
                        foreach (var pp in item.Value)
                        {
                            if (refSeq==null || pp.Value.sequence.Length > refSeq.Length)
                                refSeq = pp.Value.sequence;
                        }
                        break;
                    }
                MAlignment al = new MAlignment(refSeq.Length);
                foreach (var item in r.profiles)
                {
                    foreach (var pp in item.Value)
                    {
                        if (refSeq.Length != pp.Value.sequence.Length)
                        {
                            //Console.WriteLine(pp);

                            string seq = (al.Align(refSeq, pp.Value.sequence)).seq2;
                            if (seq.Length > 0)
                                align[pp.Key] = seq;
                        }
                        else
                            align[pp.Key] = refSeq;
                    }
                    break;

                }
                if (align.Count == 0)
                    throw new Exception("There is no alignment");
            }
            try
            {
                AlignProfiles();
            }
            catch (Exception ex)
            {
                throw new Exception("Combining alignments went wrong!");
            }
			
		}
Beispiel #6
0
        public void AddStructureToAlignment(string protName,string profileName,ref protInfo profile)
        {
           
                MAlignment al = new MAlignment(refSeq.Length);
                string resSeq = (al.Align(refSeq, profile.sequence)).seq2;

                if (!align.ContainsKey(protName))
                    align.Add(protName, resSeq);
                if(!r.profiles[profileName].ContainsKey(protName))
                    r.profiles[profileName].Add(protName,profile);
                
            
            AlignProfile(protName, profileName, profile.profile);
            profile.alignment = r.profiles[profileName][protName].alignment;
          
        }