MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / findSpectraFile

Function findSpectraFile

src/openms/source/FORMAT/ExperimentalDesignFile.cpp:25–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23namespace OpenMS
24{
25 String findSpectraFile(const String &spec_file, const String &tsv_file, const bool require_spectra_files)
26 {
27 String result;
28 QFileInfo spectra_file_info(spec_file.toQString());
29 if (spectra_file_info.isRelative())
30 {
31 // file name is relative, so we need to figure out the correct folder
32
33 // first check folder relative to folder of design file
34 // to allow, for example, a design in ./design.tsv and spectra in ./spectra/a.mzML
35 // where ./ is the same folder
36 QFileInfo design_file_info(tsv_file.toQString());
37 QString design_file_relative(design_file_info.absolutePath());
38 design_file_relative = design_file_relative + "/" + spec_file.toQString();
39
40 if (File::exists(design_file_relative))
41 {
42 result = design_file_relative.toStdString();
43 }
44 else
45 {
46 // check current folder
47 String f = File::absolutePath(spec_file);
48 if (File::exists(f))
49 {
50 result = f;
51 }
52 }
53
54 // if result still empty, just use the provided value
55 if (result.empty())
56 {
57 result = spec_file;
58 }
59 }
60 else
61 {
62 // set to absolute path
63 result = spec_file;
64 }
65
66 // Fail if the existence of the spectra files is required but they do not exist
67 if (require_spectra_files && !File::exists(result))
68 {
69 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, tsv_file,
70 "Error: Spectra file does not exist: '" + result + "'");
71 }
72 return result;
73 }
74
75 // Parse Error of filename if test holds
76 void ExperimentalDesignFile::parseErrorIf_(const bool test, const String &filename, const String &message)

Callers 2

parseOneTableFile_Method · 0.85
parseTwoTableFile_Method · 0.85

Calls 3

absolutePathMethod · 0.80
toQStringMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected