Exemple #1
0
        //[Authorize(Roles = "ReadGenome")]
        public JsonResult PartialIndex(Guid?id, int page, int pageSize)
        {
            JsonResult jr = new JsonResult();

            pageSize = pageSize == 100 ? 101 : pageSize;
            using (GeneXContext context = new GeneXContext())
            {
                IQueryable <SNPDTO> query = context.SNP
                                            .Where(m => m.GenomeId == id.Value)
                                            .Join(context.SNPedia,
                                                  c => c.ClusterId,
                                                  d => d.ClusterId,
                                                  (c, d) => new SNPDTO()
                {
                    ClusterId      = c.ClusterId,
                    ChromosomeType = c.ChromosomeType,
                    Chromosome     = c.Chromosome,
                    Allele1        = c.Allele1,
                    Allele2        = c.Allele2,
                    SNPId          = c.SNPId,
                    Position       = c.Position,
                    Notes          = d.Notes
                }).Where(m => !(m.Notes == null || m.Notes.Trim() == string.Empty))
                                            .OrderBy(m => m.Chromosome)
                                            .ThenBy(m => m.Position)
                                            .Skip(page * pageSize)
                                            .Take(pageSize);


                jr.Data = query.ToList();
            }
            jr.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return(jr);
        }
Exemple #2
0
        public ActionResult Index(Guid?id)
        {
            GenomeViewModel gvm = new GenomeViewModel();

            if (id != null)
            {
                using (GeneXContext context = new GeneXContext())
                {
                    Genome g = context.Genome.Where(m => m.GenomeId == id.Value).FirstOrDefault();
                    if (g != null)
                    {
                        gvm.Id   = g.GenomeId;
                        gvm.Name = g.Name;
                    }
                }

                FileInfo fi = new FileInfo(Path.Combine(ServerMapPath, id.ToString() + ".txt"));
                if (fi.Exists)
                {
                    gvm.DataFileExists = true;
                    gvm.DateTime       = fi.LastWriteTime;
                }
            }

            return(View(gvm));
        }
Exemple #3
0
        public ActionResult Index()
        {
            IndexViewModel ivm = new IndexViewModel();

            using (GeneXContext cs = new GeneXContext())
            {
                var claim = ((System.Security.Claims.ClaimsPrincipal) this.User).Claims.Where(m => m.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier").FirstOrDefault();
                if (claim != null)
                {
                    string        id        = claim.Value;
                    List <Guid>   genomeIds = (from gp in cs.GenomePermission where gp.UserId == new Guid(id) && gp.PermissionId == Model.Constants.Permissions.Ids.Owner select gp.GenomeId).ToList();
                    List <Genome> results   = (from g in cs.Genome where genomeIds.Contains(g.GenomeId) select g).ToList();
                    foreach (Genome g in results)
                    {
                        ivm.Genomes.Add(g.GenomeId, g.Name);
                    }
                }
            }
            return(View(ivm));
        }
Exemple #4
0
        public ActionResult Add(string Name)
        {
            using (GeneXContext context = new GeneXContext())
            {
                Genome g = new Genome();
                g.GenomeId = Guid.NewGuid();
                g.Name     = Name;
                context.Genome.Add(g);
                context.SaveChanges();

                GenomePermission gp = new GenomePermission();
                gp.GenomeId           = g.GenomeId;
                gp.GenomePermissionId = Guid.NewGuid();
                gp.OrganizationId     = User.Identity.GetUserGroupId();
                gp.UserId             = User.Identity.GetUserGuid();
                gp.PermissionId       = Constants.Permissions.Ids.Owner;
                context.GenomePermission.Add(gp);
                context.SaveChanges();
            }
            return(RedirectToAction("Index", "Home"));
        }
Exemple #5
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            //GlobalFilters.Filters.Add(new System.Web.Mvc.AuthorizeAttribute());

            AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier;
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <GeneXContext, GeneX.Model.Migrations.Configuration>());
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <Db, GeneX.Security.Migrations.Configuration>());

            GeneXContext context = new GeneXContext();

            context.Database.Initialize(false);
            context.Database.CreateIfNotExists();
            Db securityContext = new Db();

            securityContext.Database.Initialize(false);
            securityContext.Database.CreateIfNotExists();
        }
Exemple #6
0
        // TODO: Fix the Calls to include Either FormValues Dictionary or DTO.
        public ActionResult Index(Guid?id, HttpPostedFileBase file)
        {
            if (file == null || file.ContentLength == 0 || file.ContentType == null || string.IsNullOrEmpty(file.FileName) || file.InputStream == null)
            {
                this.ModelState.AddModelError("PostedFile", "Must attach file.");
                return(View());
            }

            if (file.ContentLength > 0)
            {
                string path     = Path.Combine(ServerMapPath, id.ToString() + ".txt");
                string fileName = Path.GetFileName(file.FileName);
                if (fileName.EndsWith(".zip"))
                {
                    string tempPath    = Path.Combine(ServerMapPath, id.ToString() + ".zip");
                    string extractPath = Path.Combine(ServerMapPath, id.ToString());
                    file.SaveAs(tempPath);
                    System.IO.Compression.ZipFile.ExtractToDirectory(tempPath, extractPath);
                    string[] names = Directory.GetFiles(extractPath);
                    if (names.Length != 1)
                    {
                        throw new FileLoadException("Zip file must only contain one file.");
                    }
                    System.IO.File.Move(names[0], path);
                }
                List <SNP> snps = new List <SNP>();
                int        i    = 0;
                using (StreamReader sr = new StreamReader(path))
                {
                    GeneXContext context = new GeneXContext();

                    while (sr.Peek() >= 0)
                    {
                        string line = sr.ReadLine();
                        if (line.StartsWith("#", true, CultureInfo.InvariantCulture))
                        {
                            continue;
                        }
                        string[] parsed = line.Split("\t".ToCharArray());

                        string tmp = parsed[0];
                        SNP    snp = context.SNP.Where(m => m.ClusterId == tmp && m.GenomeId == id.Value).FirstOrDefault();

                        int    chromosome = 0;
                        string chromosomeType;
                        if (parsed[1].ToUpper().Equals("X") || parsed[1].ToUpper().Equals("Y"))
                        {
                            chromosome     = 23;
                            chromosomeType = parsed[1].ToUpper();
                        }
                        else if (parsed[1].ToUpper().Equals("MT"))
                        {
                            chromosome     = 0;
                            chromosomeType = "MT";
                        }
                        else
                        {
                            chromosome     = int.Parse(parsed[1]);
                            chromosomeType = "A";
                        }

                        char?allele1 = null;
                        char?allele2 = null;
                        if (parsed[3].Length > 0)
                        {
                            allele1 = parsed[3][0];
                        }
                        if (parsed[3].Length > 1)
                        {
                            allele2 = parsed[3][0];
                        }
                        if (snp == null)
                        {
                            context.SNP.Add(new SNP {
                                SNPId = Guid.NewGuid(), GenomeId = id.Value, ClusterId = parsed[0], Chromosome = chromosome, ChromosomeType = chromosomeType, Position = int.Parse(parsed[2]), Genotype = parsed[3], Allele1 = allele1.ToString(), Allele2 = allele2.ToString()
                            });
                        }
                        else
                        {
                            snp.ChromosomeType = chromosomeType;
                            snp.Genotype       = parsed[3];
                        }

                        ++i;
                        if (i % 1000 == 0)
                        {
                            context.SaveChanges();
                            context.Dispose();
                            context = new GeneXContext();
                        }
                    }
                    context.SaveChanges();
                    context.Dispose();
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult Index(Guid?id, HttpPostedFileBase file)
        {
            if (file == null || file.ContentLength == 0 || file.ContentType == null || string.IsNullOrEmpty(file.FileName) || file.InputStream == null)
            {
                this.ModelState.AddModelError("PostedFile", "Must attach file.");
                return(View());
            }

            if (file.ContentLength > 0)
            {
                string fileName = Path.GetFileName(file.FileName);
                string path     = Path.Combine(ServerMapPath, id.ToString() + ".txt");
                file.SaveAs(path);

                List <SNPedia> snps = new List <SNPedia>();
                int            i    = 0;
                using (StreamReader sr = new StreamReader(path))
                {
                    GeneXContext context = new GeneXContext();

                    while (sr.Peek() >= 0)
                    {
                        string line = sr.ReadLine();
                        if (line.StartsWith("#", true, CultureInfo.InvariantCulture) || string.IsNullOrWhiteSpace(line))
                        {
                            continue;
                        }
                        string[] parsed = line.Split("\t".ToCharArray());

                        string chrome     = parsed[0];
                        string reference  = parsed[1];
                        string chiptype   = parsed[2];
                        int    pos        = int.Parse(parsed[3]);
                        string toParse    = parsed[8];
                        int    chromosome = -1;
                        string chromosomeType;


                        string notes    = toParse.Substring(toParse.IndexOf("Note=") + 5).Replace("\"", string.Empty);
                        int    cidStart = toParse.IndexOf("ID=") + 6;
                        int    cidEnd   = toParse.IndexOf(";", cidStart);
                        string cid      = toParse.Substring(cidStart, cidEnd - cidStart);

                        if (chrome.Contains("MT"))
                        {
                            chromosomeType = "MT";
                            chromosome     = 0;
                        }
                        else if (chrome.Contains("X"))
                        {
                            chromosomeType = "X";
                            chromosome     = 23;
                        }
                        else if (chrome.Contains("Y"))
                        {
                            chromosomeType = "Y";
                            chromosome     = 23;
                        }
                        else
                        {
                            chromosomeType = "A";

                            if (!int.TryParse(chrome.Substring(3), out chromosome))
                            {
                                // Not Human
                                continue;
                            }
                        }

                        SNPedia snpedia = context.SNPedia.Where(m => m.Position == pos && m.Chromosome == chromosome && m.ChromosomeType == chromosomeType).FirstOrDefault();
                        if (snpedia == null)
                        {
                            context.SNPedia.Add(new SNPedia {
                                SNPediaId = Guid.NewGuid(), ClusterId = cid, Chromosome = chromosome, ChromosomeType = chromosomeType, Position = pos, ChipType = chiptype, Source = reference, Notes = notes
                            });
                        }
                        ++i;
                        if (i % 1000 == 0)
                        {
                            context.SaveChanges();
                            context.Dispose();
                            context = new GeneXContext();
                        }
                    }
                    context.SaveChanges();
                    context.Dispose();
                }
            }

            return(RedirectToAction("Index", "Home"));
        }