diff --git a/src/main/groovy/life/qbic/utils/MaxQuantParser.groovy b/src/main/groovy/life/qbic/utils/MaxQuantParser.groovy index aed1088..edc427b 100644 --- a/src/main/groovy/life/qbic/utils/MaxQuantParser.groovy +++ b/src/main/groovy/life/qbic/utils/MaxQuantParser.groovy @@ -118,7 +118,7 @@ class MaxQuantParser implements DatasetParser { rootChildren.each { currentChild -> if (currentChild.containsKey("children")) { //folder - parseTxtFolder(map) + parseSubFolders(map) } else if (currentChild.containsKey("fileType")) { //file String name = currentChild.get("name") @@ -132,7 +132,7 @@ class MaxQuantParser implements DatasetParser { } /** - * Method which adapts the parsed content of the txt directory in place to the expected file structure. + * Method which adapts the parsed content of the txt directory in place to the expected file structure. This directory can be inside an optional 'combined' directory * @see {valid datastructure example} * * After parsing, the files of the txt directory are contained in the children property of the root directory. @@ -140,10 +140,18 @@ class MaxQuantParser implements DatasetParser { * @param maxQuantInformation a nested map representing the parsed fileTree structure * @since 1.9.0 */ - private static void parseTxtFolder(Map maxQuantInformation) { + private static void parseSubFolders(Map maxQuantInformation) { List rootFolderInformation = maxQuantInformation.get("children") as List def txtFolderInformation rootFolderInformation.findAll { map -> + if (map.get("name") == "combined") { + def combinedFolderInformation = map.get("children") as List + combinedFolderInformation.findAll() { innerMap -> + if (innerMap.get("name") == "txt") { + txtFolderInformation = innerMap.get("children") as List + } + } + } if (map.get("name") == "txt") { txtFolderInformation = map.get("children") as List } diff --git a/src/test/groovy/life/qbic/utils/MaxQuantParserSpec.groovy b/src/test/groovy/life/qbic/utils/MaxQuantParserSpec.groovy index c2bfe70..7e0bb8d 100644 --- a/src/test/groovy/life/qbic/utils/MaxQuantParserSpec.groovy +++ b/src/test/groovy/life/qbic/utils/MaxQuantParserSpec.groovy @@ -52,6 +52,37 @@ class MaxQuantParserSpec extends Specification { assert maxQuantRunResult.proteinGroups.getName()== "proteinGroups.txt" } + def "parsing the old file structure with combined folder returns a maxQuantRunResult object"() { + given: "A valid maxQuant run output data structure" + def pathToDirectory = Paths.get(exampleDirectoriesRoot, "validates2") + when: "we parse this valid structure" + MaxQuantRunResult maxQuantRunResult = maxQuantParser.parseFrom(pathToDirectory) + then: "we expect no exception should be thrown" + assert maxQuantRunResult instanceof MaxQuantRunResult + //Root files can be parsed + assert maxQuantRunResult.runParameters.getRelativePath() == "./mqpar.xml" + assert maxQuantRunResult.runParameters.getName()== "mqpar.xml" + + assert maxQuantRunResult.sampleIds.getRelativePath() == "./QABCD_sample_ids.txt" + assert maxQuantRunResult.sampleIds.getName()== "QABCD_sample_ids.txt" + + //Files in ./txt/ can be parsed + assert maxQuantRunResult.allPeptides.getRelativePath() == "./combined/txt/allPeptides.txt" + assert maxQuantRunResult.allPeptides.getName()== "allPeptides.txt" + + assert maxQuantRunResult.evidence.getRelativePath() == "./combined/txt/evidence.txt" + assert maxQuantRunResult.evidence.getName()== "evidence.txt" + + assert maxQuantRunResult.parameters.getRelativePath() == "./combined/txt/parameters.txt" + assert maxQuantRunResult.parameters.getName()== "parameters.txt" + + assert maxQuantRunResult.peptides.getRelativePath() == "./combined/txt/peptides.txt" + assert maxQuantRunResult.peptides.getName()== "peptides.txt" + + assert maxQuantRunResult.proteinGroups.getRelativePath() == "./combined/txt/proteinGroups.txt" + assert maxQuantRunResult.proteinGroups.getName()== "proteinGroups.txt" + } + def "parsing an invalid file structure throws DatasetValidationException"() { given: def pathToDirectory = Paths.get(exampleDirectoriesRoot, "fails/missing_txt_directory") diff --git a/src/test/resources/dummyFileSystem/maxquant-run-output/validates2/QABCD_sample_ids.txt b/src/test/resources/dummyFileSystem/maxquant-run-output/validates2/QABCD_sample_ids.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/test/resources/dummyFileSystem/maxquant-run-output/validates2/combined/txt/allPeptides.txt b/src/test/resources/dummyFileSystem/maxquant-run-output/validates2/combined/txt/allPeptides.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/test/resources/dummyFileSystem/maxquant-run-output/validates2/combined/txt/evidence.txt b/src/test/resources/dummyFileSystem/maxquant-run-output/validates2/combined/txt/evidence.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/test/resources/dummyFileSystem/maxquant-run-output/validates2/combined/txt/parameters.txt b/src/test/resources/dummyFileSystem/maxquant-run-output/validates2/combined/txt/parameters.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/test/resources/dummyFileSystem/maxquant-run-output/validates2/combined/txt/peptides.txt b/src/test/resources/dummyFileSystem/maxquant-run-output/validates2/combined/txt/peptides.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/test/resources/dummyFileSystem/maxquant-run-output/validates2/combined/txt/proteinGroups.txt b/src/test/resources/dummyFileSystem/maxquant-run-output/validates2/combined/txt/proteinGroups.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/test/resources/dummyFileSystem/maxquant-run-output/validates2/mqpar.xml b/src/test/resources/dummyFileSystem/maxquant-run-output/validates2/mqpar.xml new file mode 100644 index 0000000..e69de29