Esempio n. 1
0
        public static void SetupParallelism(ref string[] args)
        {
            //  Set up MPI
            DAVectorUtility.MPI_Environment  = new MPI.Environment(ref args);
            DAVectorUtility.MPI_communicator = Communicator.world;                    //initializing MPI world communicator
            DAVectorUtility.MPI_Rank         = DAVectorUtility.MPI_communicator.Rank; // Rank of this process
            DAVectorUtility.MPI_Size         = DAVectorUtility.MPI_communicator.Size; // Number of MPI Processes

            // Set up MPI
            DAVectorUtility.MPIperNodeCount = DAVectorUtility.MPI_Size / DAVectorUtility.NodeCount;

            if ((DAVectorUtility.MPIperNodeCount * DAVectorUtility.NodeCount) != DAVectorUtility.MPI_Size)
            {
                Exception e = DAVectorUtility.SALSAError("Inconsistent MPI counts Nodes "
                                                         + DAVectorUtility.NodeCount.ToString() + " Size " + DAVectorUtility.MPI_Size.ToString());

                throw (e);
            }

            DAVectorUtility.ParallelPattern = "---------------------------------------------------------\nMachine:"
                                              + MPI.Environment.ProcessorName.ToString() + " " + DAVectorUtility.ThreadCount.ToString()
                                              + "x" + DAVectorUtility.MPIperNodeCount.ToString() + "x" + DAVectorUtility.NodeCount.ToString();
            if (DAVectorUtility.MPI_Rank == 0)
            {
                DAVectorUtility.SALSAPrint(0, DAVectorUtility.ParallelPattern);
            }
        }   // End SetupParallelism
Esempio n. 2
0
        }   // End ReadDataFromFile

        public static void ReadDataFromFile(string fname, int ClusterPosition, int[] InitialPointAssignment, int StartPointPosition)
        {
            char[] _sep = new[] { ' ', ',', '\t' };

            int FirstPointPosition      = 0;
            int TotalNumberPointstoRead = 0;

            FirstPointPosition      = DAVectorUtility.PointStart_Process;
            TotalNumberPointstoRead = DAVectorUtility.PointCount_Process;

            int MinSplitSize = ClusterPosition + 1;

            if (StartPointPosition >= 0)
            {
                MinSplitSize = Math.Max(MinSplitSize, StartPointPosition + Program.ParameterVectorDimension);
            }

            bool   success          = false;
            string line             = " Unset";
            int    CountLinesinFile = 0;
            string stringtest       = "";

            try
            {
                StreamReader sr = null;
                if (!string.IsNullOrEmpty(fname))
                {
                    Stream stream = File.Open(fname, FileMode.Open, FileAccess.Read, FileShare.Read);
                    sr = new StreamReader(stream);
                }
                if (sr != null)
                {
                    while (!sr.EndOfStream)
                    {
                        line = sr.ReadLine();
                        if (!string.IsNullOrEmpty(line))
                        {
                            string[] splits = line.Trim().Split(_sep, StringSplitOptions.RemoveEmptyEntries);
                            if (splits.Length < MinSplitSize)
                            {
                                DAVectorUtility.SALSAPrint(0, "Count " + CountLinesinFile.ToString() + " Illegal data length on Point file " + splits.Length.ToString()
                                                           + " " + MinSplitSize.ToString() + " " + line);
                                continue;
                            }   // Skip header lines
                            double junk;
                            if (!Double.TryParse(splits[StartPointPosition], out junk))
                            {
                                continue;   // Skip header lines
                            }
                            if (CountLinesinFile < FirstPointPosition)
                            {
                                CountLinesinFile += 1;
                                continue;
                            }

                            int ActualPointPosition = CountLinesinFile - FirstPointPosition;
                            int label = 0;
                            if (StartPointPosition >= 0)
                            {
                                stringtest = "0 *" + splits[StartPointPosition];
                                Program.PointPosition[ActualPointPosition][0] = double.Parse(splits[StartPointPosition]);
                                stringtest = "1 *" + splits[StartPointPosition + 1];
                                Program.PointPosition[ActualPointPosition][1] = double.Parse(splits[StartPointPosition + 1]);
                                if (Program.ParameterVectorDimension > 2)
                                {
                                    for (int VectorIndex = 2; VectorIndex < Program.ParameterVectorDimension; VectorIndex++)
                                    {
                                        stringtest = VectorIndex.ToString() + " *" + splits[StartPointPosition + VectorIndex];
                                        Program.PointPosition[ActualPointPosition][VectorIndex] = double.Parse(splits[VectorIndex + StartPointPosition]);
                                    }
                                }
                            }
                            if (ClusterPosition >= 0)
                            {
                                if (!Int32.TryParse(splits[ClusterPosition], out label))
                                {
                                    label = 1;
                                }
                                InitialPointAssignment[ActualPointPosition] = label - 1;
                            }

                            ++ActualPointPosition;
                            ++CountLinesinFile;
                            if (CountLinesinFile >= (FirstPointPosition + TotalNumberPointstoRead))
                            {
                                break;
                            }
                        }
                    }
                    if (CountLinesinFile != (FirstPointPosition + TotalNumberPointstoRead))
                    {
                        Exception e = DAVectorUtility.SALSAError("Illegal count on Points file " + fname + " Rank " + DAVectorUtility.MPI_Rank.ToString()
                                                                 + " Lines in File " + CountLinesinFile.ToString() + " Number to Read " + TotalNumberPointstoRead.ToString());
                        throw (e);
                    }
                    success = true;
                }
                sr.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(stringtest + "* Failed reading Points data " + DAVectorUtility.MPI_Rank.ToString() + " " + CountLinesinFile.ToString() + " Start "
                                  + FirstPointPosition.ToString() + " Number " + TotalNumberPointstoRead.ToString() + " " + line + e);
                throw (e);
            }
            if (!success)
            {
                Exception e = DAVectorUtility.SALSAError("DA Vector File read error " + fname);
                throw (e);
            }
        }   // End ReadDataFromFile
Esempio n. 3
0
        }   // End ReadDataFromFile

        public static void Read3DDataFromFile(string fname, int VectorSize, int StartPointPosition)
        {
            char[] _sep = new[] { ' ', ',', '\t' };

            int FirstPointPosition      = 0;
            int TotalNumberPointstoRead = 0;

            TotalNumberPointstoRead = DAVectorUtility.PointCount_Global;

            int MinSplitSize = StartPointPosition + VectorSize;

            bool   success          = false;
            string line             = " Unset";
            int    CountLinesinFile = 0;

            try
            {
                StreamReader sr = null;
                if (!string.IsNullOrEmpty(fname))
                {
                    Stream stream = File.Open(fname, FileMode.Open, FileAccess.Read, FileShare.Read);
                    sr = new StreamReader(stream);
                }
                if (sr != null)
                {
                    while (!sr.EndOfStream)
                    {
                        line = sr.ReadLine();
                        if (!string.IsNullOrEmpty(line))
                        {
                            string[] splits = line.Trim().Split(_sep);
                            if (splits.Length < MinSplitSize)
                            {
                                DAVectorUtility.SALSAPrint(0, "Count " + CountLinesinFile.ToString() + " Illegal data length on Point file " + splits.Length.ToString()
                                                           + " " + MinSplitSize.ToString() + " " + line);
                                continue;
                            }   // Skip header lines
                            double junk;
                            if (!Double.TryParse(splits[StartPointPosition], out junk))
                            {
                                continue;   // Skip header lines
                            }
                            if (CountLinesinFile < FirstPointPosition)
                            {
                                CountLinesinFile += 1;
                                continue;
                            }

                            int ActualPointPosition = CountLinesinFile - FirstPointPosition;
                            if (StartPointPosition >= 0)
                            {
                                Program.FullPoint3DPosition[ActualPointPosition][0] = double.Parse(splits[StartPointPosition]);
                                Program.FullPoint3DPosition[ActualPointPosition][1] = double.Parse(splits[StartPointPosition + 1]);
                                if (VectorSize > 2)
                                {
                                    for (int VectorIndex = 2; VectorIndex < VectorSize; VectorIndex++)
                                    {
                                        Program.FullPoint3DPosition[ActualPointPosition][VectorIndex] = double.Parse(splits[VectorIndex + StartPointPosition]);
                                    }
                                }
                            }

                            ++ActualPointPosition;
                            ++CountLinesinFile;
                            if (CountLinesinFile >= (FirstPointPosition + TotalNumberPointstoRead))
                            {
                                break;
                            }
                        }
                    }
                    if (CountLinesinFile != (FirstPointPosition + TotalNumberPointstoRead))
                    {
                        Exception e = DAVectorUtility.SALSAError("Illegal count on Points file " + fname + " Rank " + DAVectorUtility.MPI_Rank.ToString()
                                                                 + " Lines in File " + CountLinesinFile.ToString() + " Number to Read " + TotalNumberPointstoRead.ToString());
                        throw (e);
                    }
                    success = true;
                }
                sr.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed reading Points data " + DAVectorUtility.MPI_Rank.ToString() + " " + CountLinesinFile.ToString() + " Start "
                                  + FirstPointPosition.ToString() + " Number " + TotalNumberPointstoRead.ToString() + " " + line + e);
                throw (e);
            }
            if (!success)
            {
                Exception e = DAVectorUtility.SALSAError("DA Vector File read error " + fname);
                throw (e);
            }
        } // End Read3DDataFromFile
Esempio n. 4
0
        }   // End ReadLabelsFromFile

        // read point data from file to memory
        // OutputFileType = 0 Harvard Format Cosmic Index mz RT Charge Peptide Peptide.id Mclust Medea
        // OutputFileType = 1 Ingest output file:   Index mz RT  0.0 Cluster#
        public static void AnalyzeDataFromFile(string fname)
        {
            char[] _sep      = new[] { ' ', '\t' };
            int    Maxcounts = 200;

            int[] CountLabels = new int[Maxcounts];
            for (int ChargeIndex = 0; ChargeIndex < Maxcounts; ChargeIndex++)
            {
                CountLabels[ChargeIndex] = 0;
            }
            int MinSplitSize  = Program.ParameterVectorDimension + 3;
            int SplitPosition = 1 + Program.ParameterVectorDimension;

            if (Program.InputFileType == 1)
            {
                MinSplitSize  = 5;
                SplitPosition = 4;
            }
            bool success = false;
            int  count   = 0;

            try
            {
                StreamReader sr = null;
                if (!string.IsNullOrEmpty(fname))
                {
                    Stream stream = File.Open(fname, FileMode.Open, FileAccess.Read, FileShare.Read);
                    sr = new StreamReader(stream);
                }
                if (sr != null)
                {
                    string line;
                    while (!sr.EndOfStream)
                    {
                        line = sr.ReadLine();
                        if (!string.IsNullOrEmpty(line))
                        {
                            string[] splits = line.Trim().Split(_sep);
                            if (splits.Length < MinSplitSize)
                            {
                                Exception e = DAVectorUtility.SALSAError("Count " + count.ToString() + "Illegal data length on Point file " + splits.Length.ToString()
                                                                         + " " + MinSplitSize.ToString() + " " + line);
                                throw (e);
                            }
                            int Charge = -101;
                            if (!Int32.TryParse(splits[SplitPosition], out Charge))
                            {
                                continue;
                            }
                            if ((Program.SelectedInputLabel < 0) && (Charge == -Program.SelectedInputLabel))
                            {
                                continue;
                            }
                            int position = 1 + Charge;
                            position = Math.Max(0, position);
                            position = Math.Min(Maxcounts - 1, position);
                            ++CountLabels[position];
                            count++;
                        }
                    }
                    success = true;
                    if (Program.SelectedInputLabel >= 0)
                    {
                        DAVectorUtility.PointCount_Global = CountLabels[1 + Program.SelectedInputLabel];
                    }
                    else
                    {
                        DAVectorUtility.PointCount_Global = 0;
                        for (int selection = 0; selection < Maxcounts; selection++)
                        {
                            DAVectorUtility.PointCount_Global += CountLabels[selection];
                        }
                    }
                    DAVectorUtility.SALSAPrint(1, "File Analyzed " + fname + " Total " + count.ToString());
                    string label = "Charge";
                    if (Program.InputFileType == 1)
                    {
                        label = "Cluster";
                    }
                    if (CountLabels[0] > 0)
                    {
                        DAVectorUtility.SALSAPrint(1, "Negative " + label + "s " + CountLabels[0].ToString());
                    }
                    for (int LabelIndex = 1; LabelIndex < (Maxcounts - 1); LabelIndex++)
                    {
                        if (CountLabels[LabelIndex] > 0)
                        {
                            DAVectorUtility.SALSAPrint(1, label + " " + (LabelIndex - 1).ToString() + " Count " + CountLabels[LabelIndex].ToString());
                        }
                    }
                    if (CountLabels[Maxcounts - 1] > 0)
                    {
                        DAVectorUtility.SALSAPrint(1, "Overflow " + label + "s " + CountLabels[Maxcounts - 1].ToString());
                    }
                }
                sr.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed reading Points data" + e);
                throw (e);
            }
            if (!success)
            {
                Exception e = DAVectorUtility.SALSAError("DA Vector File Analyze error " + fname);
                throw (e);
            }
        }   // End AnalyzeDataFromFile