public override TargetCollection Import() { var targetCollection = new TargetCollection(); targetCollection.TargetList.Clear(); GetMassTagDataFromDB(targetCollection, MassTagsToBeRetrieved); GetModDataFromDB(targetCollection, MassTagsToBeRetrieved); var peptideUtils = new PeptideUtils(); var troubleSomePeptides = new List <TargetBase>(); foreach (var targetBase in targetCollection.TargetList) { var peptide = (PeptideTarget)targetBase; var baseEmpiricalFormula = peptideUtils.GetEmpiricalFormulaForPeptideSequence(peptide.Code); if (peptide.ContainsMods) { var peptide1 = peptide; var mods = (from n in _massTagModData where n.Item1 == peptide1.ID select n); foreach (var tuple in mods) { var modString = tuple.Item4; try { baseEmpiricalFormula = EmpiricalFormulaUtilities.AddFormula(baseEmpiricalFormula, modString); } catch { Console.WriteLine("Failed to calculate empirical formula for the Target " + peptide.ID + "; Having trouble with the mod: " + modString + "; This Target was NOT imported!!"); troubleSomePeptides.Add(peptide); } } } try { peptide.EmpiricalFormula = baseEmpiricalFormula; } catch { Console.WriteLine("Failed to calculate empirical formula for the Target " + peptide.ID + "; Cannot parse this formula: " + peptide.EmpiricalFormula + "; This Target was NOT imported!!"); troubleSomePeptides.Add(peptide); } } var cleanTargetList = new List <TargetBase>(); //filter out the bad peptides (the once with errors during empirical formula parsing) foreach (var peptide in targetCollection.TargetList) { if (!troubleSomePeptides.Contains(peptide)) { cleanTargetList.Add(peptide); } } targetCollection.TargetList = cleanTargetList; if (ChargeStateRangeBasedOnDatabase) { targetCollection.ApplyChargeStateFilter(ChargeStateFilterThreshold); } else { var chargeStateTargets = new List <TargetBase>(); foreach (var targetBase in targetCollection.TargetList) { var minCharge = 1; var maxCharge = 100; for (var charge = minCharge; charge <= maxCharge; charge++) { var mz = targetBase.MonoIsotopicMass / charge + Globals.PROTON_MASS; if (mz < MaxMZForChargeStateRange) { if (mz < MinMZForChargeStateRange) { break; } TargetBase chargeStateTarget = new PeptideTarget((PeptideTarget)targetBase); chargeStateTarget.ChargeState = (short)charge; chargeStateTarget.MZ = chargeStateTarget.MonoIsotopicMass / charge + Globals.PROTON_MASS; chargeStateTarget.ObsCount = -1; chargeStateTargets.Add(chargeStateTarget); } } } targetCollection.TargetList = chargeStateTargets.OrderBy(p => p.ID).ThenBy(p => p.ChargeState).ToList(); } return(targetCollection); }