diff --git a/.gitignore b/.gitignore
index 524f096..4aae842 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,9 @@
# Compiled class file
*.class
+# Maven
+target/
+
# Log file
*.log
diff --git a/pom.xml b/pom.xml
index 61a0d73..f7417a7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,21 +29,6 @@
${junit.jupiter.version}
test
-
- commons-io
- commons-io
- 2.16.1
-
-
- commons-net
- commons-net
- 3.10.0
-
-
- com.google.guava
- guava
- 31.1-jre
-
diff --git a/src/main/java/org/monarchinitiative/gregor/mendel/Genotype.java b/src/main/java/org/monarchinitiative/gregor/mendel/Genotype.java
index 8e3fc78..0658fc5 100644
--- a/src/main/java/org/monarchinitiative/gregor/mendel/Genotype.java
+++ b/src/main/java/org/monarchinitiative/gregor/mendel/Genotype.java
@@ -1,9 +1,8 @@
package org.monarchinitiative.gregor.mendel;
-import com.google.common.collect.ImmutableList;
-
import java.util.Arrays;
import java.util.Collection;
+import java.util.List;
/**
* Representation of a genotype in an individual
@@ -133,10 +132,12 @@ private boolean hasRefCall(int[] observedCalls) {
}
/**
- * @return {@link ImmutableList} of alleles in this genotype
+ * @return {@link List} of alleles in this genotype
*/
- public ImmutableList getAlleleNumbers() {
- return Arrays.stream(alleleNumbers).boxed().collect(ImmutableList.toImmutableList());
+ public List getAlleleNumbers() {
+ return Arrays.stream(alleleNumbers)
+ .boxed()
+ .toList();
}
/**
diff --git a/src/main/java/org/monarchinitiative/gregor/mendel/GenotypeCalls.java b/src/main/java/org/monarchinitiative/gregor/mendel/GenotypeCalls.java
index 4e20155..50ecd30 100644
--- a/src/main/java/org/monarchinitiative/gregor/mendel/GenotypeCalls.java
+++ b/src/main/java/org/monarchinitiative/gregor/mendel/GenotypeCalls.java
@@ -1,9 +1,6 @@
package org.monarchinitiative.gregor.mendel;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSortedMap;
-
-import java.util.Iterator;
+import java.util.*;
import java.util.Map.Entry;
/**
@@ -20,7 +17,7 @@
*/
public final class GenotypeCalls implements Iterable> {
- private final static Genotype GT_NO_CALL = new Genotype(ImmutableList.of(Genotype.NO_CALL));
+ private final static Genotype GT_NO_CALL = new Genotype(List.of(Genotype.NO_CALL));
/**
* Type of the chromosome that the variant lies on (autosomal, X-chromosomal, etc.)
@@ -29,11 +26,11 @@ public final class GenotypeCalls implements Iterable> {
/**
* Mapping from sample name to {@link Genotype}
*/
- private final ImmutableSortedMap sampleToGenotype;
+ private final Map sampleToGenotype;
/**
* List of sample names
*/
- private final ImmutableList sampleNames;
+ private final List sampleNames;
/**
* A payload object for later easier reidentification
*/
@@ -61,8 +58,12 @@ public GenotypeCalls(ChromosomeType chromType, Iterable extends Entry> sampleToGenotype,
Object payload) {
this.chromType = chromType;
- this.sampleToGenotype = ImmutableSortedMap.copyOf(sampleToGenotype);
- this.sampleNames = ImmutableList.copyOf(this.sampleToGenotype.keySet());
+
+ this.sampleToGenotype = new TreeMap<>();
+ for (Entry entry : sampleToGenotype){
+ this.sampleToGenotype.put(entry.getKey(), entry.getValue());
+ }
+ this.sampleNames = List.copyOf(this.sampleToGenotype.keySet());
this.payload = payload;
}
@@ -105,14 +106,14 @@ public ChromosomeType getChromType() {
/**
* @return Sample to genotype map
*/
- public ImmutableSortedMap getSampleToGenotype() {
- return sampleToGenotype;
+ public Map getSampleToGenotype() {
+ return Collections.unmodifiableMap(sampleToGenotype);
}
/**
* @return Sample names
*/
- public ImmutableList getSampleNames() {
+ public List getSampleNames() {
return sampleNames;
}
diff --git a/src/main/java/org/monarchinitiative/gregor/mendel/IncompatiblePedigreeException.java b/src/main/java/org/monarchinitiative/gregor/mendel/IncompatiblePedigreeException.java
index 2985203..e2211db 100644
--- a/src/main/java/org/monarchinitiative/gregor/mendel/IncompatiblePedigreeException.java
+++ b/src/main/java/org/monarchinitiative/gregor/mendel/IncompatiblePedigreeException.java
@@ -1,8 +1,5 @@
package org.monarchinitiative.gregor.mendel;
-
-import java.io.Serial;
-
/**
* Thrown when the pedigree does not fit to the {@link GenotypeCalls}
*
diff --git a/src/main/java/org/monarchinitiative/gregor/mendel/MendelianInheritanceChecker.java b/src/main/java/org/monarchinitiative/gregor/mendel/MendelianInheritanceChecker.java
index 1bfedbe..19b7c27 100644
--- a/src/main/java/org/monarchinitiative/gregor/mendel/MendelianInheritanceChecker.java
+++ b/src/main/java/org/monarchinitiative/gregor/mendel/MendelianInheritanceChecker.java
@@ -1,14 +1,10 @@
package org.monarchinitiative.gregor.mendel;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
import org.monarchinitiative.gregor.mendel.impl.*;
import org.monarchinitiative.gregor.pedigree.Pedigree;
import org.monarchinitiative.gregor.pedigree.PedigreeQueryDecorator;
-import java.util.Collection;
-import java.util.Map;
+import java.util.*;
/**
* Facade class for checking lists of {@link GenotypeCalls} for compatibility with mendelian inheritance
@@ -28,7 +24,7 @@ public final class MendelianInheritanceChecker {
/**
* Mendelian compatibility checker for each sub mode of inheritance
*/
- final private ImmutableMap checkers;
+ final private Map checkers;
/**
* Construct checker with the pedigree to use
@@ -39,15 +35,15 @@ public MendelianInheritanceChecker(Pedigree pedigree) {
this.pedigree = pedigree;
this.queryPed = new PedigreeQueryDecorator(pedigree);
- ImmutableMap.Builder builder = new ImmutableMap.Builder<>();
- builder.put(SubModeOfInheritance.AUTOSOMAL_DOMINANT, new MendelianCheckerAD(this));
- builder.put(SubModeOfInheritance.AUTOSOMAL_RECESSIVE_COMP_HET, new MendelianCheckerARCompoundHet(this));
- builder.put(SubModeOfInheritance.AUTOSOMAL_RECESSIVE_HOM_ALT, new MendelianCheckerARHom(this));
- builder.put(SubModeOfInheritance.X_DOMINANT, new MendelianCheckerXD(this));
- builder.put(SubModeOfInheritance.X_RECESSIVE_COMP_HET, new MendelianCheckerXRCompoundHet(this));
- builder.put(SubModeOfInheritance.X_RECESSIVE_HOM_ALT, new MendelianCheckerXRHom(this));
- builder.put(SubModeOfInheritance.MITOCHONDRIAL, new InheritanceCheckerMT(this));
- this.checkers = builder.build();
+ Map map = new LinkedHashMap<>();
+ map.put(SubModeOfInheritance.AUTOSOMAL_DOMINANT, new MendelianCheckerAD(this));
+ map.put(SubModeOfInheritance.AUTOSOMAL_RECESSIVE_COMP_HET, new MendelianCheckerARCompoundHet(this));
+ map.put(SubModeOfInheritance.AUTOSOMAL_RECESSIVE_HOM_ALT, new MendelianCheckerARHom(this));
+ map.put(SubModeOfInheritance.X_DOMINANT, new MendelianCheckerXD(this));
+ map.put(SubModeOfInheritance.X_RECESSIVE_COMP_HET, new MendelianCheckerXRCompoundHet(this));
+ map.put(SubModeOfInheritance.X_RECESSIVE_HOM_ALT, new MendelianCheckerXRHom(this));
+ map.put(SubModeOfInheritance.MITOCHONDRIAL, new InheritanceCheckerMT(this));
+ this.checkers = map;
}
/**
@@ -61,26 +57,26 @@ public MendelianInheritanceChecker(Pedigree pedigree) {
* {@link GenotypeCalls} from list
* @throws IncompatiblePedigreeException if the individuals in calls do not fit to the pedigree
*/
- public ImmutableMap> checkMendelianInheritance(
+ public Map> checkMendelianInheritance(
Collection calls, Collection recessiveCalls) throws IncompatiblePedigreeException {
- ImmutableMap.Builder> builder = new ImmutableMap.Builder<>();
+ Map> map = new LinkedHashMap<>();
for (ModeOfInheritance mode : ModeOfInheritance.values()) {
if (mode == ModeOfInheritance.ANY) {
- builder.put(mode, ImmutableList.copyOf(calls));
+ map.put(mode, List.copyOf(calls));
} else {
if (mode == ModeOfInheritance.AUTOSOMAL_RECESSIVE || mode == ModeOfInheritance.X_RECESSIVE) {
- builder.put(mode, filterCompatibleRecords(recessiveCalls, mode));
+ map.put(mode, filterCompatibleRecords(recessiveCalls, mode));
} else {
- builder.put(mode, filterCompatibleRecords(calls, mode));
+ map.put(mode, filterCompatibleRecords(calls, mode));
}
}
}
- return builder.build();
+ return map;
}
- public ImmutableMap> checkMendelianInheritance(
+ public Map> checkMendelianInheritance(
Collection calls) throws IncompatiblePedigreeException {
- return checkMendelianInheritance(calls, calls);
+ return Collections.unmodifiableMap(checkMendelianInheritance(calls, calls));
}
@@ -94,26 +90,26 @@ public ImmutableMap> checkMendel
* {@link GenotypeCalls} from list
* @throws IncompatiblePedigreeException if the individuals in calls do not fit to the pedigree
*/
- public ImmutableMap> checkMendelianInheritanceSub(
+ public Map> checkMendelianInheritanceSub(
Collection calls, Collection compHetRecessiveCalls) throws IncompatiblePedigreeException {
- ImmutableMap.Builder> builder = new ImmutableMap.Builder<>();
+ Map> map = new LinkedHashMap<>();
for (SubModeOfInheritance mode : SubModeOfInheritance.values()) {
if (mode == SubModeOfInheritance.ANY) {
- builder.put(mode, ImmutableList.copyOf(calls));
+ map.put(mode, List.copyOf(calls));
} else {
if (mode == SubModeOfInheritance.AUTOSOMAL_RECESSIVE_COMP_HET || mode == SubModeOfInheritance.X_RECESSIVE_COMP_HET) {
- builder.put(mode, filterCompatibleRecordsSub(compHetRecessiveCalls, mode));
+ map.put(mode, filterCompatibleRecordsSub(compHetRecessiveCalls, mode));
} else {
- builder.put(mode, filterCompatibleRecordsSub(calls, mode));
+ map.put(mode, filterCompatibleRecordsSub(calls, mode));
}
}
}
- return builder.build();
+ return map;
}
- public ImmutableMap> checkMendelianInheritanceSub(
+ public Map> checkMendelianInheritanceSub(
Collection calls) throws IncompatiblePedigreeException {
- return checkMendelianInheritanceSub(calls, calls);
+ return Collections.unmodifiableMap(checkMendelianInheritanceSub(calls, calls));
}
/**
@@ -124,45 +120,41 @@ public ImmutableMap> checkMen
* @return List of {@link GenotypeCalls} from calls that are compatible with mode
* @throws IncompatiblePedigreeException if the individuals in calls do not fit to the pedigree
*/
- public ImmutableList filterCompatibleRecords(Collection calls, ModeOfInheritance mode)
+ public List filterCompatibleRecords(Collection calls, ModeOfInheritance mode)
throws IncompatiblePedigreeException {
// Check for compatibility of calls with pedigree
if (!calls.stream().allMatch(c -> isCompatibleWithPedigree(c)))
throw new IncompatiblePedigreeException("GenotypeCalls not compatible with pedigree");
// Filter down to the compatible records
- ImmutableSet calls1;
- ImmutableSet calls2;
- ImmutableList.Builder builder;
+ Set calls1;
+ Set calls2;
+ List result;
switch (mode) {
case AUTOSOMAL_DOMINANT:
- return checkers.get(SubModeOfInheritance.AUTOSOMAL_DOMINANT).filterCompatibleRecords(calls);
+ return Collections.unmodifiableList(checkers.get(SubModeOfInheritance.AUTOSOMAL_DOMINANT).filterCompatibleRecords(calls));
case AUTOSOMAL_RECESSIVE:
- calls1 = ImmutableSet.copyOf(
- checkers.get(SubModeOfInheritance.AUTOSOMAL_RECESSIVE_HOM_ALT).filterCompatibleRecords(calls));
- calls2 = ImmutableSet.copyOf(
- checkers.get(SubModeOfInheritance.AUTOSOMAL_RECESSIVE_COMP_HET).filterCompatibleRecords(calls));
- builder = new ImmutableList.Builder<>();
+ calls1 = new HashSet<>(checkers.get(SubModeOfInheritance.AUTOSOMAL_RECESSIVE_HOM_ALT).filterCompatibleRecords(calls));
+ calls2 = new HashSet<>(checkers.get(SubModeOfInheritance.AUTOSOMAL_RECESSIVE_COMP_HET).filterCompatibleRecords(calls));
+ result = new ArrayList<>();
for (GenotypeCalls c : calls)
if (calls1.contains(c) || calls2.contains(c))
- builder.add(c);
- return builder.build();
+ result.add(c);
+ return Collections.unmodifiableList(result);
case X_DOMINANT:
- return checkers.get(SubModeOfInheritance.X_DOMINANT).filterCompatibleRecords(calls);
+ return Collections.unmodifiableList(checkers.get(SubModeOfInheritance.X_DOMINANT).filterCompatibleRecords(calls));
case X_RECESSIVE:
- calls1 = ImmutableSet
- .copyOf(checkers.get(SubModeOfInheritance.X_RECESSIVE_HOM_ALT).filterCompatibleRecords(calls));
- calls2 = ImmutableSet
- .copyOf(checkers.get(SubModeOfInheritance.X_RECESSIVE_COMP_HET).filterCompatibleRecords(calls));
- builder = new ImmutableList.Builder<>();
+ calls1 = new HashSet<>(checkers.get(SubModeOfInheritance.X_RECESSIVE_HOM_ALT).filterCompatibleRecords(calls));
+ calls2 = new HashSet<>(checkers.get(SubModeOfInheritance.X_RECESSIVE_COMP_HET).filterCompatibleRecords(calls));
+ result = new ArrayList<>();
for (GenotypeCalls c : calls)
if (calls1.contains(c) || calls2.contains(c))
- builder.add(c);
- return builder.build();
+ result.add(c);
+ return Collections.unmodifiableList(result);
case MITOCHONDRIAL:
- return checkers.get(SubModeOfInheritance.MITOCHONDRIAL).filterCompatibleRecords(calls);
+ return Collections.unmodifiableList(checkers.get(SubModeOfInheritance.MITOCHONDRIAL).filterCompatibleRecords(calls));
default:
case ANY:
- return ImmutableList.copyOf(calls);
+ return List.copyOf(calls);
}
}
@@ -174,14 +166,14 @@ public ImmutableList filterCompatibleRecords(Collectioncalls that are compatible with mode
* @throws IncompatiblePedigreeException if the individuals in calls do not fit to the pedigree
*/
- public ImmutableList filterCompatibleRecordsSub(Collection calls,
+ public List filterCompatibleRecordsSub(Collection calls,
SubModeOfInheritance subMode) throws IncompatiblePedigreeException {
// Check for compatibility of calls with pedigree
if (!calls.stream().allMatch(c -> isCompatibleWithPedigree(c)))
throw new IncompatiblePedigreeException("GenotypeCalls not compatible with pedigree");
// Filter down to the compatible records
if (subMode == SubModeOfInheritance.ANY)
- return ImmutableList.copyOf(calls);
+ return List.copyOf(calls);
else
return checkers.get(subMode).filterCompatibleRecords(calls);
}
diff --git a/src/main/java/org/monarchinitiative/gregor/mendel/impl/AbstractMendelianChecker.java b/src/main/java/org/monarchinitiative/gregor/mendel/impl/AbstractMendelianChecker.java
index 0d305d9..978600f 100644
--- a/src/main/java/org/monarchinitiative/gregor/mendel/impl/AbstractMendelianChecker.java
+++ b/src/main/java/org/monarchinitiative/gregor/mendel/impl/AbstractMendelianChecker.java
@@ -1,6 +1,5 @@
package org.monarchinitiative.gregor.mendel.impl;
-import com.google.common.collect.ImmutableList;
import org.monarchinitiative.gregor.mendel.GenotypeCalls;
import org.monarchinitiative.gregor.mendel.IncompatiblePedigreeException;
import org.monarchinitiative.gregor.mendel.MendelianInheritanceChecker;
@@ -8,6 +7,7 @@
import org.monarchinitiative.gregor.pedigree.PedigreeQueryDecorator;
import java.util.Collection;
+import java.util.List;
// TODO: check compatibility of pedigree with GenotypeCalls
@@ -41,10 +41,10 @@ public AbstractMendelianChecker(MendelianInheritanceChecker parent) {
* Filter list of {@link GenotypeCalls} for fitting to mode
*
* @param calls The list of calls to check for compatibility
- * @return Filtered {@link ImmutableList} of {@link GenotypeCalls} objects, subset of calls
+ * @return Filtered {@link List} of {@link GenotypeCalls} objects, subset of calls
* @throws IncompatiblePedigreeException if calls is incompatible with the pedigree
*/
- public abstract ImmutableList filterCompatibleRecords(Collection calls)
+ public abstract List filterCompatibleRecords(Collection calls)
throws IncompatiblePedigreeException;
}
diff --git a/src/main/java/org/monarchinitiative/gregor/mendel/impl/InheritanceCheckerMT.java b/src/main/java/org/monarchinitiative/gregor/mendel/impl/InheritanceCheckerMT.java
index 3eed5e1..1e46c07 100644
--- a/src/main/java/org/monarchinitiative/gregor/mendel/impl/InheritanceCheckerMT.java
+++ b/src/main/java/org/monarchinitiative/gregor/mendel/impl/InheritanceCheckerMT.java
@@ -1,13 +1,12 @@
package org.monarchinitiative.gregor.mendel.impl;
-import com.google.common.collect.ImmutableList;
import org.monarchinitiative.gregor.mendel.*;
import org.monarchinitiative.gregor.pedigree.Disease;
import org.monarchinitiative.gregor.pedigree.Pedigree;
import org.monarchinitiative.gregor.pedigree.Person;
import java.util.Collection;
-import java.util.stream.Collectors;
+import java.util.List;
import java.util.stream.Stream;
/**
@@ -40,7 +39,7 @@ public InheritanceCheckerMT(MendelianInheritanceChecker parent) {
}
@Override
- public ImmutableList filterCompatibleRecords(Collection calls)
+ public List filterCompatibleRecords(Collection calls)
throws IncompatiblePedigreeException {
// Filter to calls on the mitochondrion
@@ -53,8 +52,7 @@ public ImmutableList filterCompatibleRecords(Collection filterCompatibleRecords(Collection calls) {
+ public List filterCompatibleRecords(Collection calls) {
// Filter to calls on autosomal chromosomes
Stream autosomalCalls = calls.stream()
.filter(call -> call.getChromType() == ChromosomeType.AUTOSOMAL);
@@ -42,7 +41,7 @@ public ImmutableList filterCompatibleRecords(Collection filterCompatibleRecords(Collection calls)
+ public List filterCompatibleRecords(Collection calls)
throws IncompatiblePedigreeException {
// Apply homozygous and compound heterozygous checker, then select distinct records
Stream joint = Stream.concat(checkerCompound.filterCompatibleRecords(calls).stream(),
checkerHom.filterCompatibleRecords(calls).stream());
- HashSet set = new HashSet<>();
- set.addAll(joint.collect(Collectors.toList()));
- return ImmutableList.copyOf(set);
+ return joint.distinct().toList();
}
}
diff --git a/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerARCompoundHet.java b/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerARCompoundHet.java
index 40226c8..946bd5b 100644
--- a/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerARCompoundHet.java
+++ b/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerARCompoundHet.java
@@ -1,7 +1,5 @@
package org.monarchinitiative.gregor.mendel.impl;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
import org.monarchinitiative.gregor.mendel.*;
import org.monarchinitiative.gregor.pedigree.Disease;
import org.monarchinitiative.gregor.pedigree.Pedigree;
@@ -9,6 +7,7 @@
import java.util.*;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
// TODO: also return no-call/not-observed variant
@@ -29,7 +28,7 @@ public class MendelianCheckerARCompoundHet extends AbstractMendelianChecker {
/**
* list of siblings for each person in {@link #pedigree}
*/
- private final ImmutableMap> siblings;
+ private final Map> siblings;
public MendelianCheckerARCompoundHet(MendelianInheritanceChecker parent) {
super(parent);
@@ -42,35 +41,34 @@ public MendelianCheckerARCompoundHet(MendelianInheritanceChecker parent) {
* @return Genotypes for all variants that are compatible with autosomal recessive compound heterozygous inheritance.
*/
@Override
- public ImmutableList filterCompatibleRecords(Collection calls)
+ public List filterCompatibleRecords(Collection calls)
throws IncompatiblePedigreeException {
List autosomalCalls = calls.stream()
- .filter(call -> call.getChromType() == ChromosomeType.AUTOSOMAL).collect(Collectors.toList());
- if (pedigree.getNMembers() == 1)
- return filterCompatibleRecordsSingleSample(autosomalCalls);
- else
- return filterCompatibleRecordsMultiSample(autosomalCalls);
+ .filter(call -> call.getChromType() == ChromosomeType.AUTOSOMAL)
+ .collect(Collectors.toList());
+ return pedigree.getNMembers() == 1 ?
+ filterCompatibleRecordsSingleSample(autosomalCalls) :
+ filterCompatibleRecordsMultiSample(autosomalCalls);
}
/**
* In the single sample case, if we find two or more heterozygous variants, then there is compatibility with
* autosomal recessive compound heterozygous inheritance.
*/
- ImmutableList filterCompatibleRecordsSingleSample(Collection calls) {
- ImmutableList.Builder builder = new ImmutableList.Builder<>();
+ List filterCompatibleRecordsSingleSample(Collection calls) {
+ List builder = new ArrayList<>();
for (GenotypeCalls gc : calls) {
if (gc.getGenotypeBySampleNo(0).isHet())
builder.add(gc);
}
- ImmutableList result = builder.build();
- if (result.size() > 1)
- return result;
+ if (builder.size() > 1)
+ return builder;
else
- return ImmutableList.of();
+ return List.of();
}
- private ImmutableList filterCompatibleRecordsMultiSample(Collection calls) {
+ private List filterCompatibleRecordsMultiSample(Collection calls) {
// First, collect candidate genotype call lists from trios around affected individuals
ArrayList candidates = collectTrioCandidates(calls);
@@ -85,7 +83,7 @@ private ImmutableList filterCompatibleRecordsMultiSample(Collecti
}
}
}
- return ImmutableList.copyOf(result);
+ return List.copyOf(result);
}
private boolean isCompatibleWithUnaffected(Candidate c) {
diff --git a/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerARHom.java b/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerARHom.java
index e28fc80..721a3b7 100644
--- a/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerARHom.java
+++ b/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerARHom.java
@@ -1,13 +1,15 @@
package org.monarchinitiative.gregor.mendel.impl;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
import org.monarchinitiative.gregor.mendel.*;
import org.monarchinitiative.gregor.pedigree.Disease;
import org.monarchinitiative.gregor.pedigree.Pedigree;
import org.monarchinitiative.gregor.pedigree.Person;
import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -35,18 +37,15 @@ public MendelianCheckerARHom(MendelianInheritanceChecker parent) {
}
@Override
- public ImmutableList filterCompatibleRecords(Collection calls)
- throws IncompatiblePedigreeException {
- // Filter to calls on autosomal chromosomes
- Stream autosomalCalls = calls.stream()
- .filter(call -> call.getChromType() == ChromosomeType.AUTOSOMAL);
- // Filter to calls compatible with AD inheritance
- Stream compatibleCalls;
- if (this.pedigree.getNMembers() == 1)
- compatibleCalls = autosomalCalls.filter(this::isCompatibleSingleton);
- else
- compatibleCalls = autosomalCalls.filter(this::isCompatibleFamily);
- return ImmutableList.copyOf(compatibleCalls.collect(Collectors.toList()));
+ public List filterCompatibleRecords(Collection calls) throws IncompatiblePedigreeException{
+ // Determine compatibility checking method based on the number of pedigree members
+ Predicate compatibilityChecker = (this.pedigree.getNMembers() == 1) ?
+ this::isCompatibleSingleton : this::isCompatibleFamily;
+ // Stream the calls, filter by chromosome type and compatibility
+ return calls.stream()
+ .filter(call -> call.getChromType() == ChromosomeType.AUTOSOMAL)
+ .filter(compatibilityChecker)
+ .toList();
}
/**
@@ -96,18 +95,18 @@ private boolean unaffectedParentsOfAffectedAreNotHomozygous(GenotypeCalls calls)
/**
* @return names of unaffected parents of unaffecteds
*/
- private ImmutableSet getUnaffectedParentNamesOfAffecteds() {
- ImmutableSet.Builder builder = new ImmutableSet.Builder();
+ private Set getUnaffectedParentNamesOfAffecteds() {
+ Set set = new HashSet<>();
for (Person person : pedigree.getMembers())
if (person.getDisease() == Disease.AFFECTED) {
if (person.getFather() != null && person.getFather().getDisease() == Disease.UNAFFECTED)
- builder.add(person.getFather().getName());
+ set.add(person.getFather().getName());
if (person.getMother() != null && person.getMother().getDisease() == Disease.UNAFFECTED)
- builder.add(person.getMother().getName());
+ set.add(person.getMother().getName());
}
- return builder.build();
+ return set;
}
private boolean unaffectedsAreNotHomozygousAlt(GenotypeCalls calls) {
diff --git a/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerXD.java b/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerXD.java
index 9900b3d..0dfd591 100644
--- a/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerXD.java
+++ b/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerXD.java
@@ -1,6 +1,5 @@
package org.monarchinitiative.gregor.mendel.impl;
-import com.google.common.collect.ImmutableList;
import org.monarchinitiative.gregor.mendel.ChromosomeType;
import org.monarchinitiative.gregor.mendel.Genotype;
import org.monarchinitiative.gregor.mendel.GenotypeCalls;
@@ -10,8 +9,8 @@
import org.monarchinitiative.gregor.pedigree.Sex;
import java.util.Collection;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
+import java.util.List;
+import java.util.function.Predicate;
/**
* Implementation of Mendelian compatibility check for autosomal dominant case
@@ -31,17 +30,15 @@ public MendelianCheckerXD(MendelianInheritanceChecker parent) {
}
@Override
- public ImmutableList filterCompatibleRecords(Collection calls) {
- // Filter to calls on X chromosomes
- Stream xCalls = calls.stream()
- .filter(call -> call.getChromType() == ChromosomeType.X_CHROMOSOMAL);
- // Filter to calls compatible with AD inheritance
- Stream compatibleCalls;
- if (this.pedigree.getNMembers() == 1)
- compatibleCalls = xCalls.filter(this::isCompatibleSingleton);
- else
- compatibleCalls = xCalls.filter(this::isCompatibleFamily);
- return ImmutableList.copyOf(compatibleCalls.collect(Collectors.toList()));
+ public List filterCompatibleRecords(Collection calls) {
+ // Determine compatibility checking method based on the number of pedigree members
+ Predicate compatibilityChecker = (this.pedigree.getNMembers() == 1) ?
+ this::isCompatibleSingleton : this::isCompatibleFamily;
+ // Stream the calls, filter by chromosome type and compatibility
+ return calls.stream()
+ .filter(call -> call.getChromType() == ChromosomeType.X_CHROMOSOMAL)
+ .filter(compatibilityChecker)
+ .toList();
}
/**
diff --git a/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerXR.java b/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerXR.java
index 9b8be6a..d7ca636 100644
--- a/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerXR.java
+++ b/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerXR.java
@@ -1,13 +1,11 @@
package org.monarchinitiative.gregor.mendel.impl;
-import com.google.common.collect.ImmutableList;
import org.monarchinitiative.gregor.mendel.GenotypeCalls;
import org.monarchinitiative.gregor.mendel.IncompatiblePedigreeException;
import org.monarchinitiative.gregor.mendel.MendelianInheritanceChecker;
import java.util.Collection;
-import java.util.HashSet;
-import java.util.stream.Collectors;
+import java.util.List;
import java.util.stream.Stream;
/**
@@ -34,14 +32,12 @@ public MendelianCheckerXR(MendelianInheritanceChecker parent) {
}
@Override
- public ImmutableList filterCompatibleRecords(Collection calls)
+ public List filterCompatibleRecords(Collection calls)
throws IncompatiblePedigreeException {
// Apply homozygous and compound heterozygous checker, then select distinct records
Stream joint = Stream.concat(checkerCompound.filterCompatibleRecords(calls).stream(),
checkerHom.filterCompatibleRecords(calls).stream());
- HashSet set = new HashSet<>();
- set.addAll(joint.collect(Collectors.toList()));
- return ImmutableList.copyOf(set);
+ return joint.distinct().toList();
}
}
diff --git a/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerXRCompoundHet.java b/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerXRCompoundHet.java
index d5ed491..474f6a6 100644
--- a/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerXRCompoundHet.java
+++ b/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerXRCompoundHet.java
@@ -1,7 +1,5 @@
package org.monarchinitiative.gregor.mendel.impl;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
import org.monarchinitiative.gregor.mendel.*;
import org.monarchinitiative.gregor.pedigree.Disease;
import org.monarchinitiative.gregor.pedigree.Pedigree;
@@ -37,7 +35,7 @@ public class MendelianCheckerXRCompoundHet extends AbstractMendelianChecker {
/**
* list of siblings for each person in {@link #pedigree}
*/
- private final ImmutableMap> siblings;
+ private final Map> siblings;
public MendelianCheckerXRCompoundHet(MendelianInheritanceChecker parent) {
super(parent);
@@ -46,7 +44,7 @@ public MendelianCheckerXRCompoundHet(MendelianInheritanceChecker parent) {
}
@Override
- public ImmutableList filterCompatibleRecords(Collection calls)
+ public List filterCompatibleRecords(Collection calls)
throws IncompatiblePedigreeException {
List xCalls = calls.stream().filter(call -> call.getChromType() == ChromosomeType.X_CHROMOSOMAL)
.collect(Collectors.toList());
@@ -57,14 +55,14 @@ public ImmutableList filterCompatibleRecords(Collection filterCompatibleRecordsSingleSample(Collection calls) {
+ private List filterCompatibleRecordsSingleSample(Collection calls) {
if (pedigree.getMembers().get(0).getSex() == Sex.MALE)
- return ImmutableList.of();
+ return List.of();
else
return new MendelianCheckerARCompoundHet(parent).filterCompatibleRecordsSingleSample(calls);
}
- private ImmutableList filterCompatibleRecordsMultiSample(Collection calls) {
+ private List filterCompatibleRecordsMultiSample(Collection calls) {
List autosomalCalls = calls.stream()
.filter(call -> call.getChromType() == ChromosomeType.AUTOSOMAL).collect(Collectors.toList());
@@ -82,7 +80,7 @@ private ImmutableList filterCompatibleRecordsMultiSample(Collecti
}
}
}
- return ImmutableList.copyOf(result);
+ return List.copyOf(result);
}
private ArrayList collectTrioCandidates(Collection calls) {
diff --git a/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerXRHom.java b/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerXRHom.java
index 393c864..27f65e2 100644
--- a/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerXRHom.java
+++ b/src/main/java/org/monarchinitiative/gregor/mendel/impl/MendelianCheckerXRHom.java
@@ -1,7 +1,5 @@
package org.monarchinitiative.gregor.mendel.impl;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
import org.monarchinitiative.gregor.mendel.*;
import org.monarchinitiative.gregor.pedigree.Disease;
import org.monarchinitiative.gregor.pedigree.Pedigree;
@@ -9,8 +7,10 @@
import org.monarchinitiative.gregor.pedigree.Sex;
import java.util.Collection;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.function.Predicate;
/**
* Helper class for checking a {@link GenotypeCalls} for compatibility with a
@@ -38,19 +38,16 @@ public MendelianCheckerXRHom(MendelianInheritanceChecker parent) {
}
@Override
- public ImmutableList filterCompatibleRecords(Collection calls)
+ public List filterCompatibleRecords(Collection calls)
throws IncompatiblePedigreeException {
- // Filter to calls on X chromosome
- Stream xCalls = calls.stream()
- .filter(call -> call.getChromType() == ChromosomeType.X_CHROMOSOMAL);
-
- // Filter to calls compatible with AD inheritance
- Stream compatibleCalls;
- if (this.pedigree.getNMembers() == 1)
- compatibleCalls = xCalls.filter(this::isCompatibleSingleton);
- else
- compatibleCalls = xCalls.filter(this::isCompatibleFamily);
- return ImmutableList.copyOf(compatibleCalls.collect(Collectors.toList()));
+ // Determine compatibility checking method based on the number of pedigree members
+ Predicate compatibilityChecker = (this.pedigree.getNMembers() == 1) ?
+ this::isCompatibleSingleton : this::isCompatibleFamily;
+ // Stream the calls, filter by chromosome type and compatibility
+ return calls.stream()
+ .filter(call -> call.getChromType() == ChromosomeType.X_CHROMOSOMAL)
+ .filter(compatibilityChecker)
+ .toList();
}
/**
@@ -114,7 +111,7 @@ private boolean affectedsAreCompatible(GenotypeCalls calls) {
* @return
*/
private boolean parentsAreCompatible(GenotypeCalls calls) {
- final ImmutableSet femaleParentNames = queryDecorator.getAffectedFemaleParentNames();
+ Set femaleParentNames = Collections.unmodifiableSet(queryDecorator.getAffectedFemaleParentNames());
for (Person p : pedigree.getMembers()) {
final Genotype gt = calls.getGenotypeForSample(p.getName());
@@ -135,7 +132,7 @@ private boolean parentsAreCompatible(GenotypeCalls calls) {
}
private boolean unaffectedsAreCompatible(GenotypeCalls calls) {
- final ImmutableSet unaffectedNames = queryDecorator.getUnaffectedNames();
+ Set unaffectedNames = Collections.unmodifiableSet(queryDecorator.getUnaffectedNames());
for (Person p : pedigree.getMembers()) {
if (unaffectedNames.contains(p.getName())) {
diff --git a/src/main/java/org/monarchinitiative/gregor/pedigree/PedFileContents.java b/src/main/java/org/monarchinitiative/gregor/pedigree/PedFileContents.java
index b8df7e6..8b7cdab 100644
--- a/src/main/java/org/monarchinitiative/gregor/pedigree/PedFileContents.java
+++ b/src/main/java/org/monarchinitiative/gregor/pedigree/PedFileContents.java
@@ -1,7 +1,9 @@
package org.monarchinitiative.gregor.pedigree;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
/**
* Represents the contents of a pedigree file.
@@ -13,46 +15,47 @@ public class PedFileContents {
/**
* headers for extra columns (column 7 and beyond)
*/
- private final ImmutableList extraColumnHeaders;
+ private final List extraColumnHeaders;
/**
* the individuals in the PED file
*/
- private final ImmutableList individuals;
+ private final List individuals;
/**
* mapping of name to PedPerson
*/
- private final ImmutableMap nameToPerson; // TODO(holtgrew): Test this!
+ private final Map nameToPerson; // TODO(holtgrew): Test this!
- public PedFileContents(ImmutableList extraColumnHeaders, ImmutableList individuals) {
+ public PedFileContents(List extraColumnHeaders, List individuals) {
this.extraColumnHeaders = extraColumnHeaders;
this.individuals = individuals;
- ImmutableMap.Builder builder = new ImmutableMap.Builder();
+ Map map = new LinkedHashMap<>();
for (PedPerson p : individuals)
- builder.put(p.getName(), p);
- this.nameToPerson = builder.build();
+ map.put(p.getName(), p);
+ this.nameToPerson = Collections.unmodifiableMap(map);
}
+
/**
* @return headers for extra columns (column 7 and beyond)
*/
- public ImmutableList getExtraColumnHeaders() {
- return extraColumnHeaders;
+ public List getExtraColumnHeaders() {
+ return Collections.unmodifiableList(extraColumnHeaders);
}
/**
* @return the individuals in the PED file
*/
- public ImmutableList getIndividuals() {
- return individuals;
+ public List getIndividuals() {
+ return Collections.unmodifiableList(individuals);
}
/**
* @return mapping of name to PedPerson
*/
- public ImmutableMap getNameToPerson() {
+ public Map getNameToPerson() {
return nameToPerson;
}
diff --git a/src/main/java/org/monarchinitiative/gregor/pedigree/PedFileReader.java b/src/main/java/org/monarchinitiative/gregor/pedigree/PedFileReader.java
index bdd8ae8..9c4e332 100644
--- a/src/main/java/org/monarchinitiative/gregor/pedigree/PedFileReader.java
+++ b/src/main/java/org/monarchinitiative/gregor/pedigree/PedFileReader.java
@@ -1,11 +1,8 @@
package org.monarchinitiative.gregor.pedigree;
-import com.google.common.base.Splitter;
-import com.google.common.collect.ImmutableList;
-
import java.io.*;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
+import java.util.*;
+import java.util.stream.Collectors;
// TODO(holtgrem): Test me!
@@ -51,7 +48,7 @@ public static PedFileContents read(InputStream stream) throws IOException, PedPa
BufferedReader in = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
// Parse header.
- ImmutableList extraHeaders = ImmutableList.of(); // default to empty
+ List extraHeaders = List.of(); // default to empty
String line = in.readLine();
if (line != null && line.startsWith("#")) {
extraHeaders = parseHeader(line);
@@ -59,32 +56,28 @@ public static PedFileContents read(InputStream stream) throws IOException, PedPa
}
// Parse individuals.
- ImmutableList.Builder individualBuilder = new ImmutableList.Builder();
+ List individuals = new ArrayList();
while (line != null) {
line = line.trim(); // trim leading and trailing whitespace
if (line.length() != 0) // ignore empty lines
- individualBuilder.add(readIndividual(line));
+ individuals.add(readIndividual(line));
line = in.readLine(); // read next
}
- return new PedFileContents(extraHeaders, individualBuilder.build());
+ return new PedFileContents(extraHeaders, Collections.unmodifiableList(individuals));
}
/**
* Parse header and return extra header fields, line must start with '#'.
*/
- private static ImmutableList parseHeader(String line) {
- ImmutableList.Builder extraHeaderBuilder = new ImmutableList.Builder();
- Iterator it = Splitter.on('\t').split(line.trim().substring(1)).iterator();
- for (int i = 0; it.hasNext(); ++i)
- if (i < 6)
- it.next();
- else
- extraHeaderBuilder.add(it.next());
- return extraHeaderBuilder.build();
+ private static List parseHeader(String line) {
+ return Arrays.stream(line.trim().substring(1).split("\t"))
+ .skip(6)
+ .collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));
}
+
/**
* Parse individual from the given line.
*
@@ -92,23 +85,22 @@ private static ImmutableList parseHeader(String line) {
*/
private static PedPerson readIndividual(String line) throws PedParseException {
try {
- Iterator it = Splitter.onPattern("\\s+").split(line.trim()).iterator();
+ String[] fields = line.trim().split("\\s+");
+ if (fields.length < 6) {
+ throw new PedParseException("Insufficient number of fields in line: \"" + line + "\"");
+ }
- // parse out core fields
- String pedigree = it.next();
- String name = it.next();
- String father = it.next();
- String mother = it.next();
- String sex = it.next();
- String disease = it.next();
+ String pedigree = fields[0];
+ String name = fields[1];
+ String father = fields[2];
+ String mother = fields[3];
+ String sex = fields[4];
+ String disease = fields[5];
- // parse out extra fields
- ImmutableList.Builder extraFields = new ImmutableList.Builder();
- while (it.hasNext())
- extraFields.add(it.next());
+ List extraFields = new ArrayList<>(Arrays.asList(fields).subList(6, fields.length));
return new PedPerson(pedigree, name, father, mother, Sex.toSex(sex), Disease.toDisease(disease),
- extraFields.build());
+ Collections.unmodifiableList(extraFields));
} catch (NoSuchElementException e) {
throw new PedParseException("Insufficient number of fields in line: \"" + line + "\"");
}
diff --git a/src/main/java/org/monarchinitiative/gregor/pedigree/PedPerson.java b/src/main/java/org/monarchinitiative/gregor/pedigree/PedPerson.java
index 701f354..73e8e08 100644
--- a/src/main/java/org/monarchinitiative/gregor/pedigree/PedPerson.java
+++ b/src/main/java/org/monarchinitiative/gregor/pedigree/PedPerson.java
@@ -1,9 +1,8 @@
package org.monarchinitiative.gregor.pedigree;
-import com.google.common.collect.ImmutableList;
-
import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
/**
* Representation of a line from a pedigree (.ped) file.
@@ -69,7 +68,7 @@ public final class PedPerson {
/**
* the additional fields stored for this person
*/
- private final ImmutableList extraFields;
+ private final List extraFields;
/**
* Initialize object with the given data.
@@ -82,7 +81,7 @@ public PedPerson(String pedigree, String name, String father, String mother, Sex
this.mother = mother;
this.sex = sex;
this.disease = disease;
- this.extraFields = ImmutableList.copyOf(extraFields);
+ this.extraFields = List.copyOf(extraFields);
}
/**
@@ -137,7 +136,7 @@ public Disease getDisease() {
/**
* @return the additional fields stored for this person
*/
- public ImmutableList getExtraFields() {
+ public List getExtraFields() {
return extraFields;
}
diff --git a/src/main/java/org/monarchinitiative/gregor/pedigree/Pedigree.java b/src/main/java/org/monarchinitiative/gregor/pedigree/Pedigree.java
index c93b7e3..2273319 100644
--- a/src/main/java/org/monarchinitiative/gregor/pedigree/Pedigree.java
+++ b/src/main/java/org/monarchinitiative/gregor/pedigree/Pedigree.java
@@ -1,11 +1,6 @@
package org.monarchinitiative.gregor.pedigree;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
+import java.util.*;
// TODO(holtgrem): Test me!
@@ -25,12 +20,12 @@ public final class Pedigree {
/**
* the pedigree's members
*/
- private final ImmutableList members;
+ private final List members;
/**
* mapping from member name to member
*/
- private final ImmutableMap nameToMember;
+ private final Map nameToMember;
/**
* Initialize the object with the given values
@@ -40,13 +35,13 @@ public final class Pedigree {
*/
public Pedigree(String name, Collection members) {
this.name = name;
- this.members = ImmutableList.copyOf(members);
+ this.members = List.copyOf(members);
- ImmutableMap.Builder mapBuilder = new ImmutableMap.Builder();
+ Map map = new LinkedHashMap<>();
int i = 0;
for (Person person : members)
- mapBuilder.put(person.getName(), new IndexedPerson(i++, person));
- this.nameToMember = mapBuilder.build();
+ map.put(person.getName(), new IndexedPerson(i++, person));
+ this.nameToMember = Collections.unmodifiableMap(map);
}
/**
@@ -78,14 +73,14 @@ public String getName() {
/**
* @return the pedigree's members
*/
- public ImmutableList getMembers() {
+ public List getMembers() {
return members;
}
/**
* @return mapping from member name to member
*/
- public ImmutableMap getNameToMember() {
+ public Map getNameToMember() {
return nameToMember;
}
@@ -118,7 +113,7 @@ public Pedigree subsetOfMembers(Collection names) {
*/
public static Pedigree constructSingleSamplePedigree(String sampleName) {
final Person person = new Person(sampleName, null, null, Sex.UNKNOWN, Disease.AFFECTED);
- return new Pedigree("pedigree", ImmutableList.of(person));
+ return new Pedigree("pedigree", List.of(person));
}
/**
@@ -131,11 +126,11 @@ public boolean hasPerson(String name) {
/**
* @return list of members, in the same order as in {@link #members}.
*/
- public ImmutableList getNames() {
- ImmutableList.Builder builder = new ImmutableList.Builder();
+ public List getNames() {
+ List names = new ArrayList<>();
for (Person p : members)
- builder.add(p.getName());
- return builder.build();
+ names.add(p.getName());
+ return Collections.unmodifiableList(names);
}
@Override
diff --git a/src/main/java/org/monarchinitiative/gregor/pedigree/PedigreeExtractor.java b/src/main/java/org/monarchinitiative/gregor/pedigree/PedigreeExtractor.java
index 675c3ed..a6501f1 100644
--- a/src/main/java/org/monarchinitiative/gregor/pedigree/PedigreeExtractor.java
+++ b/src/main/java/org/monarchinitiative/gregor/pedigree/PedigreeExtractor.java
@@ -1,8 +1,9 @@
package org.monarchinitiative.gregor.pedigree;
-import com.google.common.collect.ImmutableList;
-
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
// TODO(holtgrew): Test me!
// TODO(holtgrew): Convenience class for parsing Pedigree files?
@@ -36,7 +37,7 @@ public PedigreeExtractor(String name, PedFileContents contents) {
* @return list of {@link Person}s of the given pedigree
* @throws PedParseException on problems with resolving names of individuals
*/
- public ImmutableList run() throws PedParseException {
+ public List run() throws PedParseException {
// check that all linked-to mothers and fathers exist
for (PedPerson pedPerson : contents.getIndividuals()) {
if (!"0".equals(pedPerson.getFather()) && !contents.getNameToPerson().containsKey(pedPerson.getFather()))
@@ -47,16 +48,16 @@ public ImmutableList run() throws PedParseException {
// construct all Person objects, we use a trick for the construction of immutable Person objects while still
// allowing potential cycles
- ImmutableList.Builder builder = new ImmutableList.Builder();
+ List persons = new ArrayList<>();
HashMap existing = new HashMap();
for (PedPerson pedPerson : contents.getIndividuals())
if (pedPerson.getPedigree().equals(name)) {
if (existing.containsKey(pedPerson.getName()))
- builder.add(existing.get(pedPerson.getName()));
+ persons.add(existing.get(pedPerson.getName()));
else
- builder.add(new Person(pedPerson, contents, existing));
+ persons.add(new Person(pedPerson, contents, existing));
}
- return builder.build();
+ return Collections.unmodifiableList(persons);
}
}
diff --git a/src/main/java/org/monarchinitiative/gregor/pedigree/PedigreeQueryDecorator.java b/src/main/java/org/monarchinitiative/gregor/pedigree/PedigreeQueryDecorator.java
index 406a083..4466b7f 100644
--- a/src/main/java/org/monarchinitiative/gregor/pedigree/PedigreeQueryDecorator.java
+++ b/src/main/java/org/monarchinitiative/gregor/pedigree/PedigreeQueryDecorator.java
@@ -1,10 +1,8 @@
package org.monarchinitiative.gregor.pedigree;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-
-import java.util.HashSet;
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
// TODO(holtgrem): Test me!
@@ -49,33 +47,41 @@ public boolean isParentOfAffected(Person person) {
/**
* @return set with the name of the unaffected persons
*/
- public ImmutableSet getUnaffectedNames() {
- ImmutableSet.Builder resultNames = new ImmutableSet.Builder();
+ public Set getUnaffectedNames() {
+ Set resultNames = new HashSet<>();
for (Person member : pedigree.getMembers())
if (member.getDisease() == Disease.UNAFFECTED)
resultNames.add(member.getName());
- return resultNames.build();
+ return Collections.unmodifiableSet(resultNames);
}
/**
* @return set with the name of the parents
*/
- public ImmutableSet getParentNames() {
- ImmutableSet.Builder parentNames = new ImmutableSet.Builder();
+ public Set getParentNames() {
+ Set parentNames = new HashSet<>();
for (Person member : pedigree.getMembers()) {
if (member.getFather() != null)
parentNames.add(member.getFather().getName());
if (member.getMother() != null)
parentNames.add(member.getMother().getName());
}
- return parentNames.build();
+ return Collections.unmodifiableSet(parentNames);
+ }
+
+ public Set getParentsNames() {
+ return pedigree.getMembers().stream()
+ .flatMap(member -> Stream.of(member.getFather(), member.getMother()))
+ .filter(Objects::nonNull)
+ .map(Person::getName)
+ .collect(Collectors.toUnmodifiableSet());
}
/**
* @return set with the name of the parents from affected females.
*/
- public ImmutableSet getAffectedFemaleParentNames() {
- ImmutableSet.Builder parentNames = new ImmutableSet.Builder();
+ public Set getAffectedFemaleParentNames() {
+ Set parentNames = new HashSet<>();
for (Person member : pedigree.getMembers()) {
if (member.isAffected() && member.isFemale()) {
if (member.getFather() != null)
@@ -84,14 +90,14 @@ public ImmutableSet getAffectedFemaleParentNames() {
parentNames.add(member.getMother().getName());
}
}
- return parentNames.build();
+ return Collections.unmodifiableSet(parentNames);
}
/**
* @return set with the name of the parents from affected males.
*/
- public ImmutableSet getAffectedMaleParentNames() {
- ImmutableSet.Builder parentNames = new ImmutableSet.Builder();
+ public Set getAffectedMaleParentNames() {
+ Set parentNames = new HashSet<>();
for (Person member : pedigree.getMembers()) {
if (member.isAffected() && member.isMale()) {
if (member.getFather() != null)
@@ -100,20 +106,20 @@ public ImmutableSet getAffectedMaleParentNames() {
parentNames.add(member.getMother().getName());
}
}
- return parentNames.build();
+ return Collections.unmodifiableSet(parentNames);
}
/**
* @return list of parents in the same order as in {@link Pedigree#members pedigree.getMembers()}
*/
- public ImmutableList getParents() {
- ImmutableSet parentNames = getParentNames();
+ public List getParents() {
+ Set parentNames = getParentNames();
- ImmutableList.Builder builder = new ImmutableList.Builder();
+ List parents = new ArrayList<>();
for (Person member : pedigree.getMembers())
if (parentNames.contains(member.getName()))
- builder.add(member);
- return builder.build();
+ parents.add(member);
+ return Collections.unmodifiableList(parents);
}
/**
@@ -156,22 +162,22 @@ public int getNumberOfUnaffecteds() {
* @return sibling map for each {@link Person} in {@link Pedigree}, both parents must be in {@link Pedigree} and the
* same pedigree
*/
- public ImmutableMap> buildSiblings() {
- ImmutableMap.Builder> mapBuilder = new ImmutableMap.Builder>();
+ public Map> buildSiblings() {
+ Map> map = new LinkedHashMap<>();
for (Person p1 : pedigree.getMembers()) {
if (p1.getMother() == null || p1.getFather() == null)
continue;
- ImmutableList.Builder listBuilder = new ImmutableList.Builder();
+ List