/// <summary> /// Reads the input paths file /// </summary> /// <param name="path"></param> /// <returns></returns> public static InputAnalysisInfo ReadInputFile(string path) { var info = new InputAnalysisInfo(); var lines = File.ReadAllLines(path); var readType = FileReadMode.None; foreach (var line in lines) { var fixedLine = line.ToLower(); fixedLine = fixedLine.Trim(); var containsHeaderOpen = fixedLine.Contains("["); var containsHeaderClose = fixedLine.Contains("]"); if (containsHeaderClose && containsHeaderOpen) { fixedLine = fixedLine.Replace(" ", ""); } if (string.IsNullOrEmpty(fixedLine) || string.IsNullOrWhiteSpace(fixedLine)) { continue; } // If wasModeChanged = true, then the current // line is not data, but a tag to say change how read the next section. var wasModeChanged = false; switch (fixedLine) { case FILE_HEADER: wasModeChanged = true; readType = FileReadMode.Files; break; case DATABASE_HEADER: wasModeChanged = true; readType = FileReadMode.Database; break; case RAW_HEADER: wasModeChanged = true; readType = FileReadMode.RawFiles; break; case SCANS_HEADER: wasModeChanged = true; readType = FileReadMode.ScanFiles; break; case PEAKS_HEADER: wasModeChanged = true; readType = FileReadMode.Peaks; break; case SEQUENCE_HEADER: wasModeChanged = true; readType = FileReadMode.Sequence; break; default: if (containsHeaderClose && containsHeaderOpen) { wasModeChanged = true; readType = FileReadMode.Unknown; throw new Exception(fixedLine + " is not a recognized data tag."); } wasModeChanged = false; break; } if (!wasModeChanged) { switch (readType) { case FileReadMode.Files: var baselineCheck = fixedLine.Split(BASELINE_INDICATOR); if (baselineCheck.Length == 2 && !string.IsNullOrEmpty(baselineCheck[0])) { var newFile = new InputFile(); newFile.Path = baselineCheck[0]; newFile.FileType = InputFileType.Features; info.BaselineFile = newFile; info.Files.Add(newFile); } else if (!string.IsNullOrEmpty(baselineCheck[0])) { var newFile = new InputFile(); newFile.Path = baselineCheck[0]; newFile.FileType = InputFileType.Features; info.Files.Add(newFile); } break; case FileReadMode.Database: var keys = fixedLine.Split('='); if (keys.Length > 1) { keys[0] = keys[0].Replace('\t', ' ').Trim(); switch (keys[0].ToLower()) { case "database": info.Database.DatabaseFormat = MassTagDatabaseFormat.MassTagSystemSql; info.Database.DatabaseName = keys[1]; break; case "server": info.Database.DatabaseFormat = MassTagDatabaseFormat.MassTagSystemSql; info.Database.DatabaseServer = keys[1]; break; case "sqlite": info.Database.DatabaseFormat = MassTagDatabaseFormat.Sqlite; info.Database.LocalPath = keys[1]; break; case "metasample": info.Database.DatabaseFormat = MassTagDatabaseFormat.DelimitedTextFile; info.Database.LocalPath = keys[1]; break; case "ims": info.Database.DatabaseFormat = MassTagDatabaseFormat.SkipAlignment; info.Database.LocalPath = keys[1]; break; } } break; case FileReadMode.RawFiles: var rawFile = new InputFile(); rawFile.Path = fixedLine; rawFile.FileType = InputFileType.Raw; info.Files.Add(rawFile); break; case FileReadMode.ScanFiles: var scanFile = new InputFile(); scanFile.Path = fixedLine; scanFile.FileType = InputFileType.Scans; info.Files.Add(scanFile); break; case FileReadMode.Unknown: // do nothing! break; case FileReadMode.Sequence: var sequenceFile = new InputFile(); sequenceFile.Path = fixedLine; sequenceFile.FileType = InputFileType.Sequence; info.Files.Add(sequenceFile); break; } } } return(info); }
/// <summary> /// Loads factors from file or other. /// </summary> private void ConstructFactorInformation(InputAnalysisInfo analysisSetupInformation, ObservableCollection<DatasetInformation> datasets, FeatureDataAccessProviders providers) { var mage = new MAGEFactorAdapter(); if (analysisSetupInformation.FactorFile == null) { Logger.PrintMessage("Loading Factor Information from DMS"); mage.LoadFactorsFromDMS(datasets, providers); } else { Logger.PrintMessage("Loading Factor Information from file: " + analysisSetupInformation.FactorFile); mage.LoadFactorsFromFile(analysisSetupInformation.FactorFile, datasets, providers); } }
private void ImportFactors(AnalysisConfig config, bool databaseExists) { Logger.PrintMessage("Updating factors"); if (!databaseExists) { Logger.PrintMessage("The database you specified to extract data from does not exist."); return; } // Create access to data. var providers = SetupDataProviders(false); if (providers == null) { Logger.PrintMessage("Could not create connection to database."); return; } // Find all the datasets var datasetsFactors = providers.DatasetCache.FindAll(); if (datasetsFactors == null || datasetsFactors.Count == 0) { Logger.PrintMessage("There are no datasets present in the current database."); CleanupDataProviders(); return; } var info = new InputAnalysisInfo(); if (config.options.ContainsKey("-factors")) { Logger.PrintMessage("Factor file specified."); var factorFile = config.options["-factors"][0]; info.FactorFile = factorFile; } ConstructFactorInformation(info, datasetsFactors.ToObservableCollection(), providers); CleanupDataProviders(); }
/// <summary> /// Constructs dataset infromation from the input analysis information. /// </summary> private void ConstructDatasetInformation(InputAnalysisInfo analysisSetupInformation, MultiAlignAnalysis analysis, bool insertIntoDatabase) { // Create dataset information. Logger.PrintMessage("Creating dataset and other input information."); var datasets = DatasetInformation.CreateDatasetsFromInputFile(analysisSetupInformation.Files); analysis.MetaData.Datasets.AddRange(datasets); if (insertIntoDatabase) { m_config.Analysis.DataProviders.DatasetCache.AddAll(datasets); } }
/// <summary> /// Constructs the baseline databases. /// </summary> private bool ConstructBaselines(InputAnalysisInfo analysisSetupInformation, AnalysisMetaData analysisMetaData, bool useMtdb) { Logger.PrintMessage("Confirming baseline selections."); if (useMtdb) { switch (analysisSetupInformation.Database.DatabaseFormat) { case MassTagDatabaseFormat.MassTagSystemSql: Logger.PrintMessage("Using Mass Tag Database:"); Logger.PrintMessage(string.Format("\tServer: {0}", analysisSetupInformation.Database.DatabaseServer)); Logger.PrintMessage(string.Format("\tDatabase Name: {0}", analysisSetupInformation.Database.DatabaseName)); m_config.Analysis.MetaData.Database = analysisSetupInformation.Database; break; case MassTagDatabaseFormat.Sqlite: Logger.PrintMessage("Using local Sqlite Mass Tag Database at location: "); Logger.PrintMessage(string.Format("\tFull Path: {0}", analysisSetupInformation.Database.LocalPath)); Logger.PrintMessage(string.Format("\tDatabase Name: {0}", Path.GetFileName(analysisSetupInformation.Database.LocalPath))); m_config.Analysis.MetaData.Database = analysisSetupInformation.Database; break; case MassTagDatabaseFormat.DelimitedTextFile: Logger.PrintMessage("Using local MetaSample Mass Tag Database at location: "); Logger.PrintMessage(string.Format("\tFull Path: {0}", analysisSetupInformation.Database.LocalPath)); Logger.PrintMessage(string.Format("\tDatabase Name: {0}", Path.GetFileName(analysisSetupInformation.Database.LocalPath))); m_config.Analysis.MetaData.Database = analysisSetupInformation.Database; break; } // Validate the baseline if (analysisSetupInformation.BaselineFile == null) { m_config.Analysis.Options.AlignmentOptions.IsAlignmentBaselineAMasstagDB = true; Logger.PrintMessage(string.Format("Using mass tag database {0} as the alignment baseline.", analysisSetupInformation.Database.DatabaseName)); } else { m_config.Analysis.Options.AlignmentOptions.IsAlignmentBaselineAMasstagDB = false; m_config.Analysis.MetaData.BaselineDataset = null; foreach (var info in analysisMetaData.Datasets) { if (info.Features.Path == analysisSetupInformation.BaselineFile.Path) { m_config.Analysis.MetaData.BaselineDataset = info; info.IsBaseline = true; m_config.Analysis.DataProviders.DatasetCache.Update(info); } } Logger.PrintMessage(string.Format("Using dataset {0} as the alignment baseline.", m_config.Analysis.MetaData.BaselineDataset)); } } else { m_config.Analysis.MetaData.Database = analysisSetupInformation.Database; m_config.Analysis.Options.AlignmentOptions.IsAlignmentBaselineAMasstagDB = false; if (analysisSetupInformation.BaselineFile == null) { Logger.PrintMessage("No baseline dataset or database was selected."); return false; } m_config.Analysis.MetaData.BaselineDataset = null; foreach (var info in analysisMetaData.Datasets) { if (info.Features.Path == analysisSetupInformation.BaselineFile.Path) { info.IsBaseline = true; m_config.Analysis.MetaData.BaselineDataset = info; m_config.Analysis.DataProviders.DatasetCache.Update(info); } } Logger.PrintMessage(string.Format("Using dataset {0} as the alignment baseline.", m_config.Analysis.MetaData.BaselineDataset)); } return true; }
private MultiAlignAnalysis ConstructAnalysisObject(InputAnalysisInfo analysisSetupInformation) { Logger.PrintMessage("Creating Analysis Objects."); var analysis = new MultiAlignAnalysis { MetaData = { AnalysisPath = m_config.AnalysisPath, AnalysisName = m_config.AnalysisName } }; analysis.Options.AlignmentOptions.IsAlignmentBaselineAMasstagDB = true; analysis.MetaData.ParameterFile = m_config.ParameterFile; analysis.MetaData.InputFileDefinition = m_config.InputPaths; analysis.MetaData.AnalysisSetupInfo = analysisSetupInformation; return analysis; }
private bool ReadInputDefinitionFile(out InputAnalysisInfo analysisSetupInformation, out bool useMtdb) { // Read the input datasets. if (!File.Exists(m_config.InputPaths)) { Logger.PrintMessage(string.Format("The input file {0} does not exist.", m_config.InputPaths)); } else { Logger.PrintMessage("Copying input file to output directory."); try { var dateSuffix = AnalysisPathUtils.BuildDateSuffix(); var newPath = Path.GetFileNameWithoutExtension(m_config.InputPaths); newPath = newPath + "_" + dateSuffix + ".txt"; File.Copy(m_config.InputPaths, Path.Combine(m_config.AnalysisPath, newPath)); } catch (Exception ex) { Logger.PrintMessage("Could not copy the input file to the output directory. " + ex.Message); } } Logger.PrintMessage("Parsing Input Filenames and Databases."); useMtdb = false; analysisSetupInformation = null; try { analysisSetupInformation = MultiAlignFileInputReader.ReadInputFile(m_config.InputPaths); } catch (Exception ex) { Logger.PrintMessage("The input file had some bad lines in it. " + ex.Message); return false; } Logger.PrintMessage("Found " + analysisSetupInformation.Files.Count + " files."); // Validate the mass tag database settings. try { useMtdb = analysisSetupInformation.Database.ValidateDatabaseType(); } catch (AnalysisMTDBSetupException ex) { Logger.PrintMessage("There was a problem with the mass tag database specification. " + ex.Message); return false; } return true; }
/// <summary> /// Reads the input paths file /// </summary> /// <param name="path"></param> /// <returns></returns> public static InputAnalysisInfo ReadInputFile(string path) { var info = new InputAnalysisInfo(); var lines = File.ReadAllLines(path); var readType = FileReadMode.None; foreach (var line in lines) { var fixedLine = line.ToLower(); fixedLine = fixedLine.Trim(); var containsHeaderOpen = fixedLine.Contains("["); var containsHeaderClose = fixedLine.Contains("]"); if (containsHeaderClose && containsHeaderOpen) { fixedLine = fixedLine.Replace(" ", ""); } if (string.IsNullOrEmpty(fixedLine) || string.IsNullOrWhiteSpace(fixedLine)) { continue; } // If wasModeChanged = true, then the current // line is not data, but a tag to say change how read the next section. var wasModeChanged = false; switch (fixedLine) { case FILE_HEADER: wasModeChanged = true; readType = FileReadMode.Files; break; case DATABASE_HEADER: wasModeChanged = true; readType = FileReadMode.Database; break; case RAW_HEADER: wasModeChanged = true; readType = FileReadMode.RawFiles; break; case SCANS_HEADER: wasModeChanged = true; readType = FileReadMode.ScanFiles; break; case PEAKS_HEADER: wasModeChanged = true; readType = FileReadMode.Peaks; break; case SEQUENCE_HEADER: wasModeChanged = true; readType = FileReadMode.Sequence; break; default: if (containsHeaderClose && containsHeaderOpen) { wasModeChanged = true; readType = FileReadMode.Unknown; throw new Exception(fixedLine + " is not a recognized data tag."); } wasModeChanged = false; break; } if (!wasModeChanged) { switch (readType) { case FileReadMode.Files: var baselineCheck = fixedLine.Split(BASELINE_INDICATOR); if (baselineCheck.Length == 2 && !string.IsNullOrEmpty(baselineCheck[0])) { var newFile = new InputFile(); newFile.Path = baselineCheck[0]; newFile.FileType = InputFileType.Features; info.BaselineFile = newFile; info.Files.Add(newFile); } else if (!string.IsNullOrEmpty(baselineCheck[0])) { var newFile = new InputFile(); newFile.Path = baselineCheck[0]; newFile.FileType = InputFileType.Features; info.Files.Add(newFile); } break; case FileReadMode.Database: var keys = fixedLine.Split('='); if (keys.Length > 1) { keys[0] = keys[0].Replace('\t', ' ').Trim(); switch (keys[0].ToLower()) { case "database": info.Database.DatabaseFormat = MassTagDatabaseFormat.MassTagSystemSql; info.Database.DatabaseName = keys[1]; break; case "server": info.Database.DatabaseFormat = MassTagDatabaseFormat.MassTagSystemSql; info.Database.DatabaseServer = keys[1]; break; case "sqlite": info.Database.DatabaseFormat = MassTagDatabaseFormat.Sqlite; info.Database.LocalPath = keys[1]; break; case "metasample": info.Database.DatabaseFormat = MassTagDatabaseFormat.DelimitedTextFile; info.Database.LocalPath = keys[1]; break; case "ims": info.Database.DatabaseFormat = MassTagDatabaseFormat.SkipAlignment; info.Database.LocalPath = keys[1]; break; } } break; case FileReadMode.RawFiles: var rawFile = new InputFile(); rawFile.Path = fixedLine; rawFile.FileType = InputFileType.Raw; info.Files.Add(rawFile); break; case FileReadMode.ScanFiles: var scanFile = new InputFile(); scanFile.Path = fixedLine; scanFile.FileType = InputFileType.Scans; info.Files.Add(scanFile); break; case FileReadMode.Unknown: // do nothing! break; case FileReadMode.Sequence: var sequenceFile = new InputFile(); sequenceFile.Path = fixedLine; sequenceFile.FileType = InputFileType.Sequence; info.Files.Add(sequenceFile); break; } } } return info; }