@@ -171,40 +171,40 @@ private static List<LibSourceFile> getLibSources(SpecLibReader libReader, ISpect
171171 {
172172 throw UnexpectedException .wrap (e , "Error reading source files from library file " + libFilePath .toString ());
173173 }
174- if (sourceFiles != null )
174+
175+ if (sourceFiles == null ) return null ;
176+
177+ if (sourceFiles .stream ().anyMatch (LibSourceFile ::isMaxQuantSearch ))
175178 {
176- if (sourceFiles .stream ().anyMatch (LibSourceFile ::isMaxQuantSearch ))
179+ // For libraries built with MaxQuant search results we need to add additional files that are required for library building
180+ Set <String > idFileNames = sourceFiles .stream ().filter (LibSourceFile ::hasIdFile ).map (LibSourceFile ::getIdFile ).collect (Collectors .toSet ());
181+ for (String file : LibSourceFile .MAX_QUANT_ID_FILES )
177182 {
178- // For libraries built with MaxQuant search results we need to add additional files that are required for library building
179- Set <String > idFileNames = sourceFiles .stream ().filter (LibSourceFile ::hasIdFile ).map (LibSourceFile ::getIdFile ).collect (Collectors .toSet ());
180- for (String file : LibSourceFile .MAX_QUANT_ID_FILES )
183+ if (!idFileNames .contains (file ))
181184 {
182- if (!idFileNames .contains (file ))
183- {
184- sourceFiles .add (new LibSourceFile (null , file , null ));
185- }
185+ sourceFiles .add (new LibSourceFile (null , file , null ));
186186 }
187187 }
188- else if (sourceFiles .stream ().anyMatch (LibSourceFile ::isDiannSearch ))
188+ }
189+ else if (sourceFiles .stream ().anyMatch (LibSourceFile ::isDiannSearch ))
190+ {
191+ // Building a library with DIA-NN results in Skyline requires a .speclib file and a report TSV file.
192+ // The .blib file includes the name of .speclib but not the name of the report TSV file.
193+ // Building a library without the TSV gives this error message in Skyline:
194+ // "...the TSV report is required to read speclib files and must be in the same directory as the speclib
195+ // and share some leading characters (e.g. somedata-tsv.speclib and somedata-report.tsv)..."
196+
197+ // At some point Skyline may start including the names of all source files in the .blib SQLite file,
198+ // so first check if any TSV files were listed as sources in the .blib
199+ boolean hasTsvFiles = sourceFiles .stream ()
200+ .anyMatch (file -> file .hasIdFile () && file .getIdFile ().toLowerCase ().endsWith (".tsv" ));
201+ if (!hasTsvFiles )
189202 {
190- // Building a library with DIA-NN results in Skyline requires a .speclib file and a report TSV file.
191- // The .blib file includes the name of .speclib but not the name of the report TSV file, unfortunately.
192- // We only know that: "the TSV report is required to read speclib files and must be in the
193- // same directory as the speclib and share some leading characters
194- // (e.g. somedata-tsv.speclib and somedata-report.tsv)"
195-
196- // At some point Skyline may start including the names of all source files in the .blib SQLite file,
197- // so first check if any TSV files are listed as sources in the .blib
198- boolean hasTsvFiles = sourceFiles .stream ()
199- .anyMatch (file -> file .hasIdFile () && file .getIdFile ().toLowerCase ().endsWith (".tsv" ));
200- if (!hasTsvFiles )
201- {
202- // If there is no TSV source listed in the .blib, then add a placeholder for the DIA-NN report file.
203- sourceFiles .add (new LibSourceFile (null , LibSourceFile .DIANN_REPORT_TSV_PLACEHOLDER , null ));
204- }
203+ // If there is no TSV source listed in the .blib, then add a placeholder for the DIA-NN report file.
204+ sourceFiles .add (new LibSourceFile (null , LibSourceFile .DIANN_REPORT_TSV_PLACEHOLDER , null ));
205205 }
206-
207206 }
207+
208208 return sourceFiles ;
209209 }
210210
@@ -294,7 +294,6 @@ private void validateLibrarySources(List<LibSourceFile> sources, FileContentServ
294294
295295 private Path getPath (String name , Set <Path > rawFilesDirPaths , boolean isMaxquant , FileContentService fcs )
296296 {
297- // TODO: Prefer root experiment RawFiles directory?
298297 for (Path rawFilesDir : rawFilesDirPaths )
299298 {
300299 Path path = findInDirectoryTree (rawFilesDir , name , isMaxquant );
@@ -322,9 +321,9 @@ private static Path getDiannReportFilePath(Path speclibFilePath)
322321
323322 private static Path getDiannReportFilePath (String specLibFileName , List <Path > candidateFiles )
324323 {
325- Map <Path , Integer > prefixLengthMap = getCommonPrefixLengths (candidateFiles , specLibFileName );
324+ Map <Path , Integer > prefixLengthMap = getCommonPrefixLengthsForTsvFiles (candidateFiles , specLibFileName );
326325
327- // Find the TSV file with the longest common prefix that has the expected column headers in the first line
326+ // Find the TSV file with the longest common prefix that also has the expected column headers in the first line
328327 return prefixLengthMap .entrySet ().stream ()
329328 .sorted ((entry1 , entry2 ) -> Integer .compare (entry2 .getValue (), entry1 .getValue ())) // Sort descending by matching prefix length
330329 .map (Map .Entry ::getKey ) // File paths
@@ -333,7 +332,7 @@ private static Path getDiannReportFilePath(String specLibFileName, List<Path> ca
333332 .orElse (null );
334333 }
335334
336- private static Map <Path , Integer > getCommonPrefixLengths (List <Path > files , String specLibFileName )
335+ private static Map <Path , Integer > getCommonPrefixLengthsForTsvFiles (List <Path > files , String specLibFileName )
337336 {
338337 String specLibFileBaseName = FileUtil .getBaseName (specLibFileName ); // Remove file extension
339338 Map <Path , Integer > prefixLengthMap = new HashMap <>();
@@ -585,11 +584,12 @@ public void testCommonPrefixLength() throws IOException
585584 Path tsvFile5 = testDataDir .resolve ("no-prefix-match-report.tsv" );
586585 Path nonTsvFile1 = testDataDir .resolve ("report-lib.parquet.skyline-for-test.txt" );
587586 Path nonTsvFile2 = testDataDir .resolve ("report.txt" );
587+ Path nonTsvFile3 = testDataDir .resolve (specLibFileName );
588588
589- List <Path > files = List .of (tsvFile1 , tsvFile2 , tsvFile3 , tsvFile4 , tsvFile5 , nonTsvFile1 , nonTsvFile2 );
589+ List <Path > files = List .of (tsvFile1 , tsvFile2 , tsvFile3 , tsvFile4 , tsvFile5 , nonTsvFile1 , nonTsvFile2 , nonTsvFile3 );
590590
591- Map <Path , Integer > prefixLengthMap = SpecLibValidator .getCommonPrefixLengths (files , specLibFileName );
592- // Expect 4 TSV files in the list; files witout a prefix match, and non-TSV files should be ignored.
591+ Map <Path , Integer > prefixLengthMap = SpecLibValidator .getCommonPrefixLengthsForTsvFiles (files , specLibFileName );
592+ // Expect 4 TSV files in the list; files without a prefix match, and non-TSV files should be ignored.
593593 assertEquals ("Unexpected size of prefixLengthMap" , 4 , prefixLengthMap .size ());
594594
595595 // File report-lib.tsv should have a common prefix "report-lib"
@@ -613,13 +613,14 @@ public void testCommonPrefixLength() throws IOException
613613
614614 assertFalse (prefixLengthMap .containsKey (nonTsvFile1 ));
615615 assertFalse (prefixLengthMap .containsKey (nonTsvFile2 ));
616+ assertFalse (prefixLengthMap .containsKey (nonTsvFile3 ));
616617
617618 // List of files that do not share a common prefix with the speclib file
618- files = List .of (testDataDir .resolve ("absc .tsv" ), testDataDir .resolve ("1234.tsv" ), testDataDir .resolve ("lib.parquet.skyline.tsv" ));
619- prefixLengthMap = SpecLibValidator .getCommonPrefixLengths (files , specLibFileName );
619+ files = List .of (testDataDir .resolve ("abcd .tsv" ), testDataDir .resolve ("1234.tsv" ), testDataDir .resolve ("lib.parquet.skyline.tsv" ));
620+ prefixLengthMap = SpecLibValidator .getCommonPrefixLengthsForTsvFiles (files , specLibFileName );
620621 assertEquals (0 , prefixLengthMap .size ());
621622
622- prefixLengthMap = SpecLibValidator .getCommonPrefixLengths (files , specLibFileName );
623+ prefixLengthMap = SpecLibValidator .getCommonPrefixLengthsForTsvFiles (files , specLibFileName );
623624 assertEquals (0 , prefixLengthMap .size ());
624625 }
625626
@@ -632,15 +633,12 @@ public void testGetDiannReportFilePath() throws IOException
632633 Path reportTsvFile = SpecLibValidator .getDiannReportFilePath (specLibFileName , Collections .emptyList ());
633634 assertNull ("Unexpected report TSV file path returned. Input file list is empty." , reportTsvFile );
634635
635- // Files in the test directory:
636- // 1. report.tsv
637- // 2. report-lib-test.tsv
638- // 3. no-prefix-match-report-for-test.tsv
639- // 4. report-lib.parquet-missing-headers.tsv
636+ // TSV Files in the test directory
640637 Path tsvFile1 = testDataDir .resolve ("report.tsv" );
641638 Path tsvFile2 = testDataDir .resolve ("report-lib-for-test.tsv" );
642639 Path tsvFile3 = testDataDir .resolve ("no-prefix-match-report-for-test.tsv" );
643640 Path tsvFile4 = testDataDir .resolve ("report-lib.parquet-missing-headers.txt" );
641+ // Non-TSV files in the test directory
644642 Path nonTsvFile1 = testDataDir .resolve ("report.txt" );
645643 Path nonTsvFile2 = testDataDir .resolve ("report-lib.parquet.skyline-for-test.txt" );
646644 Path nonTsvFile3 = testDataDir .resolve (specLibFileName );
0 commit comments