From ff763d64289bfe9e06d9ff7a23cf6eeb24f1ed16 Mon Sep 17 00:00:00 2001 From: iQuxLE Date: Mon, 29 Apr 2024 18:54:31 +0100 Subject: [PATCH 1/4] Refactor Collection Implementations: Drop Guava for Java Native --- pom.xml | 5 - .../org/monarchinitiative/gregor/App.java | 13 --- .../gregor/mendel/Genotype.java | 11 +- .../gregor/mendel/GenotypeCalls.java | 25 ++--- .../mendel/IncompatiblePedigreeException.java | 3 - .../mendel/MendelianInheritanceChecker.java | 102 ++++++++---------- .../mendel/impl/AbstractMendelianChecker.java | 6 +- .../mendel/impl/InheritanceCheckerMT.java | 8 +- .../mendel/impl/MendelianCheckerAD.java | 7 +- .../mendel/impl/MendelianCheckerAR.java | 11 +- .../impl/MendelianCheckerARCompoundHet.java | 32 +++--- .../mendel/impl/MendelianCheckerARHom.java | 37 ++++--- .../mendel/impl/MendelianCheckerXD.java | 25 ++--- .../mendel/impl/MendelianCheckerXR.java | 10 +- .../impl/MendelianCheckerXRCompoundHet.java | 14 ++- .../mendel/impl/MendelianCheckerXRHom.java | 33 +++--- .../gregor/pedigree/PedFileContents.java | 31 +++--- .../gregor/pedigree/PedFileReader.java | 54 ++++------ .../gregor/pedigree/PedPerson.java | 9 +- .../gregor/pedigree/Pedigree.java | 33 +++--- .../gregor/pedigree/PedigreeExtractor.java | 15 +-- .../pedigree/PedigreeQueryDecorator.java | 60 ++++++----- .../gregor/pedigree/Person.java | 9 +- .../org/monarchinitiative/gregor/AppTest.java | 13 --- .../mendel/GenotypeCallsBuilderTest.java | 5 +- 25 files changed, 252 insertions(+), 319 deletions(-) delete mode 100644 src/main/java/org/monarchinitiative/gregor/App.java delete mode 100644 src/test/java/org/monarchinitiative/gregor/AppTest.java diff --git a/pom.xml b/pom.xml index 17f8ba4..a84af52 100644 --- a/pom.xml +++ b/pom.xml @@ -41,11 +41,6 @@ commons-net 3.10.0 - - com.google.guava - guava - 31.1-jre - diff --git a/src/main/java/org/monarchinitiative/gregor/App.java b/src/main/java/org/monarchinitiative/gregor/App.java deleted file mode 100644 index 4f1e665..0000000 --- a/src/main/java/org/monarchinitiative/gregor/App.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.monarchinitiative.gregor; - -/** - * Hello world! - * - */ -public class App -{ - public static void main( String[] args ) - { - System.out.println( "Hello World!" ); - } -} 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> 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 listBuilder = new ArrayList<>(); for (Person p2 : pedigree.getMembers()) { if (p1.equals(p2) || !p1.getMother().equals(p2.getMother()) || !p1.getFather().equals(p2.getFather())) continue; listBuilder.add(p2); } - mapBuilder.put(p1, listBuilder.build()); + map.put(p1, Collections.unmodifiableList(listBuilder)); } - return mapBuilder.build(); +; return Collections.unmodifiableMap(map); } } diff --git a/src/main/java/org/monarchinitiative/gregor/pedigree/Person.java b/src/main/java/org/monarchinitiative/gregor/pedigree/Person.java index edd9430..1a66b2a 100644 --- a/src/main/java/org/monarchinitiative/gregor/pedigree/Person.java +++ b/src/main/java/org/monarchinitiative/gregor/pedigree/Person.java @@ -1,10 +1,9 @@ package org.monarchinitiative.gregor.pedigree; -import com.google.common.collect.ImmutableList; - import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.List; /** * An individual from a pedigree file, Java programmer friendly version. @@ -46,7 +45,7 @@ public final class Person { /** * extra fields from the PED file */ - private final ImmutableList extraFields; + private final List extraFields; /** * Initialize object with the given values. @@ -57,7 +56,7 @@ public Person(String name, Person father, Person mother, Sex sex, Disease diseas this.mother = mother; this.sex = sex; this.disease = disease; - this.extraFields = ImmutableList.copyOf(extraFields); + this.extraFields = List.copyOf(extraFields); } /** @@ -126,7 +125,7 @@ public Disease getDisease() { /** * @return extra fields from the PED file */ - public ImmutableList getExtraFields() { + public List getExtraFields() { return extraFields; } diff --git a/src/test/java/org/monarchinitiative/gregor/AppTest.java b/src/test/java/org/monarchinitiative/gregor/AppTest.java deleted file mode 100644 index 893973a..0000000 --- a/src/test/java/org/monarchinitiative/gregor/AppTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.monarchinitiative.gregor; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class AppTest { - - @Test - public void testApp() { - assertTrue(true); - } -} \ No newline at end of file diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/GenotypeCallsBuilderTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/GenotypeCallsBuilderTest.java index 70672db..d73c683 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/GenotypeCallsBuilderTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/GenotypeCallsBuilderTest.java @@ -1,10 +1,11 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.List; + public class GenotypeCallsBuilderTest { @BeforeEach @@ -16,7 +17,7 @@ public void test() { GenotypeCallsBuilder builder = new GenotypeCallsBuilder(); builder.setPayload(1); builder.setChromType(ChromosomeType.AUTOSOMAL); - builder.getSampleToGenotype().put("example", new Genotype(ImmutableList.of(0, 1))); + builder.getSampleToGenotype().put("example", new Genotype(List.of(0, 1))); GenotypeCalls calls = builder.build(); From 35240c694cda00466767d7192ba2216845dd2a0a Mon Sep 17 00:00:00 2001 From: iQuxLE Date: Mon, 29 Apr 2024 18:55:13 +0100 Subject: [PATCH 2/4] Refactor Collection Implementations in Tests: Drop Guava for Java Native --- .../InheritanceCheckerMTSinglePersonTest.java | 17 ++++---- .../mendel/InheritanceCheckerMTSmallTest.java | 20 ++++----- ...delianCompatibilityCheckerADLargeTest.java | 41 ++++++++++--------- ...elianCompatibilityCheckerADMediumTest.java | 30 +++++++------- ...anCompatibilityCheckerADSingletonTest.java | 17 ++++---- ...delianCompatibilityCheckerADSmallTest.java | 22 +++++----- ...anCompatibilityCheckerADVerySmallTest.java | 17 ++++---- ...elianCompatibilityCheckerARLarge2Test.java | 29 ++++++------- ...delianCompatibilityCheckerARLargeTest.java | 34 +++++++-------- ...elianCompatibilityCheckerARMediumTest.java | 32 +++++++-------- ...ianCompatibilityCheckerARSiblingsTest.java | 20 +++++---- ...anCompatibilityCheckerARSingletonTest.java | 17 ++++---- ...delianCompatibilityCheckerARSmallTest.java | 22 +++++----- .../MendelianCompatibilityCheckerTest.java | 22 +++++----- ...MendelianCompatibilityCheckerTestBase.java | 36 ++++++++-------- ...atibilityCheckerXDSingletonFemaleTest.java | 16 ++++---- ...mpatibilityCheckerXDSingletonMaleTest.java | 17 ++++---- ...CompatibilityCheckerXDSmallFemaleTest.java | 22 +++++----- ...anCompatibilityCheckerXDSmallMaleTest.java | 22 +++++----- ...atibilityCheckerXRSingletonFemaleTest.java | 16 ++++---- ...mpatibilityCheckerXRSingletonMaleTest.java | 16 ++++---- ...CompatibilityCheckerXRSmallFemaleTest.java | 23 ++++++----- ...anCompatibilityCheckerXRSmallMaleTest.java | 22 +++++----- ...ibilityCheckerXRSmallStupidFemaleTest.java | 23 ++++++----- .../gregor/pedigree/PedFileReaderTest.java | 28 +++++++------ .../gregor/pedigree/PedFileWriterTest.java | 41 +++++++++++-------- .../pedigree/PedigreeQueryDecoratorTest.java | 27 ++++++------ .../gregor/pedigree/PedigreeTest.java | 19 +++++---- 28 files changed, 345 insertions(+), 323 deletions(-) diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/InheritanceCheckerMTSinglePersonTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/InheritanceCheckerMTSinglePersonTest.java index dbdeb25..56e425a 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/InheritanceCheckerMTSinglePersonTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/InheritanceCheckerMTSinglePersonTest.java @@ -1,29 +1,30 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.ArrayList; import java.util.List; +import java.util.Map; public class InheritanceCheckerMTSinglePersonTest extends MendelianCompatibilityCheckerTestBase { private MendelianInheritanceChecker checker; private List gcList; - private ImmutableMap> result; + private Map> result; @BeforeEach public void setUp() throws Exception { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.FEMALE, Disease.AFFECTED)); - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.FEMALE, Disease.AFFECTED) + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1"); + this.names = List.of("I.1"); this.checker = new MendelianInheritanceChecker(this.pedigree); diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/InheritanceCheckerMTSmallTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/InheritanceCheckerMTSmallTest.java index 8c3070f..5f8434f 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/InheritanceCheckerMTSmallTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/InheritanceCheckerMTSmallTest.java @@ -1,34 +1,34 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.ArrayList; import java.util.List; +import java.util.Map; public class InheritanceCheckerMTSmallTest extends MendelianCompatibilityCheckerTestBase { private MendelianInheritanceChecker checker; private List gcList; - private ImmutableMap> result; + private Map> result; private Pedigree inconsistentMTpedigree; @BeforeEach public void setUp() throws Exception { - ImmutableList.Builder individuals = new ImmutableList.Builder(); + List individuals = new ArrayList(); individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED)); // father individuals.add(new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.AFFECTED)); // mother individuals.add(new PedPerson("ped", "II.1", "I.1", "I.2", Sex.MALE, Disease.AFFECTED)); // son individuals.add(new PedPerson("ped", "II.2", "I.1", "I.2", Sex.FEMALE, Disease.AFFECTED)); // daughter - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + PedFileContents pedFileContents = new PedFileContents(new ArrayList(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1", "I.2", "II.1", "II.2"); + this.names = List.of("I.1", "I.2", "II.1", "II.2"); this.checker = new MendelianInheritanceChecker(this.pedigree); @@ -38,13 +38,13 @@ public void setUp() throws Exception { * same as above but father is transmitting mitochrondrial mutation, which is * impossible */ - ImmutableList.Builder individuals2 = new ImmutableList.Builder(); + List individuals2 = new ArrayList(); individuals2.add(new PedPerson("ped2", "I.1", "0", "0", Sex.MALE, Disease.AFFECTED)); // father individuals2.add(new PedPerson("ped2", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED)); // mother individuals2.add(new PedPerson("ped2", "II.1", "I.1", "I.2", Sex.MALE, Disease.AFFECTED)); // son individuals2.add(new PedPerson("ped2", "II.2", "I.1", "I.2", Sex.FEMALE, Disease.AFFECTED)); // daughter - PedFileContents pedFileContents2 = new PedFileContents(new ImmutableList.Builder().build(), - individuals2.build()); + PedFileContents pedFileContents2 = new PedFileContents(new ArrayList(), + individuals2); this.inconsistentMTpedigree = new Pedigree(pedFileContents2, "ped2"); } diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerADLargeTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerADLargeTest.java index 1f1cbf9..4e6655f 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerADLargeTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerADLargeTest.java @@ -1,41 +1,42 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.ArrayList; import java.util.List; +import java.util.Map; public class MendelianCompatibilityCheckerADLargeTest extends MendelianCompatibilityCheckerTestBase { MendelianInheritanceChecker checker; List gcList; - ImmutableMap> result; + Map> result; @BeforeEach public void setUp() throws Exception { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED)); // grandfather - individuals.add(new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED)); // grandmother - individuals.add(new PedPerson("ped", "II.1", "I.1", "I.2", Sex.MALE, Disease.UNAFFECTED)); // p1 - individuals.add(new PedPerson("ped", "II.2", "I.1", "I.2", Sex.MALE, Disease.AFFECTED)); // p2 - individuals.add(new PedPerson("ped", "II.3", "I.1", "I.2", Sex.FEMALE, Disease.UNAFFECTED)); // p3 - individuals.add(new PedPerson("ped", "II.4", "I.1", "I.2", Sex.FEMALE, Disease.AFFECTED)); // p4 - individuals.add(new PedPerson("ped", "II.5", "I.1", "I.2", Sex.UNKNOWN, Disease.UNKNOWN)); // p5 - individuals.add(new PedPerson("ped", "III.1", "II.1", "0", Sex.FEMALE, Disease.UNAFFECTED)); // c1 - individuals.add(new PedPerson("ped", "III.2", "II.1", "0", Sex.MALE, Disease.UNAFFECTED)); // c2 - individuals.add(new PedPerson("ped", "III.3", "II.2", "0", Sex.MALE, Disease.AFFECTED)); // c3 - individuals.add(new PedPerson("ped", "III.4", "II.2", "0", Sex.FEMALE, Disease.UNAFFECTED)); // c4 - individuals.add(new PedPerson("ped", "III.5", "0", "II.3", Sex.FEMALE, Disease.UNAFFECTED)); // c5 - individuals.add(new PedPerson("ped", "III.6", "0", "II.4", Sex.MALE, Disease.AFFECTED)); // c6 - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED), // grandfather + new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED), // grandmother + new PedPerson("ped", "II.1", "I.1", "I.2", Sex.MALE, Disease.UNAFFECTED), // p1 + new PedPerson("ped", "II.2", "I.1", "I.2", Sex.MALE, Disease.AFFECTED), // p2 + new PedPerson("ped", "II.3", "I.1", "I.2", Sex.FEMALE, Disease.UNAFFECTED), // p3 + new PedPerson("ped", "II.4", "I.1", "I.2", Sex.FEMALE, Disease.AFFECTED), // p4 + new PedPerson("ped", "II.5", "I.1", "I.2", Sex.UNKNOWN, Disease.UNKNOWN), // p5 + new PedPerson("ped", "III.1", "II.1", "0", Sex.FEMALE, Disease.UNAFFECTED), // c1 + new PedPerson("ped", "III.2", "II.1", "0", Sex.MALE, Disease.UNAFFECTED), // c2 + new PedPerson("ped", "III.3", "II.2", "0", Sex.MALE, Disease.AFFECTED), // c3 + new PedPerson("ped", "III.4", "II.2", "0", Sex.FEMALE, Disease.UNAFFECTED), // c4 + new PedPerson("ped", "III.5", "0", "II.3", Sex.FEMALE, Disease.UNAFFECTED), // c5 + new PedPerson("ped", "III.6", "0", "II.4", Sex.MALE, Disease.AFFECTED) // c6 + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1", "I.2", "II.1", "II.2", "II.3", "II.4", "II.5", "III.1", "III.2", "III.3", + this.names = List.of("I.1", "I.2", "II.1", "II.2", "II.3", "II.4", "II.5", "III.1", "III.2", "III.3", "III.4", "III.5", "III.6"); this.checker = new MendelianInheritanceChecker(this.pedigree); diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerADMediumTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerADMediumTest.java index 8f647b9..1be16af 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerADMediumTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerADMediumTest.java @@ -1,42 +1,42 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.ArrayList; import java.util.List; +import java.util.Map; public class MendelianCompatibilityCheckerADMediumTest extends MendelianCompatibilityCheckerTestBase { MendelianInheritanceChecker checker; List gcList; - ImmutableMap> result; + Map> result; @BeforeEach public void setUp() throws Exception { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED)); // grandfather - individuals.add(new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED)); // grandmother - individuals.add(new PedPerson("ped", "II.1", "I.1", "I.2", Sex.MALE, Disease.UNAFFECTED)); // uncle - individuals.add(new PedPerson("ped", "II.2", "I.1", "I.2", Sex.MALE, Disease.AFFECTED)); // father - individuals.add(new PedPerson("ped", "II.3", "0", "0", Sex.FEMALE, Disease.UNAFFECTED)); // mother - individuals.add(new PedPerson("ped", "III.1", "II.2", "II.3", Sex.FEMALE, Disease.AFFECTED)); // daughter - individuals.add(new PedPerson("ped", "III.2", "II.2", "II.3", Sex.MALE, Disease.UNAFFECTED)); // son - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED), // grandfather + new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED), // grandmother + new PedPerson("ped", "II.1", "I.1", "I.2", Sex.MALE, Disease.UNAFFECTED), // uncle + new PedPerson("ped", "II.2", "I.1", "I.2", Sex.MALE, Disease.AFFECTED), // father + new PedPerson("ped", "II.3", "0", "0", Sex.FEMALE, Disease.UNAFFECTED), // mother + new PedPerson("ped", "III.1", "II.2", "II.3", Sex.FEMALE, Disease.AFFECTED), // daughter + new PedPerson("ped", "III.2", "II.2", "II.3", Sex.MALE, Disease.UNAFFECTED) // son + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1", "I.2", "II.1", "II.2", "II.3", "III.1", "III.2"); - + this.names = List.of("I.1", "I.2", "II.1", "II.2", "II.3", "III.1", "III.2"); this.checker = new MendelianInheritanceChecker(this.pedigree); this.result = null; this.gcList = null; } + @Test public void testSizeOfPedigree() { Assertions.assertEquals(7, pedigree.getMembers().size()); diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerADSingletonTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerADSingletonTest.java index 095e7d6..63d2649 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerADSingletonTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerADSingletonTest.java @@ -1,28 +1,29 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.ArrayList; import java.util.List; +import java.util.Map; public class MendelianCompatibilityCheckerADSingletonTest extends MendelianCompatibilityCheckerTestBase { MendelianInheritanceChecker checker; List gcList; - ImmutableMap> result; + Map> result; @BeforeEach public void setUp() throws Exception { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.AFFECTED)); - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.AFFECTED) + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1"); + this.names = List.of("I.1"); this.checker = new MendelianInheritanceChecker(this.pedigree); diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerADSmallTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerADSmallTest.java index fbc8f3f..091c12c 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerADSmallTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerADSmallTest.java @@ -1,32 +1,32 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.List; +import java.util.Map; public class MendelianCompatibilityCheckerADSmallTest extends MendelianCompatibilityCheckerTestBase { MendelianInheritanceChecker checker; List gcList; - ImmutableMap> result; + Map> result; @BeforeEach public void setUp() throws Exception { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.AFFECTED)); // father - individuals.add(new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED)); // mother - individuals.add(new PedPerson("ped", "II.1", "I.1", "I.2", Sex.MALE, Disease.AFFECTED)); // son - individuals.add(new PedPerson("ped", "II.2", "I.1", "I.2", Sex.FEMALE, Disease.UNAFFECTED)); // daughter - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.AFFECTED), // father + new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED), // mother + new PedPerson("ped", "II.1", "I.1", "I.2", Sex.MALE, Disease.AFFECTED), // son + new PedPerson("ped", "II.2", "I.1", "I.2", Sex.FEMALE, Disease.UNAFFECTED) // daughter + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1", "I.2", "II.1", "II.2"); + this.names = List.of("I.1", "I.2", "II.1", "II.2"); this.checker = new MendelianInheritanceChecker(this.pedigree); diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerADVerySmallTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerADVerySmallTest.java index 9f2d3c2..d063afd 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerADVerySmallTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerADVerySmallTest.java @@ -1,30 +1,29 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.List; +import java.util.Map; public class MendelianCompatibilityCheckerADVerySmallTest extends MendelianCompatibilityCheckerTestBase { MendelianInheritanceChecker checker; List gcList; - ImmutableMap> result; + Map> result; @BeforeEach public void setUp() throws Exception { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED)); // father - individuals.add(new PedPerson("ped", "II.1", "I.1", "0", Sex.MALE, Disease.AFFECTED)); // son - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED), // father + new PedPerson("ped", "II.1", "I.1", "0", Sex.MALE, Disease.AFFECTED)); // son + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1", "II.1"); + this.names = List.of("I.1", "II.1"); this.checker = new MendelianInheritanceChecker(this.pedigree); diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARLarge2Test.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARLarge2Test.java index 26b60df..3794c81 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARLarge2Test.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARLarge2Test.java @@ -1,35 +1,36 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.ArrayList; import java.util.List; +import java.util.Map; public class MendelianCompatibilityCheckerARLarge2Test extends MendelianCompatibilityCheckerTestBase { MendelianInheritanceChecker checker; List gcList; - ImmutableMap> result; + Map> result; @BeforeEach public void setUp() throws Exception { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED)); // grandgrandfather - individuals.add(new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED)); // grandgrandmother - individuals.add(new PedPerson("ped", "II.1", "I.1", "I.2", Sex.FEMALE, Disease.AFFECTED)); // parent1 - individuals.add(new PedPerson("ped", "II.2", "I.1", "I.2", Sex.MALE, Disease.UNAFFECTED)); // parent2 - individuals.add(new PedPerson("ped", "II.3", "0", "0", Sex.FEMALE, Disease.UNAFFECTED)); // parent3 - individuals.add(new PedPerson("ped", "III.1", "II.2", "II.3", Sex.MALE, Disease.AFFECTED)); // child1 - individuals.add(new PedPerson("ped", "III.2", "II.2", "II.3", Sex.FEMALE, Disease.UNAFFECTED)); // child2 - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED), // grandgrandfather + new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED), // grandgrandmother + new PedPerson("ped", "II.1", "I.1", "I.2", Sex.FEMALE, Disease.AFFECTED), // parent1 + new PedPerson("ped", "II.2", "I.1", "I.2", Sex.MALE, Disease.UNAFFECTED), // parent2 + new PedPerson("ped", "II.3", "0", "0", Sex.FEMALE, Disease.UNAFFECTED), // parent3 + new PedPerson("ped", "III.1", "II.2", "II.3", Sex.MALE, Disease.AFFECTED), // child1 + new PedPerson("ped", "III.2", "II.2", "II.3", Sex.FEMALE, Disease.UNAFFECTED) // child2 + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1", "I.2", "II.1", "II.2", "II.3", "III.1", "III.2"); + this.names = List.of("I.1", "I.2", "II.1", "II.2", "II.3", "III.1", "III.2"); this.checker = new MendelianInheritanceChecker(this.pedigree); diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARLargeTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARLargeTest.java index 9d76345..21eb57b 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARLargeTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARLargeTest.java @@ -1,38 +1,38 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.List; +import java.util.Map; public class MendelianCompatibilityCheckerARLargeTest extends MendelianCompatibilityCheckerTestBase { MendelianInheritanceChecker checker; List gcList; - ImmutableMap> result; + Map> result; @BeforeEach public void setUp() throws Exception { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED)); // grandgrandfather - individuals.add(new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED)); // grandgrandmother - individuals.add(new PedPerson("ped", "II.1", "0", "0", Sex.MALE, Disease.UNAFFECTED)); // parent1 - individuals.add(new PedPerson("ped", "II.2", "I.1", "I.2", Sex.FEMALE, Disease.UNAFFECTED)); // parent2 - individuals.add(new PedPerson("ped", "II.3", "I.1", "I.2", Sex.FEMALE, Disease.AFFECTED)); // parent3 - individuals.add(new PedPerson("ped", "II.4", "I.1", "I.2", Sex.FEMALE, Disease.UNKNOWN)); // parent4 - individuals.add(new PedPerson("ped", "III.1", "II.1", "II.2", Sex.MALE, Disease.UNAFFECTED)); // child1 - individuals.add(new PedPerson("ped", "III.2", "0", "II.3", Sex.MALE, Disease.UNAFFECTED)); // child2 - individuals.add(new PedPerson("ped", "IV.1", "III.1", "0", Sex.FEMALE, Disease.AFFECTED)); // baby1 - individuals.add(new PedPerson("ped", "IV.2", "III.2", "0", Sex.FEMALE, Disease.UNAFFECTED)); // baby2 - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED), // grandgrandfather + new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED), // grandgrandmother + new PedPerson("ped", "II.1", "0", "0", Sex.MALE, Disease.UNAFFECTED), // parent1 + new PedPerson("ped", "II.2", "I.1", "I.2", Sex.FEMALE, Disease.UNAFFECTED), // parent2 + new PedPerson("ped", "II.3", "I.1", "I.2", Sex.FEMALE, Disease.AFFECTED), // parent3 + new PedPerson("ped", "II.4", "I.1", "I.2", Sex.FEMALE, Disease.UNKNOWN), // parent4 + new PedPerson("ped", "III.1", "II.1", "II.2", Sex.MALE, Disease.UNAFFECTED), // child1 + new PedPerson("ped", "III.2", "0", "II.3", Sex.MALE, Disease.UNAFFECTED), // child2 + new PedPerson("ped", "IV.1", "III.1", "0", Sex.FEMALE, Disease.AFFECTED), // baby1 + new PedPerson("ped", "IV.2", "III.2", "0", Sex.FEMALE, Disease.UNAFFECTED) // baby2 + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1", "I.2", "II.1", "II.2", "II.3", "II.4", "III.1", "III.2", "IV.1", "IV.2"); + this.names = List.of("I.1", "I.2", "II.1", "II.2", "II.3", "II.4", "III.1", "III.2", "IV.1", "IV.2"); this.checker = new MendelianInheritanceChecker(this.pedigree); diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARMediumTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARMediumTest.java index 8876208..c99dfa0 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARMediumTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARMediumTest.java @@ -1,37 +1,37 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.List; +import java.util.Map; public class MendelianCompatibilityCheckerARMediumTest extends MendelianCompatibilityCheckerTestBase { MendelianInheritanceChecker checker; List gcList; - ImmutableMap> result; + Map> result; @BeforeEach public void setUp() throws Exception { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED)); // grandgrandfather - individuals.add(new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED)); // grandgrandmother - individuals.add(new PedPerson("ped", "II.1", "0", "0", Sex.FEMALE, Disease.UNAFFECTED)); // grandmother1 - individuals.add(new PedPerson("ped", "II.2", "I.1", "I.2", Sex.MALE, Disease.UNAFFECTED)); // grandfather1 - individuals.add(new PedPerson("ped", "II.3", "I.1", "I.2", Sex.FEMALE, Disease.UNAFFECTED)); // grandmother2 - individuals.add(new PedPerson("ped", "II.4", "0", "0", Sex.MALE, Disease.UNAFFECTED)); // grandfather2 - individuals.add(new PedPerson("ped", "III.1", "II.1", "II.2", Sex.MALE, Disease.UNAFFECTED)); // father - individuals.add(new PedPerson("ped", "III.2", "II.3", "II.4", Sex.FEMALE, Disease.UNAFFECTED)); // mother - individuals.add(new PedPerson("ped", "IV.1", "III.1", "III.2", Sex.FEMALE, Disease.AFFECTED)); // child - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED), // grandgrandfather + new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED), // grandgrandmother + new PedPerson("ped", "II.1", "0", "0", Sex.FEMALE, Disease.UNAFFECTED), // grandmother1 + new PedPerson("ped", "II.2", "I.1", "I.2", Sex.MALE, Disease.UNAFFECTED), // grandfather1 + new PedPerson("ped", "II.3", "I.1", "I.2", Sex.FEMALE, Disease.UNAFFECTED), // grandmother2 + new PedPerson("ped", "II.4", "0", "0", Sex.MALE, Disease.UNAFFECTED), // grandfather2 + new PedPerson("ped", "III.1", "II.1", "II.2", Sex.MALE, Disease.UNAFFECTED), // father + new PedPerson("ped", "III.2", "II.3", "II.4", Sex.FEMALE, Disease.UNAFFECTED), // mother + new PedPerson("ped", "IV.1", "III.1", "III.2", Sex.FEMALE, Disease.AFFECTED) // child + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1", "I.2", "II.1", "II.2", "II.3", "II.4", "III.1", "III.2", "IV.1"); + this.names = List.of("I.1", "I.2", "II.1", "II.2", "II.3", "II.4", "III.1", "III.2", "IV.1"); this.checker = new MendelianInheritanceChecker(this.pedigree); diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARSiblingsTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARSiblingsTest.java index 5c2e1ec..1667c01 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARSiblingsTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARSiblingsTest.java @@ -1,30 +1,32 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.sql.Array; +import java.util.ArrayList; import java.util.List; +import java.util.Map; public class MendelianCompatibilityCheckerARSiblingsTest extends MendelianCompatibilityCheckerTestBase { MendelianInheritanceChecker checker; List gcList; - ImmutableMap> result; + Map> result; @BeforeEach public void setUp() throws Exception { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.AFFECTED)); // child 1 - individuals.add(new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.AFFECTED)); // child 2 - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.AFFECTED), // child 1 + new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.AFFECTED) // child 2 + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1", "I.2"); + this.names = List.of("I.1", "I.2"); this.checker = new MendelianInheritanceChecker(this.pedigree); diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARSingletonTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARSingletonTest.java index 28c1434..58b0729 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARSingletonTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARSingletonTest.java @@ -1,29 +1,30 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.ArrayList; import java.util.List; +import java.util.Map; public class MendelianCompatibilityCheckerARSingletonTest extends MendelianCompatibilityCheckerTestBase { MendelianInheritanceChecker checker; List gcList; - ImmutableMap> result; + Map> result; @BeforeEach public void setUp() throws Exception { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.AFFECTED)); - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.AFFECTED) + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1"); + this.names = List.of("I.1"); this.checker = new MendelianInheritanceChecker(this.pedigree); diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARSmallTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARSmallTest.java index 3fb7ab1..3124fa6 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARSmallTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerARSmallTest.java @@ -1,32 +1,32 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.List; +import java.util.Map; public class MendelianCompatibilityCheckerARSmallTest extends MendelianCompatibilityCheckerTestBase { MendelianInheritanceChecker checker; List gcList; - ImmutableMap> result; + Map> result; @BeforeEach public void setUp() throws Exception { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED)); // father - individuals.add(new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED)); // mother - individuals.add(new PedPerson("ped", "II.1", "I.1", "I.2", Sex.MALE, Disease.AFFECTED)); // son - individuals.add(new PedPerson("ped", "II.2", "I.1", "I.2", Sex.FEMALE, Disease.UNAFFECTED)); // daughter - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED), // father + new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED), // mother + new PedPerson("ped", "II.1", "I.1", "I.2", Sex.MALE, Disease.AFFECTED), // son + new PedPerson("ped", "II.2", "I.1", "I.2", Sex.FEMALE, Disease.UNAFFECTED) // daughter + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1", "I.2", "II.1", "II.2"); + this.names = List.of("I.1", "I.2", "II.1", "II.2"); this.checker = new MendelianInheritanceChecker(this.pedigree); diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerTest.java index 71ff744..df48429 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerTest.java @@ -1,32 +1,32 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.List; +import java.util.Map; public class MendelianCompatibilityCheckerTest extends MendelianCompatibilityCheckerTestBase { MendelianInheritanceChecker checker; List gcList; - ImmutableMap> result; + Map> result; @BeforeEach public void setUp() throws PedParseException { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED)); // father - individuals.add(new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED)); // mother - individuals.add(new PedPerson("ped", "II.1", "I.1", "I.2", Sex.MALE, Disease.AFFECTED)); // son - individuals.add(new PedPerson("ped", "II.2", "I.1", "I.2", Sex.FEMALE, Disease.UNAFFECTED)); // daughter - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED), // father + new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED), // mother + new PedPerson("ped", "II.1", "I.1", "I.2", Sex.MALE, Disease.AFFECTED), // son + new PedPerson("ped", "II.2", "I.1", "I.2", Sex.FEMALE, Disease.UNAFFECTED) // daughter + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1", "I.2", "II.1", "II.2"); + this.names = List.of("I.1", "I.2", "II.1", "II.2"); this.checker = new MendelianInheritanceChecker(this.pedigree); diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerTestBase.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerTestBase.java index bc508e6..9589921 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerTestBase.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerTestBase.java @@ -1,9 +1,9 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; import org.monarchinitiative.gregor.pedigree.Pedigree; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -42,35 +42,35 @@ protected enum SimpleGenotype { protected final SimpleGenotype ALT = SimpleGenotype.ALT; protected final SimpleGenotype UKN = SimpleGenotype.UKN; - protected ImmutableList names; + protected List names; protected Pedigree pedigree; /** * @return a {@link com.google.common.collect.ImmutableList} object. */ - protected ImmutableList lst(SimpleGenotype... gts) { - ImmutableList.Builder builder = new ImmutableList.Builder(); + protected List lst(SimpleGenotype... gts) { + List genotypes = new ArrayList<>(); for (int i = 0; i < gts.length; ++i) - builder.add(gts[i]); - return builder.build(); + genotypes.add(gts[i]); + return Collections.unmodifiableList(genotypes); } - protected List getGenotypeCallsList(ImmutableList genotypes, + protected List getGenotypeCallsList(List genotypes, ChromosomeType chromosomeType) { HashMap entries = new HashMap(); for (int i = 0; i < names.size(); ++i) { switch (genotypes.get(i)) { case HET: - entries.put(names.get(i), new Genotype(ImmutableList.of(Genotype.REF_CALL, 1))); + entries.put(names.get(i), new Genotype(List.of(Genotype.REF_CALL, 1))); break; case REF: - entries.put(names.get(i), new Genotype(ImmutableList.of(Genotype.REF_CALL, Genotype.REF_CALL))); + entries.put(names.get(i), new Genotype(List.of(Genotype.REF_CALL, Genotype.REF_CALL))); break; case ALT: - entries.put(names.get(i), new Genotype(ImmutableList.of(1, 1))); + entries.put(names.get(i), new Genotype(List.of(1, 1))); break; case UKN: - entries.put(names.get(i), new Genotype(ImmutableList.of(Genotype.NO_CALL, Genotype.NO_CALL))); + entries.put(names.get(i), new Genotype(List.of(Genotype.NO_CALL, Genotype.NO_CALL))); break; } } @@ -81,25 +81,25 @@ protected List getGenotypeCallsList(ImmutableList } @SuppressWarnings("unchecked") - protected List getGenotypeCallsList(ImmutableList genotypes1, - ImmutableList genotypes2, ChromosomeType chromosomeType) { + protected List getGenotypeCallsList(List genotypes1, + List genotypes2, ChromosomeType chromosomeType) { List gcs = new ArrayList(); for (Object obj : new Object[]{genotypes1, genotypes2}) { - ImmutableList genotypes = (ImmutableList) obj; + List genotypes = (List) obj; HashMap entries = new HashMap(); for (int i = 0; i < names.size(); ++i) { switch (genotypes.get(i)) { case HET: - entries.put(names.get(i), new Genotype(ImmutableList.of(Genotype.REF_CALL, 1))); + entries.put(names.get(i), new Genotype(List.of(Genotype.REF_CALL, 1))); break; case REF: - entries.put(names.get(i), new Genotype(ImmutableList.of(Genotype.REF_CALL, Genotype.REF_CALL))); + entries.put(names.get(i), new Genotype(List.of(Genotype.REF_CALL, Genotype.REF_CALL))); break; case ALT: - entries.put(names.get(i), new Genotype(ImmutableList.of(1, 1))); + entries.put(names.get(i), new Genotype(List.of(1, 1))); break; case UKN: - entries.put(names.get(i), new Genotype(ImmutableList.of(Genotype.NO_CALL, Genotype.NO_CALL))); + entries.put(names.get(i), new Genotype(List.of(Genotype.NO_CALL, Genotype.NO_CALL))); break; } } diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXDSingletonFemaleTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXDSingletonFemaleTest.java index 0aba11f..9e845cb 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXDSingletonFemaleTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXDSingletonFemaleTest.java @@ -1,29 +1,29 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.List; +import java.util.Map; public class MendelianCompatibilityCheckerXDSingletonFemaleTest extends MendelianCompatibilityCheckerTestBase { MendelianInheritanceChecker checker; List gcList; - ImmutableMap> result; + Map> result; @BeforeEach public void setUp() throws Exception { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.AFFECTED)); - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.AFFECTED) + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1"); + this.names = List.of("I.1"); this.checker = new MendelianInheritanceChecker(this.pedigree); diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXDSingletonMaleTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXDSingletonMaleTest.java index 905f996..91cba02 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXDSingletonMaleTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXDSingletonMaleTest.java @@ -1,29 +1,30 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.ArrayList; import java.util.List; +import java.util.Map; public class MendelianCompatibilityCheckerXDSingletonMaleTest extends MendelianCompatibilityCheckerTestBase { MendelianInheritanceChecker checker; List gcList; - ImmutableMap> result; + Map> result; @BeforeEach public void setUp() throws Exception { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.FEMALE, Disease.AFFECTED)); - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.FEMALE, Disease.AFFECTED) + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1"); + this.names = List.of("I.1"); this.checker = new MendelianInheritanceChecker(this.pedigree); diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXDSmallFemaleTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXDSmallFemaleTest.java index 5c99b1a..fe4c66e 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXDSmallFemaleTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXDSmallFemaleTest.java @@ -1,32 +1,32 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.List; +import java.util.Map; public class MendelianCompatibilityCheckerXDSmallFemaleTest extends MendelianCompatibilityCheckerTestBase { MendelianInheritanceChecker checker; List gcList; - ImmutableMap> result; + Map> result; @BeforeEach public void setUp() throws Exception { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED)); // father - individuals.add(new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.AFFECTED)); // mother - individuals.add(new PedPerson("ped", "II.1", "I.1", "I.2", Sex.MALE, Disease.UNAFFECTED)); // son - individuals.add(new PedPerson("ped", "II.2", "I.1", "I.2", Sex.FEMALE, Disease.AFFECTED)); // daughter - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED), // father + new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.AFFECTED), // mother + new PedPerson("ped", "II.1", "I.1", "I.2", Sex.MALE, Disease.UNAFFECTED), // son + new PedPerson("ped", "II.2", "I.1", "I.2", Sex.FEMALE, Disease.AFFECTED) // daughter + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1", "I.2", "II.1", "II.2"); + this.names = List.of("I.1", "I.2", "II.1", "II.2"); this.checker = new MendelianInheritanceChecker(this.pedigree); diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXDSmallMaleTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXDSmallMaleTest.java index 1549bc5..f08427e 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXDSmallMaleTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXDSmallMaleTest.java @@ -1,32 +1,32 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.List; +import java.util.Map; public class MendelianCompatibilityCheckerXDSmallMaleTest extends MendelianCompatibilityCheckerTestBase { MendelianInheritanceChecker checker; List gcList; - ImmutableMap> result; + Map> result; @BeforeEach public void setUp() throws Exception { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED)); // father - individuals.add(new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.AFFECTED)); // mother - individuals.add(new PedPerson("ped", "II.1", "I.1", "I.2", Sex.MALE, Disease.AFFECTED)); // son - individuals.add(new PedPerson("ped", "II.2", "I.1", "I.2", Sex.FEMALE, Disease.UNAFFECTED)); // daughter - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED), // father + new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.AFFECTED), // mother + new PedPerson("ped", "II.1", "I.1", "I.2", Sex.MALE, Disease.AFFECTED), // son + new PedPerson("ped", "II.2", "I.1", "I.2", Sex.FEMALE, Disease.UNAFFECTED) // daugter + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1", "I.2", "II.1", "II.2"); + this.names = List.of("I.1", "I.2", "II.1", "II.2"); this.checker = new MendelianInheritanceChecker(this.pedigree); diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXRSingletonFemaleTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXRSingletonFemaleTest.java index 88b139b..5dd6e81 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXRSingletonFemaleTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXRSingletonFemaleTest.java @@ -1,29 +1,29 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.List; +import java.util.Map; public class MendelianCompatibilityCheckerXRSingletonFemaleTest extends MendelianCompatibilityCheckerTestBase { MendelianInheritanceChecker checker; List gcList; - ImmutableMap> result; + Map> result; @BeforeEach public void setUp() throws Exception { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.FEMALE, Disease.AFFECTED)); - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.FEMALE, Disease.AFFECTED) + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1"); + this.names = List.of("I.1"); this.checker = new MendelianInheritanceChecker(this.pedigree); diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXRSingletonMaleTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXRSingletonMaleTest.java index a73cb5d..0e1da5c 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXRSingletonMaleTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXRSingletonMaleTest.java @@ -1,29 +1,29 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.List; +import java.util.Map; public class MendelianCompatibilityCheckerXRSingletonMaleTest extends MendelianCompatibilityCheckerTestBase { MendelianInheritanceChecker checker; List gcList; - ImmutableMap> result; + Map> result; @BeforeEach public void setUp() throws Exception { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.AFFECTED)); - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.AFFECTED) + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1"); + this.names = List.of("I.1"); this.checker = new MendelianInheritanceChecker(this.pedigree); diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXRSmallFemaleTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXRSmallFemaleTest.java index 23b0888..598484e 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXRSmallFemaleTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXRSmallFemaleTest.java @@ -1,32 +1,33 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.ArrayList; import java.util.List; +import java.util.Map; public class MendelianCompatibilityCheckerXRSmallFemaleTest extends MendelianCompatibilityCheckerTestBase { MendelianInheritanceChecker checker; List gcList; - ImmutableMap> result; + Map> result; @BeforeEach public void setUp() throws Exception { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.AFFECTED)); // father - individuals.add(new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED)); // mother - individuals.add(new PedPerson("ped", "II.1", "I.1", "I.2", Sex.MALE, Disease.UNAFFECTED)); // son - individuals.add(new PedPerson("ped", "II.2", "I.1", "I.2", Sex.FEMALE, Disease.AFFECTED)); // daughter - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.AFFECTED), // father + new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED), // mother + new PedPerson("ped", "II.1", "I.1", "I.2", Sex.MALE, Disease.UNAFFECTED), // son + new PedPerson("ped", "II.2", "I.1", "I.2", Sex.FEMALE, Disease.AFFECTED) + ); // daughter + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1", "I.2", "II.1", "II.2"); + this.names = List.of("I.1", "I.2", "II.1", "II.2"); this.checker = new MendelianInheritanceChecker(this.pedigree); diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXRSmallMaleTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXRSmallMaleTest.java index a61cf47..464c111 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXRSmallMaleTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXRSmallMaleTest.java @@ -1,32 +1,32 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.List; +import java.util.Map; public class MendelianCompatibilityCheckerXRSmallMaleTest extends MendelianCompatibilityCheckerTestBase { MendelianInheritanceChecker checker; List gcList; - ImmutableMap> result; + Map> result; @BeforeEach public void setUp() throws Exception { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED)); // father - individuals.add(new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED)); // mother - individuals.add(new PedPerson("ped", "II.1", "I.1", "I.2", Sex.MALE, Disease.AFFECTED)); // son - individuals.add(new PedPerson("ped", "II.2", "I.1", "I.2", Sex.FEMALE, Disease.UNAFFECTED)); // daughter - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED), // father + new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED), // mother + new PedPerson("ped", "II.1", "I.1", "I.2", Sex.MALE, Disease.AFFECTED), // son + new PedPerson("ped", "II.2", "I.1", "I.2", Sex.FEMALE, Disease.UNAFFECTED) // daughter + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1", "I.2", "II.1", "II.2"); + this.names = List.of("I.1", "I.2", "II.1", "II.2"); this.checker = new MendelianInheritanceChecker(this.pedigree); diff --git a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXRSmallStupidFemaleTest.java b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXRSmallStupidFemaleTest.java index 6568a06..34cafd1 100644 --- a/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXRSmallStupidFemaleTest.java +++ b/src/test/java/org/monarchinitiative/gregor/mendel/MendelianCompatibilityCheckerXRSmallStupidFemaleTest.java @@ -1,35 +1,36 @@ package org.monarchinitiative.gregor.mendel; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.monarchinitiative.gregor.pedigree.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.ArrayList; import java.util.List; +import java.util.Map; public class MendelianCompatibilityCheckerXRSmallStupidFemaleTest extends MendelianCompatibilityCheckerTestBase { MendelianInheritanceChecker checker; List gcList; - ImmutableMap> result; + Map> result; @BeforeEach public void setUp() throws Exception { // STUPID PEDIGREE! The male must be affected. Otherwise it can only be // a de-novo second second hit. But we do not want to cover special // cases. So this case should always return no variant! - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED)); // father - individuals.add(new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED)); // mother - individuals.add(new PedPerson("ped", "II.1", "I.1", "I.2", Sex.MALE, Disease.UNAFFECTED)); // son - individuals.add(new PedPerson("ped", "II.2", "I.1", "I.2", Sex.FEMALE, Disease.AFFECTED)); // daughter - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("ped", "I.1", "0", "0", Sex.MALE, Disease.UNAFFECTED), // father + new PedPerson("ped", "I.2", "0", "0", Sex.FEMALE, Disease.UNAFFECTED), // mother + new PedPerson("ped", "II.1", "I.1", "I.2", Sex.MALE, Disease.UNAFFECTED), // son + new PedPerson("ped", "II.2", "I.1", "I.2", Sex.FEMALE, Disease.AFFECTED) // daughter + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "ped"); - this.names = ImmutableList.of("I.1", "I.2", "II.1", "II.2"); + this.names = List.of("I.1", "I.2", "II.1", "II.2"); this.checker = new MendelianInheritanceChecker(this.pedigree); diff --git a/src/test/java/org/monarchinitiative/gregor/pedigree/PedFileReaderTest.java b/src/test/java/org/monarchinitiative/gregor/pedigree/PedFileReaderTest.java index d0a5ca0..c1397ae 100644 --- a/src/test/java/org/monarchinitiative/gregor/pedigree/PedFileReaderTest.java +++ b/src/test/java/org/monarchinitiative/gregor/pedigree/PedFileReaderTest.java @@ -1,6 +1,5 @@ package org.monarchinitiative.gregor.pedigree; -import com.google.common.collect.ImmutableList; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -9,6 +8,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.util.List; public class PedFileReaderTest { @@ -70,12 +70,13 @@ public void testParseWithHeader() throws PedParseException, IOException { Assertions.assertEquals(pedFileContents.getExtraColumnHeaders().size(), 0); - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("fam", "father", "0", "0", Sex.MALE, Disease.UNKNOWN)); - individuals.add(new PedPerson("fam", "mother", "0", "0", Sex.FEMALE, Disease.UNKNOWN)); - individuals.add(new PedPerson("fam", "son", "father", "mother", Sex.MALE, Disease.UNKNOWN)); - individuals.add(new PedPerson("fam", "daughter", "father", "mother", Sex.FEMALE, Disease.UNKNOWN)); - Assertions.assertEquals(pedFileContents.getIndividuals(), individuals.build()); + List individuals = List.of( + new PedPerson("fam", "father", "0", "0", Sex.MALE, Disease.UNKNOWN), + new PedPerson("fam", "mother", "0", "0", Sex.FEMALE, Disease.UNKNOWN), + new PedPerson("fam", "son", "father", "mother", Sex.MALE, Disease.UNKNOWN), + new PedPerson("fam", "daughter", "father", "mother", Sex.FEMALE, Disease.UNKNOWN) + ); + Assertions.assertEquals(pedFileContents.getIndividuals(), individuals); } @Test @@ -85,12 +86,13 @@ public void testParseWithoutHeader() throws PedParseException, IOException { Assertions.assertEquals(pedFileContents.getExtraColumnHeaders().size(), 0); - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("fam", "father", "0", "0", Sex.MALE, Disease.UNKNOWN)); - individuals.add(new PedPerson("fam", "mother", "0", "0", Sex.FEMALE, Disease.UNKNOWN)); - individuals.add(new PedPerson("fam", "son", "father", "mother", Sex.MALE, Disease.UNKNOWN)); - individuals.add(new PedPerson("fam", "daughter", "father", "mother", Sex.FEMALE, Disease.UNKNOWN)); - Assertions.assertEquals(pedFileContents.getIndividuals(), individuals.build()); + List individuals = List.of( + new PedPerson("fam", "father", "0", "0", Sex.MALE, Disease.UNKNOWN), + new PedPerson("fam", "mother", "0", "0", Sex.FEMALE, Disease.UNKNOWN), + new PedPerson("fam", "son", "father", "mother", Sex.MALE, Disease.UNKNOWN), + new PedPerson("fam", "daughter", "father", "mother", Sex.FEMALE, Disease.UNKNOWN) + ); + Assertions.assertEquals(pedFileContents.getIndividuals(), individuals); } } diff --git a/src/test/java/org/monarchinitiative/gregor/pedigree/PedFileWriterTest.java b/src/test/java/org/monarchinitiative/gregor/pedigree/PedFileWriterTest.java index 1245f0f..fa1d919 100644 --- a/src/test/java/org/monarchinitiative/gregor/pedigree/PedFileWriterTest.java +++ b/src/test/java/org/monarchinitiative/gregor/pedigree/PedFileWriterTest.java @@ -1,14 +1,14 @@ package org.monarchinitiative.gregor.pedigree; -import com.google.common.base.Charsets; -import com.google.common.collect.ImmutableList; -import com.google.common.io.Files; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.List; public class PedFileWriterTest { @@ -21,25 +21,30 @@ public void setUp() throws IOException { @Test public void testWrite() throws IOException { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("fam", "father", "0", "0", Sex.MALE, Disease.UNKNOWN)); - individuals.add(new PedPerson("fam", "mother", "0", "0", Sex.FEMALE, Disease.UNKNOWN)); - individuals.add(new PedPerson("fam", "son", "father", "mother", Sex.MALE, Disease.UNKNOWN)); - individuals.add(new PedPerson("fam", "daughter", "father", "mother", Sex.FEMALE, Disease.UNKNOWN)); - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("fam", "father", "0", "0", Sex.MALE, Disease.UNKNOWN), + new PedPerson("fam", "mother", "0", "0", Sex.FEMALE, Disease.UNKNOWN), + new PedPerson("fam", "son", "father", "mother", Sex.MALE, Disease.UNKNOWN), + new PedPerson("fam", "daughter", "father", "mother", Sex.FEMALE, Disease.UNKNOWN) + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); + + File tmpFile = File.createTempFile("test", ".ped"); + tmpFile.deleteOnExit(); // Ensure the file is deleted when the JVM exits PedFileWriter writer = new PedFileWriter(tmpFile); writer.write(pedFileContents); - String fileContents = Files.asCharSource(tmpFile, Charsets.UTF_8).read(); - StringBuilder expectedContents = new StringBuilder(); - expectedContents.append("#PEDIGREE\tNAME\tFATHER\tMOTHER\tSEX\tDISEASE\n"); - expectedContents.append("fam\tfather\t0\t0\t1\t0\n"); - expectedContents.append("fam\tmother\t0\t0\t2\t0\n"); - expectedContents.append("fam\tson\tfather\tmother\t1\t0\n"); - expectedContents.append("fam\tdaughter\tfather\tmother\t2\t0\n"); - Assertions.assertEquals(expectedContents.toString(), fileContents); + String fileContents = Files.readString(tmpFile.toPath()); + + String expectedContents = "#PEDIGREE\tNAME\tFATHER\tMOTHER\tSEX\tDISEASE\n" + + "fam\tfather\t0\t0\t1\t0\n" + + "fam\tmother\t0\t0\t2\t0\n" + + "fam\tson\tfather\tmother\t1\t0\n" + + "fam\tdaughter\tfather\tmother\t2\t0\n"; + + Assertions.assertEquals(expectedContents, fileContents); } } diff --git a/src/test/java/org/monarchinitiative/gregor/pedigree/PedigreeQueryDecoratorTest.java b/src/test/java/org/monarchinitiative/gregor/pedigree/PedigreeQueryDecoratorTest.java index 1db6a40..0ab1e71 100644 --- a/src/test/java/org/monarchinitiative/gregor/pedigree/PedigreeQueryDecoratorTest.java +++ b/src/test/java/org/monarchinitiative/gregor/pedigree/PedigreeQueryDecoratorTest.java @@ -1,11 +1,13 @@ package org.monarchinitiative.gregor.pedigree; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + public class PedigreeQueryDecoratorTest { Pedigree pedigree; @@ -13,13 +15,14 @@ public class PedigreeQueryDecoratorTest { @BeforeEach public void setUp() throws PedParseException { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("fam", "father", "0", "0", Sex.MALE, Disease.UNAFFECTED)); - individuals.add(new PedPerson("fam", "mother", "0", "0", Sex.FEMALE, Disease.UNKNOWN)); - individuals.add(new PedPerson("fam", "son", "father", "mother", Sex.MALE, Disease.AFFECTED)); - individuals.add(new PedPerson("fam", "daughter", "father", "mother", Sex.FEMALE, Disease.UNKNOWN)); - PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), - individuals.build()); + List individuals = List.of( + new PedPerson("fam", "father", "0", "0", Sex.MALE, Disease.UNAFFECTED), + new PedPerson("fam", "mother", "0", "0", Sex.FEMALE, Disease.UNKNOWN), + new PedPerson("fam", "son", "father", "mother", Sex.MALE, Disease.AFFECTED), + new PedPerson("fam", "daughter", "father", "mother", Sex.FEMALE, Disease.UNKNOWN) + ); + PedFileContents pedFileContents = new PedFileContents(List.of(), + individuals); this.pedigree = new Pedigree(pedFileContents, "fam"); this.decorator = new PedigreeQueryDecorator(pedigree); @@ -35,17 +38,17 @@ public void testIsParentOfAffected() { @Test public void testGetUnaffectedNames() { - Assertions.assertEquals(ImmutableSet.of("father"), decorator.getUnaffectedNames()); + Assertions.assertEquals(Set.of("father"), decorator.getUnaffectedNames()); } @Test public void testGetParentNames() { - Assertions.assertEquals(ImmutableSet.of("father", "mother"), decorator.getParentNames()); + Assertions.assertEquals(Set.of("father", "mother"), decorator.getParentNames()); } @Test public void testGetParents() { - Assertions.assertEquals(ImmutableList.of(pedigree.getMembers().get(0), pedigree.getMembers().get(1)), decorator.getParents()); + Assertions.assertEquals(List.of(pedigree.getMembers().get(0), pedigree.getMembers().get(1)), decorator.getParents()); } @Test diff --git a/src/test/java/org/monarchinitiative/gregor/pedigree/PedigreeTest.java b/src/test/java/org/monarchinitiative/gregor/pedigree/PedigreeTest.java index ffbe6e0..947cb99 100644 --- a/src/test/java/org/monarchinitiative/gregor/pedigree/PedigreeTest.java +++ b/src/test/java/org/monarchinitiative/gregor/pedigree/PedigreeTest.java @@ -1,10 +1,12 @@ package org.monarchinitiative.gregor.pedigree; -import com.google.common.collect.ImmutableList; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.ArrayList; +import java.util.List; + /** * Unit tests for the {@link Pedigree} class. * @@ -16,13 +18,14 @@ public class PedigreeTest { @BeforeEach public void setUp() { - ImmutableList.Builder individuals = new ImmutableList.Builder(); - individuals.add(new PedPerson("fam", "father", "0", "0", Sex.MALE, Disease.UNKNOWN)); - individuals.add(new PedPerson("fam", "mother", "0", "0", Sex.FEMALE, Disease.UNKNOWN)); - individuals.add(new PedPerson("fam", "son", "father", "mother", Sex.MALE, Disease.UNKNOWN)); - individuals.add(new PedPerson("fam", "daughter", "father", "mother", Sex.FEMALE, Disease.UNKNOWN)); - individuals.add(new PedPerson("fam2", "other", "0", "0", Sex.FEMALE, Disease.UNKNOWN)); - this.pedFileContents = new PedFileContents(new ImmutableList.Builder().build(), individuals.build()); + List individuals = List.of( + new PedPerson("fam", "father", "0", "0", Sex.MALE, Disease.UNKNOWN), + new PedPerson("fam", "mother", "0", "0", Sex.FEMALE, Disease.UNKNOWN), + new PedPerson("fam", "son", "father", "mother", Sex.MALE, Disease.UNKNOWN), + new PedPerson("fam", "daughter", "father", "mother", Sex.FEMALE, Disease.UNKNOWN), + new PedPerson("fam2", "other", "0", "0", Sex.FEMALE, Disease.UNKNOWN) + ); + this.pedFileContents = new PedFileContents(List.of(), individuals); } @Test From 561481cbf7607b1aa2b4b6298e6b75e258ae19b4 Mon Sep 17 00:00:00 2001 From: iQuxLE Date: Mon, 29 Apr 2024 19:04:59 +0100 Subject: [PATCH 3/4] delete unused dependencies --- pom.xml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pom.xml b/pom.xml index 519385d..f7417a7 100644 --- a/pom.xml +++ b/pom.xml @@ -29,16 +29,6 @@ ${junit.jupiter.version} test - - commons-io - commons-io - 2.16.1 - - - commons-net - commons-net - 3.10.0 - From c4d426a3d35d98c49258423b4fa906245c58e873 Mon Sep 17 00:00:00 2001 From: iQuxLE Date: Mon, 29 Apr 2024 19:09:35 +0100 Subject: [PATCH 4/4] dont commit Maven build artifacts #5 --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) 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