|
24 | 24 | import java.util.stream.Stream;
|
25 | 25 |
|
26 | 26 | import org.apache.commons.lang3.StringUtils;
|
| 27 | +import org.apache.commons.lang3.tuple.Pair; |
27 | 28 | import org.baderlab.csplugins.enrichmentmap.model.DataSetFiles;
|
28 | 29 | import org.baderlab.csplugins.enrichmentmap.model.DataSetParameters;
|
29 | 30 | import org.baderlab.csplugins.enrichmentmap.model.EMDataSet.Method;
|
30 | 31 |
|
| 32 | +import com.google.common.base.Strings; |
31 | 33 | import com.google.common.collect.ImmutableList;
|
32 | 34 |
|
33 | 35 | public class DataSetResolver {
|
@@ -133,6 +135,10 @@ private static List<DataSetParameters> createDataSets(Map<Type,List<Path>> types
|
133 | 135 | closestClass.ifPresent(path -> {
|
134 | 136 | clasFiles.remove(path);
|
135 | 137 | files.setClassFile(path.toAbsolutePath().toString());
|
| 138 | + getGenericPhenotypes(path).ifPresent(p -> { |
| 139 | + files.setPhenotype1(p.getLeft()); |
| 140 | + files.setPhenotype2(p.getRight()); |
| 141 | + }); |
136 | 142 | });
|
137 | 143 | closestGmt.ifPresent(path -> {
|
138 | 144 | gmtFiles.remove(path);
|
@@ -400,4 +406,25 @@ public static String getDatasetNameGeneric(Path file) {
|
400 | 406 | return name;
|
401 | 407 | }
|
402 | 408 |
|
| 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 | + |
403 | 430 | }
|
0 commit comments