Skip to content

Commit 80a9001

Browse files
committed
Resolver guesses phenotypes for generic class files.
1 parent 12fcdc2 commit 80a9001

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424
import java.util.stream.Stream;
2525

2626
import org.apache.commons.lang3.StringUtils;
27+
import org.apache.commons.lang3.tuple.Pair;
2728
import org.baderlab.csplugins.enrichmentmap.model.DataSetFiles;
2829
import org.baderlab.csplugins.enrichmentmap.model.DataSetParameters;
2930
import org.baderlab.csplugins.enrichmentmap.model.EMDataSet.Method;
3031

32+
import com.google.common.base.Strings;
3133
import com.google.common.collect.ImmutableList;
3234

3335
public class DataSetResolver {
@@ -133,6 +135,10 @@ private static List<DataSetParameters> createDataSets(Map<Type,List<Path>> types
133135
closestClass.ifPresent(path -> {
134136
clasFiles.remove(path);
135137
files.setClassFile(path.toAbsolutePath().toString());
138+
getGenericPhenotypes(path).ifPresent(p -> {
139+
files.setPhenotype1(p.getLeft());
140+
files.setPhenotype2(p.getRight());
141+
});
136142
});
137143
closestGmt.ifPresent(path -> {
138144
gmtFiles.remove(path);
@@ -400,4 +406,25 @@ public static String getDatasetNameGeneric(Path file) {
400406
return name;
401407
}
402408

409+
private static Optional<Pair<String,String>> getGenericPhenotypes(Path path) {
410+
try(Stream<String> lines = Files.lines(path)) {
411+
Optional<String> firstLine = lines.findFirst();
412+
if(firstLine.isPresent()) {
413+
String[] phenos = firstLine.get().split("\\s");
414+
if(phenos != null && phenos.length >= 2 && !Strings.isNullOrEmpty(phenos[0])) {
415+
String up = phenos[0];
416+
for(int i = 1; i < phenos.length; i++) {
417+
if(!Strings.isNullOrEmpty(phenos[i]) && !up.equals(phenos[i])) {
418+
String down = phenos[i];
419+
return Optional.of(Pair.of(up, down));
420+
}
421+
}
422+
}
423+
}
424+
return Optional.empty();
425+
} catch (IOException e) {
426+
return Optional.empty();
427+
}
428+
}
429+
403430
}

0 commit comments

Comments
 (0)