Skip to content

Commit

Permalink
allow maxquant data containing the 'combined' subfolder (#129)
Browse files Browse the repository at this point in the history
* re-enable maxquant data containing the combined subfolder

Co-authored-by: Steffengreiner <[email protected]>
  • Loading branch information
wow-such-code and Steffengreiner authored Nov 9, 2023
1 parent ab2c43b commit aba60af
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/main/groovy/life/qbic/utils/MaxQuantParser.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class MaxQuantParser implements DatasetParser<MaxQuantRunResult> {
rootChildren.each { currentChild ->
if (currentChild.containsKey("children")) {
//folder
parseTxtFolder(map)
parseSubFolders(map)
} else if (currentChild.containsKey("fileType")) {
//file
String name = currentChild.get("name")
Expand All @@ -132,18 +132,26 @@ class MaxQuantParser implements DatasetParser<MaxQuantRunResult> {
}

/**
* 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 {<a href="https://github.com/qbicsoftware/data-model-lib/blob/master/src/test/resources/examples/resultset/maxquant/valid-resultset-example.json">valid datastructure example</a>}
*
* After parsing, the files of the txt directory are contained in the children property of the root directory.
* The underlying datastructure however expects a mapping of the expected files as a Map entry in the root directory.
* @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<Map> rootFolderInformation = maxQuantInformation.get("children") as List<Map>
def txtFolderInformation
rootFolderInformation.findAll { map ->
if (map.get("name") == "combined") {
def combinedFolderInformation = map.get("children") as List<Map>
combinedFolderInformation.findAll() { innerMap ->
if (innerMap.get("name") == "txt") {
txtFolderInformation = innerMap.get("children") as List<Map>
}
}
}
if (map.get("name") == "txt") {
txtFolderInformation = map.get("children") as List<Map>
}
Expand Down
31 changes: 31 additions & 0 deletions src/test/groovy/life/qbic/utils/MaxQuantParserSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit aba60af

Please sign in to comment.