Skip to content
Permalink
c9963f117b
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
588 lines (552 sloc) 22.7 KB
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Linq;
using System.Data;
using ThermoFisher.CommonCore.Data;
using ThermoFisher.CommonCore.Data.Interfaces;
using ThermoFisher.CommonCore.Data.Business;
namespace MARMoSET
{
public class InstrumentMethod
{
public string InstrumentFriendName { get; set; }
public string InstrumentName { get; set; }
public object Method { get; set; }
public object SharedTuneData { get; set; }
public string SoftwareVersion { get; set; }
public string HardwareVersion { get; set; }
/// <summary>
/// Getting Method Data for one selected instrument
/// </summary>
/// <param name="rawFile"> The current raw file as IRawDataPlus.</param>
/// <param name="index"> Index of the selected instrument.</param>
/// <param name="tuneData"> For MS Instruments the tune data as dictionary. For other instruments tuneData = null.</param>
///
public InstrumentMethod(IRawDataPlus rawFile, int index, bool toLower = false, object tuneData = null)
{
string[] name = rawFile.GetAllInstrumentNamesFromInstrumentMethod();
this.InstrumentName = name[index];
string[] friendName = rawFile.GetAllInstrumentFriendlyNamesFromInstrumentMethod();
this.InstrumentFriendName = friendName[index];
List<string> methode = MethodAsList(rawFile, index, toLower);
// due to the different structure of the method data string for each instrument:
if (name[index].Equals("Proxeon_EASY-nLC"))
{
this.Method = easyDictListCreate(methode);
}
else if (name[index].Equals("SiiXcalibur"))
{
this.Method = SiiDictListCreate(methode);
string helpName = methode[4];
string help2Name = helpName.Split(new[] { "on" }, StringSplitOptions.None)[0];
string help3Name = help2Name.Split(':')[1];
this.InstrumentFriendName = help3Name.Trim();
}
else if (name[index].Equals("Thermo Exactive"))
{
this.Method = exactiveDictListCreate(methode);
this.SharedTuneData = tuneData;
}
else if (name[index].Equals("TNG-Calcium"))
{
this.Method = calciumDictListCreate(methode);
this.SharedTuneData = tuneData;
}
else if (name[index].Equals("LTQ"))
{
Dictionary<string,object> methodWithResolution = ltqDictListCreate(methode);
// obtaining the resolution from all scans ('trailer data'), compare and add to method if all the same
if (friendName[index].Equals("LTQ Orbitrap MS"))
{
int sNumber = rawFile.RunHeaderEx.TrailerExtraCount;
var seqSNumber = Enumerable.Range(1, sNumber);
List<int> trailerD22List = new List<int>();
foreach (int scan in seqSNumber) // get resolution of each scan
{
Object aValue = rawFile.GetTrailerExtraValue(scan, 22);
int intValue = Convert.ToInt32(aValue);
trailerD22List.Add(intValue);
}
// Hash Set for unique Values
var resolutionValues = new HashSet<int>(trailerD22List);
resolutionValues.Remove(0); // no 0
string resolution = string.Join(", ", resolutionValues); // todo, unschoen. wenn fjson aus R weg, hier array
methodWithResolution.Add("Resolution", resolution);
}
this.Method = methodWithResolution;
this.SharedTuneData = tuneData;
}
// if instrument is none of the above -> Method is List<string>
else
{
this.Method = methode;
}
// for MS additional Hardware and Software information
if (!name[index].Equals("Proxeon_EASY-nLC"))
{
rawFile.SelectInstrument(Device.MS, 1);
this.SoftwareVersion = rawFile.GetInstrumentData().SoftwareVersion;
this.HardwareVersion = rawFile.GetInstrumentData().HardwareVersion;
}
}
/// <summary>
/// Split the method information string at \n and return a list of strings.
/// </summary>
/// <param name="rawFile"> The current raw file as IRawDataPlus.</param>
/// <param name="index"> Index of the selected instrument.</param>
///
public List<string> MethodAsList(IRawDataPlus rawFile, int index, bool toLower = false)
{
var Liste = new List<string>();
string methodText = rawFile.GetInstrumentMethod(index);
if (toLower)
{
methodText = methodText.ToLower();
}
string[] splitMethod = methodText.Split(new string[] { "\n" }, StringSplitOptions.None);
foreach (string s in splitMethod)
{
Liste.Add(s);
}
return Liste;
}
/// <summary>
/// For method data for the "Proxeon_EASY-nLC".
/// Parse list of strings to get information as key value pairs or table inside a dictionary.
/// </summary>
/// <param name="methodList"> Method information split by \n from "MethodAsList".</param>
///
public Dictionary<string, object> easyDictListCreate(List<string> methodList)
{
var dicList = new Dictionary<string, object>();
var dic = new Dictionary<string, string>();
DataTable table = new DataTable();
string[] split = new string[] { };
string titel = "start";
Boolean header = true;
foreach (string st in methodList)
{
// split
if (st.Contains(": ") || st.EndsWith(":"))
{
split = Regex.Split(st.Trim(), @": ");
}
else // for string of table
{
split = Regex.Split(st.Trim(), @"\s\s+");
}
// header
if (split.Length == 1 && !string.IsNullOrEmpty(titel) && split[0] != "")
{
if (split[0].Contains(':'))
{
split[0] = split[0].Trim(':');
}
if (dic.Count != 0)
{
// clone dic in dicList
dicList[titel] = new Dictionary<string, string>(dic);
// Clear dic
dic.Clear();
}
if (table.Rows.Count != 0)
{
// clone table in dicList
dicList[titel] = table.Copy();
table = new DataTable();
header = true;
}
titel = split[0].Trim();
}
// key : value
if (split.Length == 2)
{
// delete Whitespaces
split[0] = split[0].Trim();
split[1] = split[1].Trim();
// add to Dictionary
dic.Add(split[0], split[1]);
}
// table
if (split.Length > 2)
{
if (header == true)
{
foreach (string col in split)
{
table.Columns.Add(col, typeof(string));
}
header = false;
}
// Data
else
{
table.Rows.Add(split);
}
}
}
if (dic.Count != 0)
{
// clone dic in dicList
dicList[titel] = new Dictionary<string, string>(dic);
}
if (table.Rows.Count != 0)
{
// clone dic in dicList
dicList[titel] = table.Copy();
table = new DataTable();
}
return dicList;
}
/// <summary>
/// For method data for the "Sii".
/// Parse list of strings to get information as key value pairs or table inside a dictionary.
/// </summary>
/// <param name="methodList"> Method information split by \n from "MethodAsList".</param>
///
public Dictionary<string, object> SiiDictListCreate(List<string> methodList)
{
var dicList = new Dictionary<string, object>();
var dic = new Dictionary<string, object>();
string[] split = new string[] { };
List<string> udp = new List<string>();
bool udpValue = false;
string titel = "start";
foreach (string st in methodList)
{
string trimSt = st.Trim();
if (st.Contains(": ") || st.EndsWith(":"))
{
split = Regex.Split(trimSt, @": ");
// key : value
if (split.Length == 2)
{
// delete Whitespaces
split[0] = split[0].Trim();
split[1] = split[1].Trim();
// add to Dictionary
dic.Add(split[0], split[1]);
split = new string[] { };
}
}
// Heading is without spaces in front
else if (!st.StartsWith(" "))
{
if (dic.Count != 0)
{
// clone dic in dicList
dicList[titel] = new Dictionary<string, object>(dic);
// Clear dic
dic.Clear();
}
titel = trimSt.Replace("----", "");
}
else if (trimSt.StartsWith("Sampler.Udp"))
{
string coTrimSt = trimSt.Replace(",", " ");
udp.Add(coTrimSt);
if (trimSt.EndsWith(","))
{
udpValue = true;
}
}
else if (udpValue)
{
string coTrimSt = trimSt.Replace(",", " ");
udp[udp.Count -1] = udp[udp.Count - 1] + coTrimSt;
if (!trimSt.EndsWith(","))
{
udpValue = false;
}
}
else
{
}
}
if (dic.Count != 0)
{
// clone dic in dicList
dicList[titel] = new Dictionary<string, object>(dic);
}
if (udp.Any())
{
dicList["Sampler.Udp"] = udp;
}
return dicList;
}
/// <summary>
/// For method data of the "TNG-Calcium".
/// Parse list of strings to get information as key value pairs inside a dictionary.
/// </summary>
/// <param name="methodList"> Method information split by \n from "MethodAsList".</param>
///
public Dictionary<string, object> calciumDictListCreate(List<string> methodList)
{
var dicList = new Dictionary<string, object>();
var dic = new Dictionary<string, string>();
string[] split = new string[] { };
string titel = "start";
foreach (string st in methodList)
{
// split
if (st.Contains("= "))
{
split = Regex.Split(st.Trim(), @"=");
}
else
{
split = Regex.Split(st.Trim(), @"\s\s+");
}
// header
if (split.Length == 1 && !string.IsNullOrEmpty(titel) && split[0] != "")
{
if (dic.Count != 0)
{
// clone dic in dicList
dicList[titel] = new Dictionary<string, string>(dic);
// Clear dic
dic.Clear();
}
titel = split[0].Trim();
}
// key : value pair
if (split.Length == 2)
{
// delete Whitespaces
split[0] = split[0].Trim();
split[1] = split[1].Trim();
// add to Dictionary
dic.Add(split[0], split[1]);
}
}
if (dic.Count != 0)
{
// clone dic in dicList
dicList[titel] = new Dictionary<string, string>(dic);
}
// remove unneccessary entry
dicList.Remove("orbitrap fusion method summary");
return dicList;
}
/// <summary>
/// For method data of the "Thermo Exactive".
/// Parse list of strings to get information as key value pairs inside a dictionary.
/// </summary>
/// <param name="methodList"> Method information split by \n from "MethodAsList".</param>
///
public Dictionary<string, object> exactiveDictListCreate(List<string> methodList)
{
var dicList = new Dictionary<string, object>();
var dic = new Dictionary<string, string>();
string[] split = new string[] { };
string titel = "start";
foreach (string st in methodList)
{
// split
split = Regex.Split(st.Trim(), @"\s\s+");
// header
if (split.Length != 2 && !string.IsNullOrEmpty(titel) && split[0] != "" && split[0] != "general" && split[0] != "(no entries)")
{
if (dic.Count != 0)
{
// clone dic in dicList
dicList[titel] = new Dictionary<string, string>(dic);
// Clear dic
dic.Clear();
}
titel = split[0].Trim();
}
// key : value pair
if (split.Length == 2)
{
// delete Whitespaces
split[0] = split[0].Trim();
split[1] = split[1].Trim();
// add to Dictionary
dic.Add(split[0], split[1]);
}
}
if (dic.Count != 0)
{
// clone dic in dicList
dicList[titel] = new Dictionary<string, string>(dic);
}
return dicList;
}
/// <summary>
/// For method data of the "LTQ".
/// Parse list of strings to get information as key value pairs and tables inside a dictionary.
/// </summary>
/// <param name="methodList"> Method information split by \n from "MethodAsList".</param>
///
public Dictionary<string, object> ltqDictListCreate(List<string> methodList)
{
var dicList = new Dictionary<string, object>();
var dic = new Dictionary<string, object>();
string[] split = new string[] { };
string title = "general";
// table helper
DataTable table = new DataTable();
bool tHeader = true;
string tableTitle = "";
// Helpers for dictionary in dic
bool level2 = false;
string title2 = "";
var dicLevel2 = new Dictionary<string, string>();
foreach (string st in methodList)
{
bool splitIsHeader = false;
// split at : , = , enabled/not enabled/disabled , whitespaces
if (st.Contains(":"))
{
split = Regex.Split(st.Trim(), @": ");
splitIsHeader = true;
}
else if (st.Contains("="))
{
split = Regex.Split(st.Trim(), @"=");
splitIsHeader = true;
}
else if (st.Contains("not enabled") || st.Contains("Not enabled"))
{
string replaced = st.Replace("not enabled", "#not enabled");
replaced = replaced.Replace("Not enabled", "#not enabled");
split = Regex.Split(replaced,"#");
}
else if (st.Contains("abled"))
{
string replaced = st.Replace("enabled", "#enabled");
replaced = replaced.Replace("disabled", "#disabled");
split = Regex.Split(replaced, "#");
}
else // for string of table
{
split = Regex.Split(st.Trim(), @"\s\s+");
}
split[0] = split[0].Trim();
if (String.Equals(split[0], "scan event details:") || String.Equals(split[0], "Scan Event Details:"))
{
splitIsHeader = false;
char[] delChar = { ':' };
title = split[0].TrimEnd(delChar);
level2 = true;
}
// header
if (split.Length == 1 && !string.IsNullOrEmpty(title) && split[0] != "" && splitIsHeader)
{
if (dic.Count != 0)
{
if (dicLevel2.Count != 0)
{
// clone dicLevel2 in dic
dic[title2] = new Dictionary<string, string>(dicLevel2);
// Clear dicLevel2
dicLevel2.Clear();
level2 = false;
}
// clone dic in dicList
dicList[title] = new Dictionary<string, object>(dic);
// Clear dic
dic.Clear();
}
if (table.Rows.Count != 0)
{
// clone table in dicList
dicList[tableTitle] = table.Copy();
table = new DataTable();
tHeader = true;
}
title = split[0];
}
// line with information
else if (split.Length == 1 && !splitIsHeader && split[0] != "" && split[0].Contains('.'))
{
if (dicLevel2.Count != 0)
{
if (!dicLevel2.ContainsKey("Info"))
{
// add to Dictionary
dicLevel2.Add("Info", split[0]);
}
// clone dicLevel2 in dic
dic[title2] = new Dictionary<string, string>(dicLevel2);
// Clear dicLevel2
dicLevel2.Clear();
level2 = false;
}
else if (!dic.ContainsKey(split[0]))
{
// add to Dictionary
dic.Add("Info", split[0]);
}
}
// 2nd level key : value pair
else if (split.Length == 2 && level2)
{
split[1] = split[1].Trim();
if (Regex.IsMatch(split[0], @"^\d"))
{
if (dicLevel2.Count != 0)
{
// clone dicLevel2 in dic
dic[title2] = new Dictionary<string, string>(dicLevel2);
// Clear dicLevel2
dicLevel2.Clear();
}
title2 = split[1];
}
if (!dicLevel2.ContainsKey(split[0]))
{
// add to Dictionary
dicLevel2.Add(split[0], split[1]);
}
}
// usual key : value
else if (split.Length == 2)
{
// delete Whitespaces
split[1] = split[1].Trim();
if (!dic.ContainsKey(split[0]))
{
// add to Dictionary
dic.Add(split[0], split[1]);
}
}
// table
else if (split.Length > 2)
{
tableTitle = title;
if (tHeader)
{
int i = 0;
foreach (string col in split)
{
i++;
string cname = "col" + i;
table.Columns.Add(cname, typeof(string));
}
tHeader = false;
}
// Data
else
{
table.Rows.Add(split);
}
}
}
// catch last entries
if (dic.Count != 0)
{
// clone dic in dicList
dicList[title] = new Dictionary<string, object>(dic);
}
if (table.Rows.Count != 0)
{
// clone dic in dicList
dicList[title] = table.Copy();
}
return dicList;
}
}
}