Example #1
0
/*        private Dictionary<string,double> SableDist(List<string> refStructures)
 *      {
 *          StreamReader sableFile = new StreamReader(textBox3.Text);
 *          string line = sableFile.ReadLine();
 *          string prefix=refStructures[0];
 *          protInfo pr_SS=new protInfo();
 *          protInfo pr_SA = new protInfo();
 *          string seq, ss, sa;
 *          if(prefix.Contains("\\"))
 *          {
 *              string []aux=prefix.Split('\\');
 *              prefix=aux[aux.Length-2];
 *          }
 *          while (line !=null)
 *          {
 *              if(line.StartsWith("Query:"))
 *              {
 *                  string[] aux = line.Split(' ');
 *                  aux = aux[1].Split('.');
 *                  if (prefix.Contains(aux[0]))
 *                  {
 *                      pr_SS.sequence = sableFile.ReadLine();
 *                      string ww=sableFile.ReadLine();
 *                      pr_SS.profile = new List<byte>();
 *                      for (int i = 0; i < ww.Length;i++ )
 *                          pr_SS.profile.Add(ww[i].ToString());
 *                      line = sableFile.ReadLine();
 *                      pr_SA.sequence = pr_SS.sequence;
 *                      pr_SA.profile = new List<string>(Regex.Replace(sableFile.ReadLine(),@"\s+"," ").Trim().Split(' '));
 *                      for (int i = 0; i < pr_SA.profile.Count; i++)
 *                          pr_SA.profile[i] = (Convert.ToInt16(pr_SA.profile[i]) / 10).ToString();
 *
 *                  }
 *              }
 *              line = sableFile.ReadLine();
 *          }
 *
 *          sableFile.Close();
 *          Settings set=new Settings();
 *          set.Load();
 *          Alignment al=new Alignment(refStructures,set,"H:\\profiels\\SS3_SA9_internal.profiles");
 *          al.MyAlign(null);
 *          al.AddStructureToAlignment("sable_res","SS", ref pr_SS);
 *          al.AddStructureToAlignment("sable_res", "SA", ref pr_SA);
 *
 *          Dictionary<string, Dictionary<string, protInfo>> allProf = new Dictionary<string, Dictionary<string, protInfo>>();
 *          allProf.Add("SS", new Dictionary<string, protInfo>());
 *          allProf["SS"].Add("sable_res", pr_SS);
 *          allProf.Add("SA", new Dictionary<string, protInfo>());
 *          allProf["SA"].Add("sable_res", pr_SA);
 *          Dictionary<string,List<string>> protCombineStates = al.CombineProfiles("sable_res", allProf);
 *
 *
 *          JuryDistance dist = new JuryDistance(al, false);
 *
 *          Dictionary<string, double> distRes = new Dictionary<string, double>();
 *
 *          foreach (var item in refStructures)
 *          {
 *              distRes.Add(Path.GetFileName(item), dist.GetDistance("sable_res",Path.GetFileName(item)));
 *              currentV++;
 *          }
 *
 *
 *          return distRes;
 *
 *      }*/
        private DistanceMeasure PrepareDistanceMeasure(List <string> cluster, DistanceMeasures measure, string dirName)
        {
            DistanceMeasure distRes    = null;
            List <string>   clustFiles = new List <string>();

            foreach (var item in cluster)
            {
                clustFiles.Add(dirName + Path.DirectorySeparatorChar + item);
            }
            switch (measure)
            {
            case DistanceMeasures.HAMMING:
                distRes = new JuryDistance(clustFiles, alignFile, true, distanceControl1.profileName);
                break;

            case DistanceMeasures.MAXSUB:
            {
                distRes = new MaxSub(clustFiles, alignFile, distanceControl1.reference);
            }
            break;

            case DistanceMeasures.RMSD:
                distRes = new Rmsd(clustFiles, alignFile, distanceControl1.reference, distanceControl1.CAtoms, distanceControl1.referenceProfile);
                break;
            }
            distRes.InitMeasure();
            return(distRes);
        }
Example #2
0
        private StatClust Calc(ClusterOutput outp, bool flag)
        {
            List <string> five      = new List <string>();
            List <string> listFiles = new List <string>();

            //if (outp == null || outp.clusters == null)
            //    return null;

            if (outp == null || outp.dirName == null)
            {
                return(null);
            }
            string [] aux    = outp.dirName.Split(Path.DirectorySeparatorChar);
            string    native = aux[aux.Length - 1] + ".pdb";

            string dirM = "";

            for (int i = 0; i < aux.Length - 1; i++)
            {
                dirM += aux[i] + Path.DirectorySeparatorChar;
            }
            native = dirM + native;
            if (!File.Exists(native))
            {
                return(null);
            }

            five.Add(native);
            jury1D jury;

            if (outp.clusters != null)
            {
                outp.clusters.Sort((a, b) => b.Count.CompareTo(a.Count));
                int end = outp.clusters.Count;
                if (outp.clusters.Count > 5)
                {
                    end = 5;
                }



                for (int i = 0; i < end; i++)
                {
                    listFiles.Clear();
                    foreach (var item in outp.clusters[i])
                    {
                        listFiles.Add(outp.dirName + Path.DirectorySeparatorChar + item);
                    }

                    //
                    //
                    //Sift sift = new Sift(listFiles);
                    //ClusterOutput oo = sift.Shape();
                    if (flag)
                    {
                        DistanceMeasure distRmsd = new Rmsd(listFiles, "", false, uQlustCore.PDB.PDBMODE.ONLY_CA);
                        distRmsd.InitMeasure();
                        string strName = distRmsd.GetReferenceStructure(outp.clusters[i]);

                        five.Add(outp.dirName + Path.DirectorySeparatorChar + strName);
                    }
                    else
                    {
                        jury = new jury1D();
                        //jury.PrepareJury(listFiles, "", "Z:\\dcd\\SS3_SA9_jury_internal.profiles");
                        ClusterOutput oo = jury.JuryOptWeights(outp.clusters[i]);
                        if (oo == null)
                        {
                            continue;
                        }
                        five.Add(outp.dirName + Path.DirectorySeparatorChar + oo.juryLike[0].Key);
                    }

                    //five.Add(outp.dirName + Path.DirectorySeparatorChar + outp.clusters[i][0]);
                }
            }
            if (outp.hNode != null)
            {
                int end;
                List <List <string> > cli = outp.hNode.GetClusters(10);

                cli.Sort((a, b) => b.Count.CompareTo(a.Count));

                outp.clusters = new List <List <string> >();
                end           = cli.Count;
                if (cli.Count > 5)
                {
                    end = 5;
                }
                for (int i = 0; i < end; i++)
                {
                    // listFiles.Clear();
                    //foreach (var item in cli[i])
                    //{
                    //listFiles.Add(

                    //}

                    listFiles.Clear();
                    foreach (var item in cli[i])
                    {
                        listFiles.Add(outp.dirName + Path.DirectorySeparatorChar + item);
                    }

                    jury = new jury1D();
                    jury.PrepareJury(listFiles, "", "C:\\data\\dcd\\SS8_SA3_jury_internal.profiles");

                    outp.clusters.Add(cli[0]);  //jury

                    ClusterOutput oo = jury.JuryOptWeights(cli[i]);
                    if (oo == null)
                    {
                        continue;
                    }
                    five.Add(outp.dirName + Path.DirectorySeparatorChar + cli[i][0]);
                    //five.Add(outp.dirName + Path.DirectorySeparatorChar + strName);
                }
            }
            if (outp.juryLike != null)
            {
                int end = outp.juryLike.Count;
                if (outp.juryLike.Count > 5)
                {
                    end = 5;
                }

                for (int i = 0; i < end; i++)
                {
                    five.Add(outp.dirName + Path.DirectorySeparatorChar + outp.juryLike[i].Key);
                }
            }
            //          DistanceMeasure dist;
            //           dist = new Rmsd(five, "", false, PDB.PDBMODE.ONLY_CA);
            //  dist = new MaxSub(five, "", false);

            Dictionary <string, double> cc = ReadScore(aux[aux.Length - 1]);


            if (cc == null)
            {
                return(null);
            }

            StatClust stCLust = new StatClust();

            string[] tt1 = native.Split(Path.DirectorySeparatorChar);
            stCLust.native = tt1[tt1.Length - 1];
            for (int i = 1; i < five.Count; i++)
            {
                string[] tt2 = five[i].Split(Path.DirectorySeparatorChar);
                //  double rmsd = dist.GetDistance(tt1[tt1.Length-1], tt2[tt2.Length-1]) /100.0;
                double rmsd = 0;
                if (cc.ContainsKey(tt2[tt2.Length - 1]))
                {
                    rmsd = cc[tt2[tt2.Length - 1]];
                }


                if (rmsd > stCLust.rmsd)
                {
                    if (outp.juryLike != null)
                    {
                        stCLust.size = outp.juryLike.Count;
                    }
                    else
                    {
                        stCLust.size = outp.clusters[i - 1].Count;
                    }
                    stCLust.rmsd = rmsd;
                    string[] dd = five[i].Split(Path.DirectorySeparatorChar);
                    stCLust.reference = dd[dd.Length - 1];
                }
            }
            if (stCLust.rmsd < 1000)
            {
                avrSum += stCLust.rmsd;
                avrCount++;
            }
            if (outp.hNode != null)
            {
                outp.clusters.Clear();
                outp.clusters = null;
            }

            return(stCLust);
        }
Example #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            string[] aux;
            if (checkBox1.Checked)
            {
                if (jury1DSetup1.profileName == null || jury1DSetup1.profileName.Length == 0)
                {
                    MessageBox.Show("Profile name for 1djury must be specified!");
                    this.DialogResult = DialogResult.None;
                    return;
                }
                jury1D jury = new jury1D();
                jury.PrepareJury(structures, "", jury1DSetup1.profileName);
                List <string> prep = new List <string>();
                foreach (var item in structures)
                {
                    aux = item.Split(Path.DirectorySeparatorChar);
                    prep.Add(aux[aux.Length - 1]);
                }
                ClusterOutput oc = jury.JuryOptWeights(prep);

                for (int i = 0; i < selectBest1.bestNumber; i++)
                {
                    bestJuryStructures.Add(oc.juryLike[i].Key);
                }
            }
            this.DialogResult = DialogResult.OK;
            if (selectBest1.getFileName != null && File.Exists(selectBest1.getFileName))
            {
                DistanceMeasures measure = selectBest1.measure;

                structures.Add(selectBest1.getFileName);

                DistanceMeasure dist = null;
                switch (measure)
                {
                case DistanceMeasures.HAMMING:
                    dist = new JuryDistance(structures, "", false, selectBest1.hammingProfile);
                    break;

                case DistanceMeasures.MAXSUB:
                    dist = new MaxSub(structures, "", false);
                    break;

                case DistanceMeasures.RMSD:
                    dist = new Rmsd(structures, "", false, selectBest1.CAtoms);
                    break;
                }

                List <KeyValuePair <string, int> > distList = new List <KeyValuePair <string, int> >();
                aux = selectBest1.getFileName.Split(Path.DirectorySeparatorChar);
                dist.InitMeasure();
                string native = aux[aux.Length - 1];
                foreach (var item in structures)
                {
                    aux = item.Split(Path.DirectorySeparatorChar);
                    int val = dist.GetDistance(native, aux[aux.Length - 1]);
                    distList.Add(new KeyValuePair <string, int>(aux[aux.Length - 1], val));
                }

                distList.Sort((firstPair, nextPair) =>
                {
                    return(firstPair.Value.CompareTo(nextPair.Value));
                });

                for (int i = 0; i < selectBest1.bestNumber; i++)
                {
                    bestStructures.Add(distList[i].Key);
                }
            }
        }