private void DrawPdfCoverageMap(ProteinForTreeView protein, Grid mapGrid, string path)
        {
            // draw coverage map
            mapGrid.Width = 1000;
            DrawSequenceCoverageMap(protein);

            string pathToCoverageMap = Path.Combine(Path.GetDirectoryName(path), "map.png");

            CustomPdfWriter.RenderImage((int)mapGrid.Width, (int)mapGrid.Height, pathToCoverageMap, map);

            // draw legend
            SequenceCoverageMap.drawLegend(legend, proteaseByColor, proteases, legendGrid);
            string pathToLegend = Path.Combine(Path.GetDirectoryName(path), "legend.png");

            CustomPdfWriter.RenderImage((int)(legend.Width), 50, pathToLegend, legend);

            CustomPdfWriter.WriteToPdfMetaDraw(mapGrid.Width, mapGrid.Height, pathToCoverageMap, pathToLegend, path);
        }
        private void DrawSequenceCoverageMap(ProteinForTreeView protein) //string accession, Dictionary<string, PeptideForTreeView> uniquePeptides, Dictionary<string, PeptideForTreeView> sharedPeptides)
        {
            string protease    = "trypsin";                              // only works for single protease for now
            string seqCoverage = proteinGroups[protein.Accession];

            mapViewer.Visibility = Visibility.Visible;

            BaseDraw.clearCanvas(map);
            mainViewModel.Model = null; // clear plot
            BaseDraw.clearCanvas(canvas);

            double spacing     = 22;
            int    height      = 10;
            int    totalHeight = 0;
            int    accumIndex  = 0;

            foreach (string seq in seqCoverage.Split('|'))
            {
                var splitSeq = Split(seq, spacing);

                var allPeptides = new List <string>(protein.AllPeptides.Keys);
                foreach (var line in splitSeq)
                {
                    List <int> indices = new List <int>();

                    // draw sequence
                    for (int r = 0; r < line.Length; r++)
                    {
                        SequenceCoverageMap.txtDrawing(map, new Point(r * spacing + 10, height), line[r].ToString().ToUpper(), Brushes.Black);
                    }

                    // highlight partial peptide sequences (broken off into multiple lines)
                    if (partialPeptideMatches.Count > 0)
                    {
                        var temp = new Dictionary <string, int>(partialPeptideMatches);
                        partialPeptideMatches.Clear();

                        foreach (var peptide in temp)
                        {
                            if (MatchPeptideSequence(peptide.Key, line, 0, peptide.Value, accumIndex - peptide.Value == seq.IndexOf(peptide.Key)))
                            {
                                int start = 0;
                                int end   = Math.Min(start + peptide.Key.Length - peptide.Value - 1, line.Length - 1);
                                SequenceCoverageMap.Highlight(start, end, map, indices, height, proteaseByColor[protease], protein.UniquePeptides.Keys.Any(u => u.Contains(peptide.Key))); // draw line for peptide sequence
                            }
                        }
                    }

                    // highlight full peptide sequences
                    for (int i = 0; i < line.Length; ++i)
                    {
                        var temp = new List <string>(allPeptides);
                        foreach (string peptide in temp)
                        {
                            if (MatchPeptideSequence(peptide, line, i, 0, accumIndex + i == seq.IndexOf(peptide)))
                            {
                                int start = i;
                                int end   = Math.Min(start + peptide.Length - 1, line.Length - 1);
                                SequenceCoverageMap.Highlight(start, end, map, indices, height, proteaseByColor[protease], protein.UniquePeptides.Keys.Any(u => u.Contains(peptide)));
                                allPeptides.Remove(peptide);
                            }
                        }
                    }

                    height     += 50;
                    accumIndex += line.Length;
                }

                totalHeight += splitSeq.Count() * 50;
                height      += 50;
            }

            mapGrid.Height = totalHeight + 50 * seqCoverage.Split('|').Count();
            SequenceCoverageMap.drawLegend(legend, proteaseByColor, proteases, legendGrid);
        }