Ejemplo n.º 1
0
        private static void WriteToSheetFrequencyMotif(ExcelPackage package, Motif motif, string title, ref int rowind, bool clear = true)
        {
            ExcelWorksheet worksheet =
                clear ? GetWorksheetBlank(package, "Motif") : GetWorksheetKeepData(package, "Motif");

            if (clear)
            {
                worksheet.Drawings.Clear();
            }

            worksheet.Cells[rowind, 1].Value   = "Frequency Threshold:";
            worksheet.Cells[rowind++, 2].Value = motif.PositiveThreshold;

            Settings settings    = Settings.Load("default.settings");
            int      heightImage = 200;
            int      widthImage  = 800;

            if (settings != null)
            {
                heightImage = settings.MotifHeight;
                widthImage  = settings.MotifWidth;
            }
            Bitmap bmp = motif.GetFrequencyMotif(widthImage, heightImage);

            if (bmp != null)
            {
                var picture = worksheet.Drawings.AddPicture(title, bmp);
                picture.SetPosition(rowind, 0, 1, 0);
            }
            int occupiedRows = (int)Math.Round(heightImage / worksheet.Row(rowind).Height);

            rowind += occupiedRows + 1;
            DumpMotifData(worksheet, ref rowind, null, motif.Frequencies);
        }
Ejemplo n.º 2
0
 public static bool SaveToFile(string filename, Motif motif)
 {
     try
     {
         motif.Version = typeof(Analyzer).Assembly.GetName().Version.ToString();
         string json = JsonConvert.SerializeObject(motif);
         File.WriteAllText(filename, json);
         return(true);
     }
     catch { return(false); }
 }
Ejemplo n.º 3
0
 public static Motif ReadFromFile(string filename)
 {
     try
     {
         Motif motif = null;
         if (File.Exists(filename))
         {
             motif = JsonConvert.DeserializeObject <Motif>(File.ReadAllText(filename));
             if (motif.Version == "")
             {
                 motif.Version = "Old version";
             }
         }
         return(motif);
     }
     catch (Exception exc) { return(null); }
 }
Ejemplo n.º 4
0
 public bool Run(Motif motif, int posSpec, int negSpec)
 {
     if (motif == null)
     {
         return(false);
     }
     Motif = motif;
     PositiveSpecificity = posSpec;
     NegativeSpecificity = negSpec;
     if (!GenerateTemplate())
     {
         return(false);
     }
     FullSequenceList     = SequenceGenerator.Combinations(FullTemplate);
     PositiveSequenceList = SequenceGenerator.Combinations(PositiveTemplate);
     NegativeSequenceList = FullSequenceList.Except(PositiveSequenceList).ToList();
     return(true);
 }
Ejemplo n.º 5
0
        public static bool ExportPeptideArrayToExcel(string fileName, PeptideArray PA, bool overwrite, out string errormsg)
        {
            try
            {
                errormsg = "";
                FileInfo existingFile = new FileInfo(fileName);
                if (existingFile.Exists && !overwrite)
                {
                    return(false);
                }
                using (ExcelPackage package = new ExcelPackage(existingFile))
                {
                    if (existingFile.Exists)
                    {
                        while (package.Workbook.Worksheets.Count > 0)
                        {
                            package.Workbook.Worksheets.Delete(1);
                        }
                    }
                    ExcelWorksheet worksheet = GetWorksheetBlank(package, "Arrays");

                    int lastrow = MatrixToExcel(worksheet, 1, "Peptide Matrix", PA.PeptideMatrix);
                    if (lastrow < 0)
                    {
                        return(false);
                    }
                    lastrow = MatrixToExcel(worksheet, lastrow + 3, "Binary Matrix", PA.BinaryMatrix);
                    if (lastrow < 0)
                    {
                        return(false);
                    }
                    lastrow = MatrixToExcel(worksheet, lastrow + 3, "Quantification Matrix", PA.QuantificationMatrix);
                    if (lastrow < 0)
                    {
                        return(false);
                    }

                    worksheet.Cells[++lastrow, 1].Value = "Norm By:";
                    worksheet.Cells[lastrow, 2].Value   = PA.NormalizationValue;
                    lastrow = MatrixToExcel(worksheet, lastrow + 3, "Normalized Matrix", PA.NormalizedMatrix);

                    WriteToSheetWeighedPeptideList(package, PA.NormalizedPeptideWeights, PA.PositiveThreshold, PA.NegativeThreshold);

                    if (PA.KeyPosition != null && PA.KeyAA != ' ')
                    {
                        int           rowind      = 1;
                        List <string> mainList    = PA.ModifiedPeptides.Where(s => s[(int)PA.KeyPosition - 1] == PA.KeyAA).ToList();
                        List <string> shiftedList = Analyzer.ShiftPeptides(PA.ModifiedPeptides.Where(s => s[(int)PA.KeyPosition - 1] != PA.KeyAA).ToList(), PA.KeyAA, PA.PeptideLength, (int)PA.KeyPosition - 1,
                                                                           out List <string> replacements);
                        Motif motif = new Motif(mainList, PA.PeptideLength);
                        motif.FreqThreshold = PA.FrequencyThreshold;

                        WriteToSheetFrequencyMotif(package, motif, "Motif", ref rowind);
                        rowind++;

                        motif = new Motif(shiftedList, PA.PeptideLength);
                        motif.FreqThreshold = PA.FrequencyThreshold;
                        WriteToSheetFrequencyMotif(package, motif, "Shifted Motif", ref rowind, false);
                    }
                    else
                    {
                        Motif motif = new Motif(PA.ModifiedPeptides, PA.PeptideLength);
                        motif.FreqThreshold = PA.FrequencyThreshold;

                        int rowind = 1;
                        WriteToSheetFrequencyMotif(package, motif, "Motif", ref rowind);
                    }

                    WriteToSheetReferenceInfo(package, PA);

                    try
                    {
                        package.Save();
                    }
                    catch
                    {
                        errormsg = "There is a problem with saving the export file. Please make sure the file is not open and you have writing rights to the specific folder.";
                        return(false);
                    }
                }

                return(true);
            }
            catch
            {
                errormsg = "There is a problem with creating the export file. Please try again.";
                return(false);
            }
        }
Ejemplo n.º 6
0
        private static void WriteToSheetMotif(ExcelPackage package, Motif motif)
        {
            ExcelWorksheet worksheet = GetWorksheetBlank(package, "Motif");

            worksheet.Drawings.Clear();

            Settings settings    = Settings.Load("default.settings");
            int      heightImage = 200;
            int      widthImage  = 800;

            if (settings != null)
            {
                heightImage = settings.MotifHeight;
                widthImage  = settings.MotifWidth;
            }

            int rowind = 1;

            worksheet.Cells[rowind, 1].Value   = "Positive Threshold:";
            worksheet.Cells[rowind++, 2].Value = motif.PositiveThreshold;
            if (motif.WildTypePeptide != "")
            {
                worksheet.Cells[rowind, 1].Value   = "Wildtype Sequence:";
                worksheet.Cells[rowind++, 2].Value = motif.WildTypePeptide;
            }

            Bitmap bmp = motif.GetPositiveMotif(widthImage, heightImage);

            if (bmp != null)
            {
                var picture = worksheet.Drawings.AddPicture("Positive Motif", bmp);
                picture.SetPosition(rowind, 0, 1, 0);
            }

            int occupiedRows = (int)Math.Round(heightImage / worksheet.Row(rowind).Height);

            rowind += occupiedRows + 1;

            Dictionary <int, Dictionary <char, double> > scaledcolumns = motif.GetScaledColumns(motif.PositiveColumns);

            DumpMotifData(worksheet, ref rowind, motif.PositiveColumns, scaledcolumns);

            rowind += 2;

            worksheet.Cells[rowind, 1].Value   = "Negative Threshold:";
            worksheet.Cells[rowind++, 2].Value = motif.NegativeThreshold;

            bmp = motif.GetNegativeMotif(widthImage, heightImage);
            if (bmp != null)
            {
                var picture = worksheet.Drawings.AddPicture("Negative Motif", bmp);
                picture.SetPosition(rowind, 0, 1, 0);
            }

            occupiedRows = (int)Math.Round(heightImage / worksheet.Row(rowind).Height);
            rowind      += occupiedRows + 1;

            scaledcolumns = motif.GetScaledColumns(motif.NegativeColumns);
            DumpMotifData(worksheet, ref rowind, motif.NegativeColumns, scaledcolumns);

            rowind += 2;

            worksheet.Cells[rowind++, 1].Value = "Bar Chart:";
            bmp = motif.GetBarChart(widthImage / 2);
            if (bmp != null)
            {
                var picture = worksheet.Drawings.AddPicture("Bar Chart", bmp);
                picture.SetPosition(rowind, 0, 1, 0);
            }

            occupiedRows = (int)Math.Round(heightImage / worksheet.Row(rowind).Height);
            rowind      += occupiedRows + 1;
        }