private void PDFButton_Click(object sender, RoutedEventArgs e) { PsmFromTsv tempPsm = null; if (dataGridScanNums.SelectedCells.Count == 0) { MessageBox.Show("Please select at least one scan to export"); } else { int numberOfScansToExport = dataGridScanNums.SelectedItems.Count; foreach (object selectedItem in dataGridScanNums.SelectedItems) { PsmFromTsv psm = (PsmFromTsv)selectedItem; if (tempPsm == null) { tempPsm = psm; } MsDataScan msDataScanToDraw = MsDataFile.GetOneBasedScan(psm.Ms2ScanNumber); string myString = illegalInFileName.Replace(psm.FullSequence, ""); if (myString.Length > 30) { myString = myString.Substring(0, 30); } string filePath = Path.Combine(Path.GetDirectoryName(tsvResultsFilePath), "MetaDrawExport", psm.Ms2ScanNumber + "_" + myString + ".pdf"); string dir = Path.GetDirectoryName(filePath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } DrawPdfAnnotatedBaseSequence(psm, canvas, filePath); // captures the annotation for the pdf mainViewModel.DrawPeptideSpectralMatchPdf(msDataScanToDraw, psm, filePath, numberOfScansToExport > 1); } dataGridScanNums.SelectedItem = dataGridScanNums.SelectedItem; DrawPsm(tempPsm.Ms2ScanNumber, tempPsm.FullSequence); MessageBox.Show(string.Format("{0} PDFs exported", numberOfScansToExport)); } }
private void PDFButton_Click(object sender, RoutedEventArgs e) { PsmFromTsv tempPsm = null; if (dataGridScanNums.SelectedCells.Count == 0) { MessageBox.Show("Please select at least one scan to export"); } else { int numberOfScansToExport = dataGridScanNums.SelectedItems.Count; foreach (object selectedItem in dataGridScanNums.SelectedItems) { PsmFromTsv psm = (PsmFromTsv)selectedItem; if (tempPsm == null) { tempPsm = psm; } MsDataScan msDataScanToDraw = MsDataFile.GetOneBasedScan(psm.Ms2ScanNumber); string myString = illegalInFileName.Replace(psm.FullSequence, ""); if (myString.Length > 30) { myString = myString.Substring(0, 30); } string filePath = Path.Combine(Path.GetDirectoryName(tsvResultsFilePath), "MetaDrawExport", psm.Ms2ScanNumber + "_" + myString + ".pdf"); string dir = Path.GetDirectoryName(filePath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } DrawPdfAnnotatedBaseSequence(psm, canvas, filePath); // captures the annotation for the pdf mainViewModel.DrawPeptideSpectralMatchPdf(msDataScanToDraw, psm, filePath, numberOfScansToExport > 1); // if this spectrum has child scans, draw them in the "advanced" tab if ((psm.ChildScanMatchedIons != null && psm.ChildScanMatchedIons.Count > 0) || (psm.BetaPeptideChildScanMatchedIons != null && psm.BetaPeptideChildScanMatchedIons.Count > 0)) { // draw child scans HashSet <int> scansDrawn = new HashSet <int>(); var allChildScanMatchedIons = psm.ChildScanMatchedIons; if (psm.BetaPeptideChildScanMatchedIons != null) { allChildScanMatchedIons = allChildScanMatchedIons.Concat(psm.BetaPeptideChildScanMatchedIons).ToDictionary(p => p.Key, q => q.Value); } foreach (var childScanMatchedIons in allChildScanMatchedIons) { int scanNumber = childScanMatchedIons.Key; if (scansDrawn.Contains(scanNumber)) { continue; } scansDrawn.Add(scanNumber); List <MatchedFragmentIon> matchedIons = childScanMatchedIons.Value; var childPsmModel = new PsmAnnotationViewModel(); MsDataScan childScan = MsDataFile.GetOneBasedScan(scanNumber); childPsmModel.DrawPeptideSpectralMatch(childScan, psm, metaDrawGraphicalSettings.ShowMzValues, metaDrawGraphicalSettings.ShowAnnotationCharges, metaDrawGraphicalSettings.AnnotatedFontSize, metaDrawGraphicalSettings.BoldText); string childfilePath = Path.Combine(Path.GetDirectoryName(tsvResultsFilePath), "MetaDrawExport", childScan.OneBasedScanNumber + "_" + myString + ".pdf"); DrawPdfAnnotatedBaseSequence(psm, canvas, childfilePath); // captures the annotation for the pdf childPsmModel.DrawPeptideSpectralMatchPdf(childScan, psm, childfilePath, false); } } } dataGridScanNums.SelectedItem = dataGridScanNums.SelectedItem; itemsControlSampleViewModel.Data.Clear(); DrawPsm(tempPsm.Ms2ScanNumber, tempPsm.FullSequence); MessageBox.Show(string.Format("{0} PDFs exported", numberOfScansToExport)); } }
private void PDFButton_Click(object sender, RoutedEventArgs e) { object temp = null; var selections = new List <object>(); // select best scoring psm for any peptide selections foreach (object selectedItem in proteinTreeView.SelectedItems) { if (selectedItem.GetType().Name.Equals("PeptideForTreeView")) { PeptideForTreeView peptide = (PeptideForTreeView)selectedItem; PsmForTreeView bestScoringPsm = peptide.Children.OrderByDescending(psm => psm.Psm.Score).First(); selections.Add(bestScoringPsm); continue; } selections.Add(selectedItem); } if (proteinTreeView.SelectedItems.Count == 0) { MessageBox.Show("Please select at least one scan or coverage map to export"); } else { int numberOfScansToExport = selections.Distinct().Count(); foreach (object selectedItem in selections.Distinct()) { if (temp == null) { temp = selectedItem; } var selection = selectedItem.GetType().Name; switch (selection) { case "ProteinForTreeView": { ProteinForTreeView protein = (ProteinForTreeView)selectedItem; string myString = illegalInFileName.Replace(protein.DisplayName, ""); myString = myString.Length > 30 ? myString.Substring(0, 30) : myString; string filePath = Path.Combine(Path.GetDirectoryName(psmFilePath), "MetaDrawExport", myString.Trim(), myString + ".pdf"); string dir = Path.GetDirectoryName(filePath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } DrawPdfCoverageMap(protein, mapGrid, filePath); } break; case "PsmForTreeView": { PsmForTreeView psm = (PsmForTreeView)selectedItem; var proteinFolder = illegalInFileName.Replace(psm.Parent.Parent.DisplayName, ""); proteinFolder = proteinFolder.Length > 30 ? proteinFolder.Substring(0, 30) : proteinFolder; string peptideFolder = illegalInFileName.Replace(psm.Parent.DisplayName, ""); peptideFolder = peptideFolder.Length > 30 ? peptideFolder.Substring(0, 30) : peptideFolder; string filePath = Path.Combine(Path.GetDirectoryName(psmFilePath), "MetaDrawExport", proteinFolder.Trim(), peptideFolder.Trim(), psm.ScanNo + ".pdf"); string dir = Path.GetDirectoryName(filePath); MsDataScan msDataScanToDraw = MsDataFile.GetOneBasedScan(psm.ScanNo); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } DrawPdfAnnotatedBaseSequence(psm.Psm, canvas, filePath); // captures the annotation for the pdf mainViewModel.DrawPeptideSpectralMatchPdf(msDataScanToDraw, psm.Psm, filePath, numberOfScansToExport > 1); } break; } } RestoreDefault(temp); MessageBox.Show(string.Format("{0} PDFs exported", numberOfScansToExport)); } }