Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow maxquant data containing the 'combined' subfolder #129

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
33 changes: 33 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,39 @@ 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"
//TODO remove print
println("#### Got $maxQuantRunResult for $pathToDirectory")
wow-such-code marked this conversation as resolved.
Show resolved Hide resolved
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