Exemplo n.º 1
0
        /// <summary>
        /// This initializes the view model and generates the appropriate view.
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public override bool Initialize(IBioDataLoader data)
        {
            _data = data as IBioDataLoader <IAlignedBioEntity>;
            Debug.Assert(_data != null);

            if (_data == null)
            {
                return(false);
            }

            IBioDataLoaderProperties bioProps = data as IBioDataLoaderProperties;

            if (bioProps != null)
            {
                bioProps.PropertiesChanged += OnLoaderPropertiesChanged;
            }

            var allData = _data.Entities;

            TotalColumns = allData != null && allData.Count > 0
                               ? allData.Max(seq => (seq.AlignedData != null) ? seq.AlignedData.Count : 0)
                               : 0;

            ReloadSequences();
            FocusedRow = VisibleData[0];

            if (SupportsGrouping && Options.OpenWithGrouping)
            {
                IsGrouped = true;
            }

            return(base.Initialize(data));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="loadData"></param>
 /// <param name="format"></param>
 /// <param name="loader"></param>
 /// <param name="key"></param>
 public BioDataFile(string loadData, BioFormatType format, IBioDataLoader loader, string key)
 {
     LoadData   = loadData;
     FormatType = format;
     Loader     = loader;
     LoaderKey  = key;
 }
Exemplo n.º 3
0
        /// <summary>
        /// This adds a workspace entry to our available data source list.
        /// </summary>
        /// <param name="entry"></param>
        private void AddFileToWorkspace(WorkspaceEntry entry)
        {
            // Find the specific data loader responsible for this entry.
            var owner = Extensions.Current.DataProviders.Where(ldr => ldr.Key == entry.LoaderKey).FirstOrDefault();

            if (owner != null)
            {
                IBioDataLoader loader = owner.Create(entry.LoaderData);
                if (loader != null)
                {
                    var dvm = new OpenBioDataViewModel(entry.LoaderData, entry.FormatType, loader, owner);
                    dvm.CloseRequest += OnDataSourceClosing;
                    AvailableDataSources.Add(dvm);
                }
            }
            else
            {
                var uiMessage = Resolve <IErrorVisualizer>();
                if (uiMessage != null)
                {
                    uiMessage.Show("Error loading workspace",
                                   "Could not resolve loader provider for " + entry.FormatType +
                                   ".  File will be ignored.");
                }
            }
        }
        public override bool Initialize(IBioDataLoader data)
        {
            var loader = data as IBioDataLoader <IStreamBioEntity>;

            if (loader != null && loader.Entities.Count == 1)
            {
                Filename = loader.Entities[0].Source;
                return(base.Initialize(data));
            }
            return(false);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Routine to open a file
        /// </summary>
        /// <param name="entry"></param>
        /// <param name="filename"></param>
        /// <returns></returns>
        private bool OpenFile(IBioDataProvider entry, string filename)
        {
            IBioDataLoader dataLoader = entry.Create(filename);

            if (dataLoader != null)
            {
                var dvm = new OpenBioDataViewModel(filename, entry.SupportedTypes, dataLoader, entry);
                dvm.Load();
                dvm.CloseRequest += OnDataSourceClosing;

                OpenDataSources.Add(dvm);
                return(true);
            }
            return(false);
        }
Exemplo n.º 6
0
        public override bool Initialize(IBioDataLoader data)
        {
            var sdloader = data as IBioDataLoader <IStructureModelBioEntity>;

            if (sdloader != null)
            {
                var basePairs = from bp in sdloader.Entities.OfType <IBasePairEntity>()
                                select bp;
                _sequence = basePairs.First(bp => bp.Sequence != null).Sequence;
                //ElementSpacing = (Width - (2 * _xPadding)) / _sequence.RawData.Count;
                Width = (2 * _xPadding) + ElementSpacing * _sequence.RawData.Count;

                for (int i = 0; i < _sequence.RawData.Count; i++)
                {
                    NestedElementViewModel nevm = new NestedElementViewModel(this, _sequence.RawData[i], i);
                    _nestedVMs.Add(nevm);
                }

                _maxBPDistance = basePairs.Max(e => e.ThreePrimeIndex - e.FivePrimeIndex - 1);
                _minBPDistance = basePairs.Min(e => e.ThreePrimeIndex - e.FivePrimeIndex - 1);

                var basepairVMs = from bp in basePairs
                                  join fpVM in _nestedVMs on bp.FivePrimeIndex equals fpVM.Index
                                  join tpVM in _nestedVMs on bp.ThreePrimeIndex equals tpVM.Index
                                  select new NestedBasePairViewModel(this, fpVM, tpVM);

                foreach (NestedBasePairViewModel bp in basepairVMs)
                {
                    ModelElements.Add(bp);
                }

                foreach (NestedElementViewModel elem in _nestedVMs)
                {
                    ModelElements.Add(elem);
                }

                var tickElems = from elem in _nestedVMs
                                where elem.Index == 1 || elem.Index % 10 == 0
                                select elem;
                foreach (NestedElementViewModel elem in tickElems)
                {
                    ModelElements.Add(new NestedElementTickViewModel(this, elem));
                }
            }
            return(base.Initialize(data));
        }
Exemplo n.º 7
0
        public override bool Initialize(IBioDataLoader data)
        {
            var sdloader = data as IBioDataLoader <IStructureModelBioEntity>;

            if (sdloader != null)
            {
                var basePairs = from bp in sdloader.Entities.OfType <IBasePairEntity>()
                                select bp;
                IBioEntity sequence = basePairs.First(bp => bp.Sequence != null).Sequence;

                _seqVM   = new CircleSequenceViewModel(sequence);
                PhyloDVM = new PhyloDCircleViewModel(_seqVM);
                LoadPhyloDDataCommand = new DelegatingCommand(_phyloDVM.OnLoadPhyloDData);
                Width  = _seqVM.Width;
                Height = _seqVM.Height;

                var basePairVM = from bp in basePairs
                                 select new CircleBasePairViewModel(_seqVM, bp);

                foreach (var vm in basePairVM)
                {
                    ModelElements.Add(vm);
                }
                ModelElements.Add(_seqVM);
                foreach (var vm in _seqVM.Elements)
                {
                    ModelElements.Add(vm);
                }
                foreach (var vm in _seqVM.TickMarks)
                {
                    ModelElements.Add(vm);
                }
                foreach (var vm in _seqVM.TickLabels)
                {
                    ModelElements.Add(vm);
                }
            }
            return(base.Initialize(data));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Constructor for the bio file
        /// </summary>
        /// <param name="loadData"></param>
        /// <param name="format"></param>
        /// <param name="loader"></param>
        /// <param name="info"></param>
        public OpenBioDataViewModel(string loadData, BioFormatType format, IBioDataLoader loader, IBioDataProvider info)
        {
            if (format == BioFormatType.Unknown)
            {
                throw new ArgumentException("BioFormatType cannot be unknown.");
            }
            if (loader == null)
            {
                throw new ArgumentNullException("loader");
            }

            RegisterWithMessageMediator();

            DefaultCommand          = new DelegatingCommand(OnOpenDefaultView, () => !IsLoading);
            CloseCommand            = new DelegatingCommand(OnClose, () => IsLoaded || !IsLoading);
            ChangePropertiesCommand = new DelegatingCommand(OnChangeProperties, () => IsLoaded);
            Children = new MTObservableCollection <OpenBioViewModel>();

            _bioData = new BioDataFile(loadData, format, loader, info.Key);

            Header = string.Format("{0} [{1}]", loader.InitializationData, info.Description);
            Image  = info.ImageUrl;
        }
Exemplo n.º 9
0
 /// <summary>
 /// This method is used to initialize the view
 /// </summary>
 /// <param name="data">BioData loader interface</param>
 /// <returns>True = success, false = failed</returns>
 public abstract bool Initialize(IBioDataLoader data);
Exemplo n.º 10
0
        public override bool Initialize(IBioDataLoader data)
        {
            Dictionary <int, SSBasePairViewModel> basePairVMs = new Dictionary <int, SSBasePairViewModel>();

            var sdloader = data as IBioDataLoader <IStructureModelBioEntity>;

            if (sdloader != null)
            {
                var basePairs = from bp in sdloader.Entities.OfType <XRNABasePair>()
                                select bp;

                foreach (XRNABasePair bp in basePairs)
                {
                    SSBasePairViewModel bpvm = BuildBasePairViewModel(bp);
                    ModelElements.Add(bpvm);
                    ModelElements.Add(bpvm.FivePrimeNucleotide);
                    ModelElements.Add(bpvm.ThreePrimeNucleotide);
                    basePairVMs.Add(bpvm.FivePrimeNucleotide.Index, bpvm);
                }

                var unpairedNt = from nt in sdloader.Entities.OfType <XRNANucleotide>()
                                 select nt;
                foreach (XRNANucleotide nt in unpairedNt)
                {
                    SSSymbolViewModel svm = BuildSymbolViewModel(nt);
                    ModelElements.Add(svm);
                }

                var allEntities = from entity in sdloader.Entities
                                  select entity;

                foreach (IStructureModelBioEntity entity in allEntities)
                {
                    if (entity is XRNABasePairConnector)
                    {
                        XRNABasePairConnector lc = (XRNABasePairConnector)entity;
                        ModelElements.Add(new SSBasePairLineConnectorViewModel(basePairVMs[lc.BasePair.FivePrimeIndex + 1])
                        {
                            Color     = lc.Color,
                            Thickness = lc.Thickness,
                            Visible   = lc.Visible
                        });
                    }
                    else if (entity is XRNABasePairConnectorCircle)
                    {
                        XRNABasePairConnectorCircle cc = (XRNABasePairConnectorCircle)entity;
                        ModelElements.Add(new SSBasePairCircleConnectorViewModel(basePairVMs[cc.BasePair.FivePrimeIndex + 1])
                        {
                            Color     = cc.Color,
                            Radius    = cc.Radius,
                            Filled    = cc.Filled,
                            Thickness = cc.Thickness
                        });
                    }
                    else if (entity is TextLabel)
                    {
                        TextLabel lc = (TextLabel)entity;
                        ModelElements.Add(new SSTextLabelViewModel(lc.Start.X, lc.Start.Y, lc.Text, new FontFamily(lc.FontFace), (FontStyle)_fscvtr.ConvertFrom(lc.FontStyle),
                                                                   (FontWeight)_fwcvtr.ConvertFrom(lc.FontWeight), lc.FontSize, (Brush)_colorCvtr.ConvertFrom(lc.Color)));
                    }
                    else if (entity is LineLabel)
                    {
                        LineLabel ll = (LineLabel)entity;
                        ModelElements.Add(new SSLineLabelViewModel()
                        {
                            X         = ll.Start.X,
                            Y         = ll.Start.Y,
                            X1        = ll.End.X - ll.Start.X,
                            Y1        = ll.End.Y - ll.Start.Y,
                            Color     = (Brush)_colorCvtr.ConvertFrom(ll.Color),
                            Thickness = ll.LineWeight
                        });
                    }
                    else if (entity is ParallelogramLabel)
                    {
                        ParallelogramLabel            lc = (ParallelogramLabel)entity;
                        SSParallelogramLabelViewModel vm = new SSParallelogramLabelViewModel()
                        {
                            CenterX            = lc.Center.X,
                            CenterY            = lc.Center.Y,
                            Side1Length        = lc.Side1Length,
                            RotationAngle      = lc.Side1Angle,
                            Side2Length        = lc.Side2Length,
                            ParallelogramAngle = lc.Side2Angle,
                            Color      = (Brush)_colorCvtr.ConvertFrom(lc.Color),
                            LineWeight = lc.LineWeight
                        };
                        vm.ComputeParallelogram();
                        ModelElements.Add(vm);
                    }
                    else if (entity is ArcLabel)
                    {
                        ArcLabel            ac = (ArcLabel)entity;
                        SSArcLabelViewModel vm = new SSArcLabelViewModel()
                        {
                            CenterX    = ac.Center.X,
                            CenterY    = ac.Center.Y,
                            Color      = (Brush)_colorCvtr.ConvertFrom(ac.Color),
                            LineWeight = ac.LineWeight,
                            Radius     = ac.Radius,
                            Angle1     = ac.Angle1,
                            Angle2     = ac.Angle2,
                        };
                        vm.ComputeArc();
                        ModelElements.Add(vm);
                    }
                    else if (entity is ArrowLabel)
                    {
                        ArrowLabel            al = (ArrowLabel)entity;
                        SSArrowLabelViewModel vm = new SSArrowLabelViewModel()
                        {
                            ArrowTipX     = al.ArrowTip.X,
                            ArrowTipY     = al.ArrowTip.Y,
                            LeftTipX      = al.LeftTip.X,
                            LeftTipY      = al.LeftTip.Y,
                            Color         = (Brush)_colorCvtr.ConvertFrom(al.Color),
                            LineWeight    = al.LineWeight,
                            TailLength    = al.TailLength,
                            RotationAngle = al.Angle
                        };
                        vm.ComputeArrow();
                        ModelElements.Add(vm);
                    }
                }

                MeasureAndArrangeCanvas();

                return(base.Initialize(data));
            }
            return(false);
        }