Skip to content

Commit e044765

Browse files
committed
Resolver now goes 1 level deep into subfolders.
1 parent 4bb5152 commit e044765

File tree

2 files changed

+64
-43
lines changed

2 files changed

+64
-43
lines changed

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/resolver/DataSetResolver.java

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public static enum Type {
4040
GSEA_FOLDER,
4141
EXPRESSION,
4242
RANKS,
43+
CLASS,
4344
GENE_SETS,
4445
IGNORE;
4546

@@ -101,6 +102,7 @@ private static List<DataSetParameters> createDataSets(Map<Type,List<Path>> types
101102
// MKTODO add other enrichment types
102103
List<Path> exprFiles = new ArrayList<>(types.get(Type.EXPRESSION));
103104
List<Path> rankFiles = new ArrayList<>(types.get(Type.RANKS));
105+
List<Path> clasFiles = new ArrayList<>(types.get(Type.CLASS));
104106
List<Path> gmtFiles = new ArrayList<>(types.get(Type.GENE_SETS));
105107

106108
// MKTODO what about other enrichment types?
@@ -110,6 +112,7 @@ private static List<DataSetParameters> createDataSets(Map<Type,List<Path>> types
110112

111113
Optional<Path> closestExpr = findClosestMatch(enrichment, exprFiles);
112114
Optional<Path> closestRanks = findClosestMatch(enrichment, rankFiles);
115+
Optional<Path> closestClass = findClosestMatch(enrichment, clasFiles);
113116
Optional<Path> closestGmt = findClosestMatch(enrichment, gmtFiles);
114117

115118
closestExpr.ifPresent(path -> {
@@ -120,6 +123,10 @@ private static List<DataSetParameters> createDataSets(Map<Type,List<Path>> types
120123
rankFiles.remove(path);
121124
files.setRankedFile(path.toAbsolutePath().toString());
122125
});
126+
closestClass.ifPresent(path -> {
127+
clasFiles.remove(path);
128+
files.setClassFile(path.toAbsolutePath().toString());
129+
});
123130
closestGmt.ifPresent(path -> {
124131
gmtFiles.remove(path);
125132
files.setGMTFileName(path.toAbsolutePath().toString());
@@ -169,64 +176,69 @@ public static Type guessType(Path path) {
169176
return Type.IGNORE;
170177
}
171178
if(Files.isDirectory(path)) {
172-
if(GSEAResolver.isGSEAResultsFolder(path)) {
173-
return Type.GSEA_FOLDER;
174-
} else {
179+
// if(GSEAResolver.isGSEAResultsFolder(path)) {
180+
// return Type.GSEA_FOLDER;
181+
// } else {
175182
return Type.IGNORE;
176-
}
177-
}
178-
179-
Optional<String> firstLine = getFirstDataLine(path);
180-
if(!(firstLine.isPresent() && isTabSeparated(firstLine.get()))) {
181-
return Type.IGNORE;
183+
// }
182184
}
183185

184-
return guess(path, firstLine.get());
186+
return guess(path);
185187
}
186188

187189

188-
private static Type guess(Path path, String firstLine) {
190+
private static Type guess(Path path) {
189191
Map<Type,Integer> scores = new EnumMap<>(Type.class);
190192

191-
// Guess based on extension and/or first line of file
192-
if(hasExtension(path, "gct")) {
193-
addScore(scores, Type.RANKS, 1);
194-
}
195-
if(hasExtension(path, "gmt")) {
196-
addScore(scores, Type.GENE_SETS, 1);
197-
}
198-
if(hasExtension(path, "rnk")) {
199-
addScore(scores, Type.RANKS, 1);
200-
addScore(scores, Type.EXPRESSION, 1);
201-
}
202-
if(hasExtension(path, "xls", "bgo", "tsv", "txt")) {
203-
Type type = guessEnrichmentType(path);
204-
if(type == Type.IGNORE) {
205-
addScore(scores, Type.ENRICHMENT_GENERIC, 1);
193+
String fileName = path.getFileName().toString();
194+
Optional<String> firstLine = getFirstDataLine(path);
195+
196+
if(firstLine.isPresent() && isTabSeparated(firstLine.get())) {
197+
// Guess based on extension and/or first line of file
198+
if(hasExtension(path, "gct")) {
199+
addScore(scores, Type.RANKS, 1);
200+
}
201+
if(hasExtension(path, "gmt")) {
202+
addScore(scores, Type.GENE_SETS, 1);
203+
}
204+
if(hasExtension(path, "rnk")) {
205+
addScore(scores, Type.RANKS, 1);
206206
addScore(scores, Type.EXPRESSION, 1);
207-
} else {
208-
addScore(scores, type, 2); // this is a lot of evidence
207+
}
208+
if(hasExtension(path, "xls", "bgo", "tsv", "txt")) {
209+
Type type = guessEnrichmentType(path);
210+
if(type == Type.IGNORE) {
211+
addScore(scores, Type.ENRICHMENT_GENERIC, 1);
212+
addScore(scores, Type.EXPRESSION, 1);
213+
} else {
214+
addScore(scores, type, 2); // this is a lot of evidence
215+
}
216+
}
217+
218+
// Test first line
219+
if(!isRankLine(firstLine.get())) {
220+
addScore(scores, Type.RANKS, -1);
221+
}
222+
if(!isExpressionLine(firstLine.get())) {
223+
addScore(scores, Type.EXPRESSION, -1);
224+
}
225+
226+
// Guess based on file name
227+
228+
if(matches(fileName, ".*expr(ession)?.*")) {
229+
addScore(scores, Type.EXPRESSION, 3);
230+
}
231+
if(matches(fileName, ".*rank.*")) {
232+
addScore(scores, Type.RANKS, 3);
209233
}
210234
}
211235

212-
// Test first line
213-
if(!isRankLine(firstLine)) {
214-
addScore(scores, Type.RANKS, -1);
215-
}
216-
if(!isExpressionLine(firstLine)) {
217-
addScore(scores, Type.EXPRESSION, -1);
236+
// class files are not tab separated
237+
if(matches(fileName, ".*class.*")) {
238+
addScore(scores, Type.CLASS, 3);
218239
}
219240

220-
// Guess based on file name
221-
String fileName = path.getFileName().toString();
222-
if(matches(fileName, ".*expr(ession)?.*")) {
223-
addScore(scores, Type.EXPRESSION, 3);
224-
}
225-
if(matches(fileName, ".*rank.*")) {
226-
addScore(scores, Type.RANKS, 3);
227-
}
228241
// Not adding score here for enrichment files because guessEnrichmentType should be enough evidence
229-
230242
Set<Type> possibleTypes = typesWithHighestScore(scores);
231243

232244
if(possibleTypes.isEmpty()) {

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/resolver/ResolverTask.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ public void run(TaskMonitor taskMonitor) throws Exception {
3333
taskMonitor.setTitle("EnrichmentMap");
3434
taskMonitor.setStatusMessage("Scanning Folder for Data Sets");
3535

36+
if(folders.size() == 1) {
37+
Path path = folders.get(0);
38+
if(Files.isDirectory(path)) {
39+
for(File subdirectory : path.toFile().listFiles(File::isDirectory)) {
40+
folders.add(subdirectory.toPath());
41+
}
42+
}
43+
}
44+
3645
for(Path path : folders) {
3746
if(cancelled)
3847
break;

0 commit comments

Comments
 (0)