Exemplo n.º 1
0
/// <summary>
/// Get the list, returns array of AssayIDs
/// </summary>
/// <returns></returns>
///
        public IList GetUnpivotedAssayResultsDataSource()
        {
            StreamReader sr;
            bool         changed;
            int          i1;

            if (AssayId != null)
            {
                return(AssayId);
            }

// Read cache parameters

            changed = ServerFile.GetIfChanged(ServerCacheDir + "CacheParms.txt", ClientCacheDir + "CacheParms.txt");
            sr      = new StreamReader(ClientCacheDir + "CacheParms.txt");
            string txt = sr.ReadLine();

            ResultsRowCount = int.Parse(txt);
            sr.Close();

// Init Vo position tables

            TarFieldPositionMap = UnpivotedAssayResultFieldPositionMap.NewOriginalMap();             // used for fast indexing of value by col name
            QueryTable qt = Query.GetQueryTableByName(MultiDbAssayDataNames.CombinedNonSumTableName);

            if (qt != null)
            {
                TarFieldPositionMap.InitializeFromQueryTableVoPositions(qt, 0);
            }

// Read in list of assay Ids

            AssayId = ReadUShortArray("AssayId.bin");             // read in the list of assay ids for starters
            return(AssayId);
        }
Exemplo n.º 2
0
/// <summary>
/// Summarize unpivoted unsummarized assay data by target
/// </summary>
/// <param name="parms"></param>
/// <param name="qm2"></param>
/// <returns></returns>

        public QueryManager SummarizeByTargetUnpivoted(
            TargetSummaryOptions summaryOptions,
            QueryManager qm2)
        {
            // This method takes an unpivoted input query, summarizes it according to the summarization parameters
            // and then formats the summarized data according to the specified output format.
            // If a targetMap is specified then then coordinates are included in the output, the summarization
            // level must be target, and the output format must be unpivoted.

            QueryTable        qt, qt2;
            DataRowMx         dr, dr2;
            DataRowAttributes dra;
            string            cid = "", currentCid;
            int rti, rfi;

            AssayDict tad = TargetAssayDict;                                                // be sure target assay dict has been loaded

            TargetAssaySummarizationLevel sumLevel  = TargetAssaySummarizationLevel.Target; // target level
            SummarizationType             sumMethod = summaryOptions.UseMeans ? SummarizationType.BioResponseMean : SummarizationType.MostPotent;
            OutputDest outputDest = OutputDest.WinForms;
            TargetMap  targetMap  = TargetMapDao.GetMapWithCoords(summaryOptions.TargetMapName);

            qt = Query.GetQueryTableByName(MultiDbAssayDataNames.CombinedNonSumTableName);
            if (qt == null)
            {
                throw new Exception("Query table not found: " + MultiDbAssayDataNames.CombinedNonSumTableName);
            }

            UnpivotedAssayResultFieldPositionMap voMap = UnpivotedAssayResultFieldPositionMap.NewOriginalMap();             // used for fast indexing of value by col name

            voMap.InitializeFromQueryTableVoPositions(qt, 0);

            if (qm2 == null)             // need to create query manager?
            {
                qm2 = new QueryManager();
                qm2 = InitializeSubqueryQm(MultiDbAssayDataNames.CombinedNonSumTableName);
            }

            Query q2 = qm2.Query;

            qt2 = q2.GetQueryTableByNameWithException(MultiDbAssayDataNames.BaseTableName);

            UnpivotedAssayResultFieldPositionMap voMap2 = UnpivotedAssayResultFieldPositionMap.NewOriginalMap();             // used for fast indexing of value by col name

            voMap2.InitializeFromQueryTableVoPositions(qt2, 0);

// Summarize rows & store in DataSet

            qm2.DataTable.Clear();

            Dictionary <string, object> includedTargets = null;

            if (summaryOptions.TargetsWithActivesOnly)
            {             // scan data & make a list of targets to be included
                includedTargets = new Dictionary <string, object>();
                // ...
            }

            List <UnpivotedAssayResult> tars = new List <UnpivotedAssayResult>();           // build list of TA rows here

            currentCid = "";

            for (int dri = 0; dri <= DataTableMx.Rows.Count; dri++)
            {
                if (dri < DataTableMx.Rows.Count)
                {
                    dr  = DataTableMx.Rows[dri];
                    cid = dr[KeyValueVoPos] as string;
                    dra = GetRowAttributes(dr);
                    if (dra != null && dra.Filtered)
                    {
                        continue;
                    }
                    if (currentCid == "")
                    {
                        currentCid = cid;
                    }
                }
                else
                {
                    dr = null;
                }

                if (dr == null || cid != currentCid)
                {                       // summarize rows for current cid & add to new datatable
                    if (tars.Count > 0) //
                    {
                        List <UnpivotedAssayResult> sumTars = TargetAssayUtil.SummarizeData(
                            tars,
                            sumLevel,
                            sumMethod,
                            true,
                            NullValue.NullNumber,
                            NullValue.NullNumber,
                            targetMap);

                        int voLength2 = qm2.DataTable.Columns.Count;
                        foreach (UnpivotedAssayResult sumTar in sumTars)
                        {
                            object[] vo2 = sumTar.ToValueObject(voLength2, voMap2);
                            dr2 = qm2.DataTable.NewRow();
                            dr2.ItemArrayRef = vo2;                             // copy ref for efficiency since vo won't be changed
                            qm2.DataTable.Rows.Add(dr2);
                        }
                    }
                    if (dr == null)
                    {
                        break;
                    }
                    tars.Clear();
                    currentCid = cid;
                }

                UnpivotedAssayResult tar = UnpivotedAssayResult.FromValueObjectNew(dr.ItemArray, voMap);
                tars.Add(tar);                 // store in form for summarization
            }

            qm2.DataTableManager.InitializeRowAttributes();

            return(qm2);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Join an unpivoted target-summarized table to itself
        /// </summary>

        public QueryManager BuildTargetTargetData(
            QueryManager qm2)
        {
            QueryTable        qt, qt2;
            DataRowMx         dr, dr2;
            DataRowAttributes dra, dra2;
            string            cid = "", cid2 = "", currentCid, ttKey;
            int rti, rfi;

            qt = Query.GetQueryTableByNameWithException(MultiDbAssayDataNames.BaseTableName);                   // source table

            UnpivotedAssayResultFieldPositionMap voMap = UnpivotedAssayResultFieldPositionMap.NewOriginalMap(); // used for fast indexing of value by col name

            voMap.InitializeFromQueryTableVoPositions(qt, 0);

            if (qm2 == null || Math.Abs(1) == 1)             // need to create query manager? (needs fixup)
            {
                qm2 = new QueryManager();
                qm2 = InitializeSubqueryQm(MultiDbAssayDataNames.TargetTargetUnpivotedTableName);
            }

            Query q2 = qm2.Query;

            qt2 = q2.GetQueryTableByNameWithException(MultiDbAssayDataNames.TargetTargetUnpivotedTableName);

            // Join rows & store in DataSet

            qm2.DataTable.Clear();

            Dictionary <string, int>            ttDict = new Dictionary <string, int>(); // maps target pair to row
            Dictionary <string, List <string> > cidTargetDict = new Dictionary <string, List <string> >();

            for (int dri = 0; dri < DataTableMx.Rows.Count; dri++)
            {             // get list of targets for each cid
                dr  = DataTableMx.Rows[dri];
                cid = dr[KeyValueVoPos] as string;
                dra = GetRowAttributes(dr);
                if (dra != null && dra.Filtered)
                {
                    continue;
                }
                object[] vo = dr.ItemArrayRef;

                if (!cidTargetDict.ContainsKey(cid))
                {
                    cidTargetDict[cid] = new List <string>();
                }

                string target = AssayAttributes.GetStringVo(vo, voMap.TargetSymbol.Voi);
                cidTargetDict[cid].Add(target);
            }

            foreach (string cid0 in cidTargetDict.Keys)
            {             // sum count for pair of targets
                List <string> targets = cidTargetDict[cid0];
                for (int t1i = 0; t1i < targets.Count; t1i++)
                {
                    string t1 = targets[t1i];
                    for (int t2i = t1i; t2i < targets.Count; t2i++)
                    {
                        string t2 = targets[t2i];
                        if (Lex.Lt(t1, t2))
                        {
                            ttKey = t1 + '\t' + t2;
                        }
                        else
                        {
                            ttKey = t2 + '\t' + t1;
                        }

                        if (!ttDict.ContainsKey(ttKey))
                        {
                            ttDict[ttKey] = 0;
                        }
                        ttDict[ttKey]++;
                    }
                }
            }

            foreach (string ttkey0 in ttDict.Keys)
            {             // build data rows
                string[] t1t2     = ttkey0.Split('\t');
                string   t1       = t1t2[0];
                string   t2       = t1t2[1];
                int      cpdCount = ttDict[ttkey0];

                AddRow(qm2.DataTable, t1, t2, cpdCount);
                if (t2 != t1)
                {
                    AddRow(qm2.DataTable, t2, t1, cpdCount);
                }
            }

            qm2.DataTableManager.InitializeRowAttributes();

            return(qm2);
        }