Skip to content

Commit

Permalink
Merge pull request #44 from PankratzLab/develop
Browse files Browse the repository at this point in the history
DonorCheck v0.0.14
  • Loading branch information
rcoleb authored Mar 21, 2024
2 parents bf058c4 + b998b34 commit c6084d9
Show file tree
Hide file tree
Showing 65 changed files with 13,678 additions and 1,859 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<groupId>org.pankratzlab</groupId>
<artifactId>donor-check</artifactId>
<!-- if version number changes, be sure to update in project.properties file also -->
<version>0.0.13</version>
<version>0.0.14</version>
<packaging>jar</packaging>

<description>A stand-alone tool for validating DonorNet typing entries.</description>
Expand All @@ -28,6 +28,11 @@
<name>Kaitlin Clarke</name>
<email>krclarke@umn.edu</email>
</developer>
<developer>
<id>rcoleb</id>
<name>Ben Cole</name>
<email>cole0482@umn.edu</email>
</developer>
</developers>


Expand Down
36 changes: 21 additions & 15 deletions src/main/java/org/pankratzlab/unet/deprecated/hla/Antigen.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

/** Abstract superclass for general antigen information. Allows comparison and sorting. */
public abstract class Antigen<L extends Locus<L>, A extends Antigen<L, A>>
implements Serializable, Comparable<A> {
implements Serializable, Comparable<A> {

private static final long serialVersionUID = 5L;

Expand All @@ -56,8 +56,8 @@ public abstract class Antigen<L extends Locus<L>, A extends Antigen<L, A>>
public static final String LOCUS_DELIM = "*";

/** {@link Pattern} for matching antigen specificities. */
public static final Pattern SPEC_PATTERN = Pattern.compile("\\" + LOCUS_DELIM
+ "?([0-9]+[:[0-9]+]*)(?:\\(([0-9]+[:[0-9]+]*)\\))*");
public static final Pattern SPEC_PATTERN =
Pattern.compile("\\" + LOCUS_DELIM + "?([0-9]+[:[0-9]+]*)(?:\\(([0-9]+[:[0-9]+]*)\\))*");

public static final int LATEST_REVISION = 1;

Expand Down Expand Up @@ -130,7 +130,7 @@ public String specString() {
return String.format("%d", spec().get(0));
}
return spec().stream().map(i -> String.format("%02d", i))
.collect(Collectors.joining(getSpecDelim()));
.collect(Collectors.joining(getSpecDelim()));
}

/**
Expand Down Expand Up @@ -196,12 +196,17 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Antigen<?, ?> other = (Antigen<?, ?>) obj;
if (locus != other.locus()) return false;
if (!Arrays.equals(specificity, other.specificity)) return false;
if (locus != other.locus())
return false;
if (!Arrays.equals(specificity, other.specificity))
return false;
return true;
}

Expand Down Expand Up @@ -277,9 +282,10 @@ public static boolean is(String text, Pattern typePattern) {
* @param antigens Collection of antigens
* @return Sorted string of antigen strings
*/
public static <L extends Locus<L>, T extends Antigen<L, T>> String toString(Collection<T> antigens) {
public static <L extends Locus<L>, T extends Antigen<L, T>> String toString(
Collection<T> antigens) {
return antigens.stream().sorted().map(Antigen::toString).collect(Collectors.joining(", "))
.toString();
.toString();
}

/**
Expand Down Expand Up @@ -313,12 +319,12 @@ public static String sanitize(String antigenString) {
* B*2} would translate to {@code A*21:03, A*15, B*02}
* @param lociPattern A {@link Pattern} for parsing out the {@link Locus}
* @param typeParser Method for converting individual locus + spec string combinations to a
* particular type
* particular type
* @return A list of the <b>unique</b> and <b>non-null</b> antigens parsed from the text, in the
* order of their first appearance
*/
public static <T extends Antigen<?, T>> List<T> parseTypes(String text, Pattern lociPattern,
Function<String, T> typeParser) {
Function<String, T> typeParser) {
if (text == null || text.isEmpty()) {
return Collections.emptyList();
}
Expand Down Expand Up @@ -349,8 +355,8 @@ public static <T extends Antigen<?, T>> List<T> parseTypes(String text, Pattern
String locus = locusMap.get(locusStartPos);
// The current locus has a range to the start pos of the next locus, or the end of the string
// if this is the last locus.
int rangeEnd = locusIndex + 1 == locusStarts.size() ? text.length()
: locusStarts.get(locusIndex + 1);
int rangeEnd =
locusIndex + 1 == locusStarts.size() ? text.length() : locusStarts.get(locusIndex + 1);
// The search space substring is where we look for specs
String searchSpace = text.substring(locusStartPos + locus.length(), rangeEnd);
Matcher specMatcher = SPEC_PATTERN.matcher(searchSpace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public final class AntigenDictionary implements Serializable {
private final SetMultimap<SeroType, HLAType> seroDict;
private final Set<HLAType> validTypes;

private AntigenDictionary(
SetMultimap<HLAType, SeroType> hla, SetMultimap<SeroType, HLAType> sero, Set<HLAType> valid) {
private AntigenDictionary(SetMultimap<HLAType, SeroType> hla, SetMultimap<SeroType, HLAType> sero,
Set<HLAType> valid) {
hlaDict = hla;
seroDict = sero;
validTypes = valid;
Expand Down Expand Up @@ -164,12 +164,8 @@ private static void parseDictionaries() {
// NB: what's considered a valid HLA type diverges from the HLA map keyset and thus must be
// tracked separately
Builder<HLAType> validHLATypes = ImmutableSet.builder();
try (BufferedReader reader =
new BufferedReader(
new InputStreamReader(
AntigenDictionary.class
.getClassLoader()
.getResourceAsStream(MASTER_MAP_RECORDS))); ) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(
AntigenDictionary.class.getClassLoader().getResourceAsStream(MASTER_MAP_RECORDS)));) {
while (reader.ready()) {
// Read one mapping at a time
String line = reader.readLine();
Expand Down
16 changes: 4 additions & 12 deletions src/main/java/org/pankratzlab/unet/deprecated/hla/HLALocus.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,10 @@

/** {@link Locus} implementation for HLA types */
public enum HLALocus implements Locus<HLALocus> {
A(SeroLocus.A, TIER_1),
B(SeroLocus.B, TIER_1),
C(SeroLocus.C, TIER_1),
DRB1(SeroLocus.DRB, TIER_2),
DRB3(SeroLocus.DRB, TIER_2),
DRB4(SeroLocus.DRB, TIER_2),
DRB5(SeroLocus.DRB, TIER_2),
DQA1(SeroLocus.DQA, TIER_2),
DQB1(SeroLocus.DQB, TIER_2),
DPA1(SeroLocus.DPA, TIER_2),
DPB1(SeroLocus.DPB, TIER_2),
MICA(SeroLocus.MICA, TIER_2);
A(SeroLocus.A, TIER_1), B(SeroLocus.B, TIER_1), C(SeroLocus.C, TIER_1), DRB1(SeroLocus.DRB,
TIER_2), DRB3(SeroLocus.DRB, TIER_2), DRB4(SeroLocus.DRB, TIER_2), DRB5(SeroLocus.DRB,
TIER_2), DQA1(SeroLocus.DQA, TIER_2), DQB1(SeroLocus.DQB, TIER_2), DPA1(SeroLocus.DPA,
TIER_2), DPB1(SeroLocus.DPB, TIER_2), MICA(SeroLocus.MICA, TIER_2);

private final SeroLocus sero;
private final int tier;
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/org/pankratzlab/unet/deprecated/hla/HLAType.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ public class HLAType extends Antigen<HLALocus, HLAType> {
/**
* Matches string representations of {@link HLAType}s
*
* <p>Group 1 is the {@link HLALocus}, group 2 is the {@link #SPEC_DELIM}ited specification, and
* group 3 is the parent specification e.g. 2(5) (NB: group 0 is the complete match in the {@link
* Matcher#group(int)} api)
* <p>
* Group 1 is the {@link HLALocus}, group 2 is the {@link #SPEC_DELIM}ited specification, and
* group 3 is the parent specification e.g. 2(5) (NB: group 0 is the complete match in the
* {@link Matcher#group(int)} api)
*/
public static final Pattern TYPE_PATTERN;

Expand Down Expand Up @@ -84,9 +85,9 @@ public HLAType(HLALocus l, List<Integer> p) {
* Note: this method is similar to {@link AntigenDictionary#lookup(HLAType)}, with two exceptions:
*
* <ul>
* <li>In the case of multiple {@link SeroType} mappings, only the first will be returned
* <li>If there is no explicit mapping for this type, a {@code SeroType} will be created using
* the equivalent {@link SeroLocus} and the first value in this type's {@link #spec()}
* <li>In the case of multiple {@link SeroType} mappings, only the first will be returned
* <li>If there is no explicit mapping for this type, a {@code SeroType} will be created using the
* equivalent {@link SeroLocus} and the first value in this type's {@link #spec()}
* </ul>
*
* @return {@link SeroType} equivalent of this antigen
Expand Down Expand Up @@ -124,7 +125,7 @@ public SeroType equivSafe() {

/**
* @return The {@link SeroType} equivalent of this allele without a lookup in antigen equivalences
* table.
* table.
*/
public SeroType lowResEquiv() {
return new SeroType(locus().sero(), spec().get(0));
Expand Down Expand Up @@ -188,18 +189,17 @@ public static List<HLAType> parseTypes(String text) {
}

/** @see Antigen#parseTypes(String, java.util.regex.Pattern, Function) */
public static <T extends Antigen<?, T>> List<T> parseTypes(
String text, Function<String, T> typeFunction) {
public static <T extends Antigen<?, T>> List<T> parseTypes(String text,
Function<String, T> typeFunction) {
return Antigen.parseTypes(text, LOCI_PATTERN, typeFunction);
}

static {
// Static initializer to create patterns
// See also SeroType

LOCI_PATTERN =
makePattern(
Arrays.stream(HLALocus.values()).map(HLALocus::name).collect(Collectors.toList()));
LOCI_PATTERN = makePattern(
Arrays.stream(HLALocus.values()).map(HLALocus::name).collect(Collectors.toList()));

TYPE_PATTERN = Pattern.compile(LOCI_PATTERN.pattern() + SPEC_PATTERN.pattern());
PARTIAL_PATTERN =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public LabelledType(HLALocus parsedLocus, List<Integer> spec, char charAt) {
/** @return A {@link HLAType} representation of the given string */
public static LabelledType valueOf(String typeString) {
RawType rt = new RawType(typeString, TYPE_PATTERN);
return new LabelledType(
new HLAType(rt.locus(), rt.spec()), typeString.charAt(typeString.length() - 1));
return new LabelledType(new HLAType(rt.locus(), rt.spec()),
typeString.charAt(typeString.length() - 1));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,11 @@ public static void reportError(String error) {
}

public static void report(String error, AlertType alertType) {
Platform.runLater(
() -> {
Alert alert = new Alert(alertType);
alert.setHeaderText(error);
alert.showAndWait();
});
Platform.runLater(() -> {
Alert alert = new Alert(alertType);
alert.setHeaderText(error);
alert.showAndWait();
});
}

/**
Expand All @@ -77,24 +76,19 @@ public static void report(String error, AlertType alertType) {
* @param title Title to use on the dialog shown to the user
*/
public static void reportError(Throwable exc, String title) {
Platform.runLater(
() -> {
StringBuilder sb =
new StringBuilder(
"Please send the following to the developers:\n"
+ "- A screenshot of this error\n"
+ "- The input files (or MRN) that caused this error\n\n");
sb.append(exc.getClass());
sb.append(": ");
sb.append(exc.getMessage());
sb.append("\n");
sb.append(
Arrays.stream(exc.getStackTrace())
.map(StackTraceElement::toString)
.collect(Collectors.joining("\n")));
TextArea errorText = new TextArea(sb.toString());
errorText.setWrapText(true);
JFXUtilHelper.makeContentOnlyAlert(AlertType.ERROR, title, errorText).showAndWait();
});
Platform.runLater(() -> {
StringBuilder sb = new StringBuilder(
"Please send the following to the developers:\n" + "- A screenshot of this error\n"
+ "- The input files (or MRN) that caused this error\n\n");
sb.append(exc.getClass());
sb.append(": ");
sb.append(exc.getMessage());
sb.append("\n");
sb.append(Arrays.stream(exc.getStackTrace()).map(StackTraceElement::toString)
.collect(Collectors.joining("\n")));
TextArea errorText = new TextArea(sb.toString());
errorText.setWrapText(true);
JFXUtilHelper.makeContentOnlyAlert(AlertType.ERROR, title, errorText).showAndWait();
});
}
}
13 changes: 3 additions & 10 deletions src/main/java/org/pankratzlab/unet/deprecated/hla/SeroLocus.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,8 @@

/** {@link Locus} implementation for serological types */
public enum SeroLocus implements Locus<SeroLocus> {
A(2, TIER_1),
B(2, TIER_1),
C(3, TIER_1),
DRB(1, TIER_2, "DR"),
DQB(1, TIER_2, "DQ"),
DQA(1, TIER_2),
DPB(1, TIER_2, "DP"),
DPA(1, TIER_2),
MICA(1, -1);
A(2, TIER_1), B(2, TIER_1), C(3, TIER_1), DRB(1, TIER_2, "DR"), DQB(1, TIER_2, "DQ"), DQA(1,
TIER_2), DPB(1, TIER_2, "DP"), DPA(1, TIER_2), MICA(1, -1);

private final int severity;
private final int tier;
Expand All @@ -51,7 +44,7 @@ private SeroLocus(int severity, int tier, String... alias) {

/**
* @return Numeric priority indicating whether antigens on this locus should be preferred as
* unacceptable
* unacceptable
*/
public int priority() {
return severity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ public class SeroType extends Antigen<SeroLocus, SeroType> {
/**
* Matches string representations of {@link SeroType}s
*
* <p>Group 1 is the {@link SeroLocus}, group 2 is the {@link #SPEC_DELIM}ited specification, and
* group 3 is the parent specification e.g. 2(5) (NB: group 0 is the complete match in the {@link
* Matcher#group(int)} api)
* <p>
* Group 1 is the {@link SeroLocus}, group 2 is the {@link #SPEC_DELIM}ited specification, and
* group 3 is the parent specification e.g. 2(5) (NB: group 0 is the complete match in the
* {@link Matcher#group(int)} api)
*/
public static final Pattern TYPE_PATTERN;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ private JFXPropertyHelper() {
* Helper method to handle null checking when ORing two {@link ObservableBooleanValue}s.
*
* @return If {@code optional} is null, {@code reference} is returned. Otherwise a boolean OR
* binding combining the two individual booleans is created and returned.
* binding combining the two individual booleans is created and returned.
*/
public static ObservableBooleanValue orHelper(
@Nullable ObservableBooleanValue optional, ObservableBooleanValue reference) {
public static ObservableBooleanValue orHelper(@Nullable ObservableBooleanValue optional,
ObservableBooleanValue reference) {
if (optional == null) {
return reference;
}
return Bindings.or(optional, reference);
}

public static ObservableBooleanValue andHelper(
@Nullable ObservableBooleanValue optional, ObservableBooleanValue reference) {
public static ObservableBooleanValue andHelper(@Nullable ObservableBooleanValue optional,
ObservableBooleanValue reference) {
if (optional == null) {
return reference;
}
Expand Down
Loading

0 comments on commit c6084d9

Please sign in to comment.