コード例 #1
0
ファイル: FileService.cs プロジェクト: nosredek/ZavrsniRad
        public IEnumerable <Tooltip> GetTooltips(string referenceName, int zoomLevel)
        {
            var refer    = _service._references.First(r => r.Name == referenceName);
            var tooltips = new List <Tooltip>();

            var startY = 7;
            var list   = new List <long> {
                0
            };

            string line;

            using var reader = new StreamReader($"{_service._references.IndexOf(refer)}.tmp");
            while ((line = reader.ReadLine()) != null)
            {
                var splitLine = line.Split('\t');

                var read = new SamFile
                {
                    QueryName       = splitLine[0],
                    ReferenceName   = splitLine[1],
                    StartingPos     = int.Parse(splitLine[2]),
                    DrawExpressions = DataService.GetDrawExpressions(splitLine[3]),
                    Reverse         = bool.Parse(splitLine[4])
                };
                var realStartingX = zoomLevel * read.StartingPos;

                var index      = list.FindIndex(i => realStartingX > i + 1);
                var y          = startY * (index != -1 ? index : list.Count);
                var lineLength = read.DrawExpressions.Sum(de => de.Length) * zoomLevel;

                if (index == -1)
                {
                    list.Add(realStartingX + lineLength);
                }
                else
                {
                    list[index] = realStartingX + lineLength;
                }

                tooltips.Add(new Tooltip
                {
                    Height = 7,
                    Width  = lineLength,
                    X      = realStartingX,
                    Y      = y,
                    Text   = read.QueryName
                });
            }
            return(tooltips);
        }
コード例 #2
0
ファイル: DataService.cs プロジェクト: nosredek/ZavrsniRad
        public void CalculateHist(string referenceName)
        {
            var reference = _references.First(r => r.Name == referenceName);

            var list = new List <int> {
                0
            };

            _histograms[reference.Name] = Enumerable.Repeat(0, reference.Length).ToList();
            using var reader            = new StreamReader($"{_references.IndexOf(reference)}.tmp");
            string line;

            while ((line = reader.ReadLine()) != null)
            {
                var splitLine = line.Split('\t');

                var read = new SamFile
                {
                    QueryName       = splitLine[0],
                    ReferenceName   = splitLine[1],
                    StartingPos     = int.Parse(splitLine[2]),
                    DrawExpressions = GetDrawExpressions(splitLine[3]),
                    Reverse         = bool.Parse(splitLine[4])
                };
                var realStartingX = read.StartingPos;
                var index         = list.FindIndex(i => realStartingX > i + 1);
                var lineLength    = read.DrawExpressions.Sum(de => de.Length);

                if (index == -1)
                {
                    list.Add(realStartingX + lineLength);
                }
                else
                {
                    list[index] = realStartingX + lineLength;
                }

                var currentX = realStartingX;
                foreach (var draw in read.DrawExpressions)
                {
                    if (draw.Type == DrawType.Rectangle)
                    {
                        for (int i = currentX; i < currentX + draw.Length; i++)
                        {
                            _histograms[reference.Name][i]++;
                        }
                    }
                    currentX += draw.Length;
                }
            }
        }
コード例 #3
0
        public void MakeFile(SamFile file)
        {
            var builder = new StringBuilder();

            builder.AppendLine("\"use strict\";");
            builder.AppendLine();
            builder.AppendLine($"class {file.Name}");
            builder.AppendLine("{");
            bool HasContent = false;

            if (file.Fields != null)
            {
                foreach (var item in file.Fields)
                {
                    if (HasContent)
                    {
                        builder.AppendLine();
                    }
                    MakeField(item, builder);
                    HasContent = true;
                }
            }
            if (HasContent)
            {
                builder.AppendLine();
            }
            if (file.Methods != null)
            {
                var first = file.Methods.FirstOrDefault();

                foreach (var item in file.Methods)
                {
                    if (HasContent)
                    {
                        builder.AppendLine();
                    }
                    MakeMethod(item, builder);
                    HasContent = true;
                }
            }

            builder.AppendLine("}");

            _compiler.ToOutput(file, builder, ".js");
        }
コード例 #4
0
ファイル: FileService.cs プロジェクト: nosredek/ZavrsniRad
        public byte[] GetImage(string referenceName, int zoomLevel, int chunk)
        {
            var refer  = _service._references.First(r => r.Name == referenceName);
            var height = (_service._histograms[refer.Name].Max() + 1) * 15;

            using var surface     = SKSurface.Create(new SKImageInfo(WIDTH, height));
            using SKCanvas canvas = surface.Canvas;
            canvas.Clear();

            using SKPaint paint = new SKPaint
                  {
                      Style       = SKPaintStyle.Stroke,
                      Color       = SKColors.Black,
                      StrokeWidth = 1
                  };

            using SKPaint fillPaint = new SKPaint
                  {
                      Style       = SKPaintStyle.Fill,
                      Color       = SKColors.Blue,
                      StrokeWidth = 1
                  };

            using SKPaint reverseFillPaint = new SKPaint
                  {
                      Style       = SKPaintStyle.Fill,
                      Color       = SKColors.Red,
                      StrokeWidth = 1
                  };

            var startY = 7;
            var list   = new List <long> {
                0
            };

            using var reader = new StreamReader($"{_service._references.IndexOf(refer)}.tmp");
            string line;

            while ((line = reader.ReadLine()) != null)
            {
                var splitLine = line.Split('\t');

                var read = new SamFile
                {
                    QueryName       = splitLine[0],
                    ReferenceName   = splitLine[1],
                    StartingPos     = int.Parse(splitLine[2]),
                    DrawExpressions = DataService.GetDrawExpressions(splitLine[3]),
                    Reverse         = bool.Parse(splitLine[4])
                };

                var realStartingX = zoomLevel * read.StartingPos;

                if (realStartingX >= (chunk + 1) * WIDTH)
                {
                    break;
                }

                var index      = list.FindIndex(i => realStartingX > i + 1);
                var y          = startY * (index != -1 ? index : list.Count);
                var lineLength = read.DrawExpressions.Sum(de => de.Length) * zoomLevel;

                if (index == -1)
                {
                    list.Add(realStartingX + lineLength);
                }
                else
                {
                    list[index] = realStartingX + lineLength;
                }

                realStartingX -= chunk * WIDTH;

                if (realStartingX < 0 && realStartingX + lineLength < 0)
                {
                    continue;
                }

                canvas.DrawLine(new SKPoint(realStartingX, y + 3), new SKPoint(realStartingX + lineLength, y + 3), paint);

                var currentX = realStartingX;
                foreach (var draw in read.DrawExpressions)
                {
                    if (draw.Type == DrawType.Rectangle)
                    {
                        canvas.DrawRect(currentX, y, draw.Length * zoomLevel, 5, read.Reverse ? reverseFillPaint : fillPaint);
                        canvas.DrawRect(currentX, y, draw.Length * zoomLevel, 5, paint);
                    }
                    currentX += draw.Length * zoomLevel;
                }

                canvas.Flush();
            }

            var      width      = (chunk + 1) * WIDTH * zoomLevel > refer.Length * zoomLevel ? refer.Length * zoomLevel % WIDTH : WIDTH;
            var      realHeight = 7 * (list.Count + 1);
            SKPixmap pixmap     = surface.Snapshot().Subset(SKRectI.Create(0, 0, width, realHeight)).PeekPixels();

            SKData data;

            if (realHeight > 15000)
            {
                data = pixmap.Encode(SKPngEncoderOptions.Default);
            }
            else
            {
                var options = new SKWebpEncoderOptions(SKWebpEncoderCompression.Lossless, 100);
                data = pixmap.Encode(options);
            }

            return(data.ToArray());
        }