Exemplo n.º 1
0
        public void TestGetClusters()
        {
            var neighbours = new NeighbourList();

            neighbours.Add(0, 1);
            neighbours.Add(2, 3);
            var clusters = neighbours.GetAllClusters();

            Assert.AreEqual(2, clusters.Length);
            CollectionAssert.AreEqual(new [] { 0, 1 }, clusters[0]);
            CollectionAssert.AreEqual(new [] { 2, 3 }, clusters[1]);
        }
Exemplo n.º 2
0
        /// <summary>
        /// To Get Neighbour Details
        /// </summary>
        /// <param name="householdID"></param>
        /// <returns></returns>
        public NeighbourList GetneigbrDetails(int householdID)
        {
            OracleConnection cnn = new OracleConnection(AppConfiguration.ConnectionString);
            OracleCommand    cmd;

            string proc = "USP_TRN_SEL_NEIGHBOUR";

            cmd             = new OracleCommand(proc, cnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("HHID_", householdID);
            cmd.Parameters.Add("Sp_recordset", Oracle.DataAccess.Client.OracleDbType.RefCursor).Direction = ParameterDirection.Output;

            cmd.Connection.Open();
            OracleDataReader dr               = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            NeighbourBO      Neighbourobj     = null;
            NeighbourList    NeighbourListobj = new NeighbourList();

            while (dr.Read())
            {
                Neighbourobj = new NeighbourBO();
                Neighbourobj.PAP_NEIGHBOURID1       = Convert.ToInt32(dr.GetValue(dr.GetOrdinal("PAP_NEIGHBOURID")));
                Neighbourobj.TRN_PAP_NEIGHBOURNAme1 = dr.GetString(dr.GetOrdinal("NEIGHBOURNAME"));
                Neighbourobj.ISDELETED1             = dr.GetString(dr.GetOrdinal("ISDELETED"));
                Neighbourobj.DIRECTION1             = dr.GetString(dr.GetOrdinal("DIRECTION"));
                Neighbourobj.BOUNDARIESCONFIRMED1   = dr.GetString(dr.GetOrdinal("BOUNDARIESCONFIRMED"));
                Neighbourobj.BOUNDARY_DISPUTE       = dr.GetString(dr.GetOrdinal("boundary_dispute"));
                if (ColumnExists(dr, "dispute_details") && !dr.IsDBNull(dr.GetOrdinal("dispute_details")))
                {
                    Neighbourobj.DISPUTE_DETAILS = dr.GetString(dr.GetOrdinal("dispute_details"));
                }
                NeighbourListobj.Add(Neighbourobj);
            }

            dr.Close();

            return(NeighbourListobj);
        }
Exemplo n.º 3
0
        //** cluster the peaks **
        public static List <int[]> CalcClusterIndices(int minCharge, int maxCharge, double correlationThreshold, int peakCount,
                                                      double[] centerMz, float[] centerMzErrors, float[] minTimes,
                                                      float[] maxTimes,
                                                      Peak[] peaks, IPeakList peakList)
        {
            NeighbourList neighbourList = new NeighbourList();

            //** iterate through all peaks **
            for (int j = 0; j < peakCount; j++)
            {
                //** current peak's mz and RT range **
                double massJ      = centerMz[j];
                float  massErrorJ = centerMzErrors[j];
                float  timeMinJ   = minTimes[j];
                float  timeMaxJ   = maxTimes[j];

                //** get index of nearest peak at or above current mass -1.1 **
                int start = ArrayUtil.CeilIndex(centerMz, massJ - 1.1);

                //** get index of nearest peak at or below current mass -1.2
                int w = ArrayUtil.FloorIndex(centerMz, massJ - 1.2);

                //** remove any peaks outside of massj - 1.2 **
                //** so there's a removal to the left of this peak outside 1.2 away... **
                //** what is this all about?? **

                for (int i = 0; i < w; i++)
                {
                    if (peaks != null && peaks[i] != null)
                    {
                        peaks[i].Dispose();
                        peaks[i] = null;
                    }
                }

                //** iterate from current peak at mass - 1.1 to current peak **
                //** iterates through left "adjacent" traces, neihbors with current trace (j) if valid **
                for (int i = start; i < j; i++)
                {
                    //** comparing peak mz and RT range **
                    double massI      = centerMz[i];
                    double massErrorI = centerMzErrors[i];
                    double timeMinI   = minTimes[i];
                    double timeMaxI   = maxTimes[i];

                    //** difference in mass and synthesized mass error
                    double massDiff  = Math.Abs(massI - massJ);
                    double massError = 5 * Math.Sqrt(massErrorI * massErrorI + massErrorJ * massErrorJ);

                    //** invalidating conditions: **

                    //** 1) mass difference is greater than minimum **
                    if (massDiff > MolUtil.C13C12Diff + massError)
                    {
                        continue;
                    }

                    //** 2) no RT overlap
                    if (timeMinI >= timeMaxJ)
                    {
                        continue;
                    }

                    //** 2) no RT overlap
                    if (timeMinJ >= timeMaxI)
                    {
                        continue;
                    }

                    //** 3) mass difference doesn't match any charge states **
                    if (!FitsMassDifference(massDiff, massError, minCharge, maxCharge))
                    {
                        continue;
                    }

                    //** 4) The intensity profile correlation (cosine similarity) fails the threshold **
                    if (CalcCorrelation(peakList.GetPeakKeep(i), peakList.GetPeakKeep(j)) < correlationThreshold)
                    {
                        continue;
                    }

                    //** create an edge between peak I and peak J if valid: **
                    //** 1) mass difference exceeds minimum
                    //** 2) RT has overlap
                    //** 3) mass difference fits a charge state
                    //** 4) intensity profiles have strong correlation
                    neighbourList.Add(i, j);
                }
            }

            //** convert edge list to clusters! **
            List <int[]> clusterList = new List <int[]>();

            //** iterate through all peaks **
            for (int i = 0; i < peakCount; i++)
            {
                //** if the peak has neighbors... **
                if (!neighbourList.IsEmptyAt(i))
                {
                    HashSet <int> currentCluster = new HashSet <int>();

                    AddNeighbors(i, currentCluster, neighbourList);
                    int[] c = SortByMass(currentCluster.ToArray(), centerMz);
                    clusterList.Add(c);
                }
            }
            return(clusterList);
        }