コード例 #1
0
        /// <summary>
        /// Deserialize from a binary file
        /// </summary>

        public static AssayDict DeserializeFromFile(
            string fileName)
        {
            FileStream fs = null;

            try
            {
                int       t0  = TimeOfDay.Milliseconds();
                AssayDict tad = new AssayDict();

                if (File.Exists(fileName))
                {
                    fs = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                    BinaryFormatter bf = new BinaryFormatter();

                    List <AssayAttributes> taaList = bf.Deserialize(fs) as List <AssayAttributes>;
                    fs.Close();
                    fs = null;

                    foreach (AssayAttributes taa in taaList)
                    {
                        tad.SetMaps(taa);
                    }
                }
                t0 = TimeOfDay.Milliseconds() - t0;
                return(tad);
            }

            catch (Exception ex)
            {             // be sure file is closed
                if (fs != null)
                {
                    fs.Close();
                    fs = null;
                }

                throw new Exception(ex.Message, ex);
            }
        }
コード例 #2
0
        /// <summary>
        /// Convert a value objectarray into a TargetAssayAttributes
        /// </summary>
        /// <param name="vo"></param>
        /// <param name="voMap"></param>
        /// <returns></returns>

        public void FromValueObject(
            object[] vo,
            TargetAssayAttrsFieldPositionMap voMap)
        {
            string key;

            AssayAttributes row = this;

            row.Id = GetIntVo(vo, voMap.Id.Voi);

            row.GeneSymbol             = GetStringVo(vo, voMap.TargetSymbol.Voi);
            row.GeneId                 = GetIntVo(vo, voMap.TargetId.Voi);
            row.GeneDescription        = GetStringVo(vo, voMap.TargetDescription.Voi);
            row.GeneFamily             = GetStringVo(vo, voMap.GeneFamily.Voi);
            row.GeneFamilyTargetSymbol = GetStringVo(vo, voMap.GeneFamilyTargetSymbol.Voi);

            row.AssayType = GetStringVo(vo, voMap.AssayType.Voi);
            row.AssayMode = GetStringVo(vo, voMap.AssayMode.Voi);

            object obj = GetObjectVo(vo, voMap.AssayName.Voi);

            if (obj != null)
            {
                if (obj is string)
                {
                    row.AssayName = (string)obj;
                }
                else if (obj is StringMx)
                {
                    StringMx sx = obj as StringMx;
                    row.AssayName = sx.Value;

                    if (sx.DbLink.Contains(","))
                    {
                        string mtName = sx.DbLink.Replace(",", "_").ToUpper();
                        row.AssayMetaTableName = mtName;
                    }
                }
            }

            row.AssayDesc     = GetStringVo(vo, voMap.AssayDesc.Voi);
            row.AssayDatabase = GetStringVo(vo, voMap.AssayDatabase.Voi);
            row.AssaySource   = GetStringVo(vo, voMap.AssayLocation.Voi);
            row.AssayId2      = GetIntVo(vo, voMap.AssayId2.Voi);
            row.AssayIdNbr    = GetIntVo(vo, voMap.AssayIdNbr.Voi);
            row.AssayIdTxt    = GetStringVo(vo, voMap.AssayIdTxt.Voi);

            string txt = GetStringVo(vo, voMap.AssayMetaTableName.Voi);

            if (txt != null)
            {
                row.AssayMetaTableName = txt;
            }

            row.AssayStatus = GetStringVo(vo, voMap.AssayStatus.Voi);
            row.GeneCount   = GetIntVo(vo, voMap.AssayGeneCount.Voi);

            row.ResultName          = GetStringVo(vo, voMap.ResultName.Voi);
            row.ResultTypeId2       = GetIntVo(vo, voMap.ResultTypeId2.Voi);
            row.ResultTypeIdNbr     = GetIntVo(vo, voMap.ResultTypeIdNbr.Voi);
            row.ResultTypeIdTxt     = GetStringVo(vo, voMap.ResultTypeIdTxt.Voi);
            row.ResultTypeConcType  = GetStringVo(vo, voMap.ResultTypeConcType.Voi);
            row.ResultTypeUnits     = GetStringVo(vo, voMap.ResultTypeUnits.Voi);
            row.ResultTypeConcUnits = GetStringVo(vo, voMap.ResultTypeConcUnits.Voi);
            row.TopLevelResult      = GetStringVo(vo, voMap.TopLevelResult.Voi);

            row.Remapped         = GetStringVo(vo, voMap.Remapped.Voi);
            row.Multiplexed      = GetStringVo(vo, voMap.Multiplexed.Voi);
            row.Reviewed         = GetStringVo(vo, voMap.Reviewed.Voi);
            row.ProfilingAssay   = GetStringVo(vo, voMap.ProfilingAssay.Voi);
            row.CompoundsAssayed = GetIntVo(vo, voMap.CompoundsAssayed.Voi);

            row.ResultCount         = GetIntVo(vo, voMap.ResultCount.Voi);
            row.AssayUpdateDate     = GetDateVo(vo, voMap.AssayUpdateDate.Voi);
            row.AssociationSource   = GetStringVo(vo, voMap.AssociationSource.Voi);
            row.AssociationConflict = GetStringVo(vo, voMap.AssociationConflict.Voi);

            row.TargetMapX = GetDoubleVo(vo, voMap.TargetMapX.Voi);
            row.TargetMapY = GetDoubleVo(vo, voMap.TargetMapY.Voi);
            row.TargetMapZ = GetDoubleVo(vo, voMap.TargetMapZ.Voi);

            // Complete assignment any missing assay database and/or assay id information

            AssayDict tad = AssayDict.Instance;             // dict used for various lookups

            if (Lex.IsNullOrEmpty(row.AssayIdTxt) && row.AssayId2 == NullValue.NullNumber)
            {             // try to assign from assay name
                if (!Lex.IsNullOrEmpty(row.AssayName) && tad != null)
                {
                    key = row.AssayName.Trim().ToUpper();
                    if (tad.AssayNameMap.ContainsKey(key))
                    {
                        AssayAttributes taa = tad.AssayNameMap[key];
                        row.AssayDatabase = taa.AssayDatabase;
                        row.AssayId2      = taa.AssayId2;
                        row.AssayIdNbr    = taa.AssayIdNbr;
                        row.AssayIdTxt    = taa.AssayIdTxt;
                    }
                }
            }

            else if (Lex.IsNullOrEmpty(row.AssayIdTxt))
            {
                row.AssayIdTxt = row.AssayId2.ToString();
            }

            else if (row.AssayId2 == NullValue.NullNumber)
            {
                int.TryParse(row.AssayIdTxt, out row.AssayId2);
            }

            // Complete any missing target information if target dict is available

            if (tad != null)
            {
                if (Lex.IsNullOrEmpty(row.GeneSymbol) && row.GeneId == NullValue.NullNumber)                 // assign target from assay info
                {
                    if (!Lex.IsNullOrEmpty(row.AssayDatabase) && !Lex.IsNullOrEmpty(row.AssayIdTxt))
                    {
                        key = row.AssayDatabase.ToUpper() + "-" + row.AssayIdTxt.ToUpper();

                        if (tad.DatabaseAssayIdMap.ContainsKey(key))
                        {
                            row.GeneSymbol = tad.DatabaseAssayIdMap[key].GeneSymbol;
                            row.GeneId     = tad.DatabaseAssayIdMap[key].GeneId;
                        }
                    }
                }

                else if (Lex.IsNullOrEmpty(row.GeneSymbol))                 // assign symbol from targetid
                {
                    if (tad.TargetIdMap.ContainsKey(row.GeneId))
                    {
                        row.GeneSymbol = tad.TargetIdMap[row.GeneId].GeneSymbol;
                    }
                }

                else if (row.GeneId == NullValue.NullNumber)                 // assign targetId from symbol
                {
                    string geneSymbol = row.GeneSymbol.ToUpper();
                    if (tad.TargetSymbolMap.ContainsKey(geneSymbol))
                    {
                        //geneSymbol = "EPHB1"; // debug
                        //geneSymbol = "AKT3"; // debug
                        row.GeneId = tad.TargetSymbolMap[geneSymbol].GeneId;
                    }
                }
            }

            return;
        }