Skip to content

Commit

Permalink
Merge pull request #73 from waterflow80/update-comparison-format
Browse files Browse the repository at this point in the history
updated the comparison function format
  • Loading branch information
waterflow80 authored Jan 8, 2024
2 parents ff31f18 + e98c976 commit ca90fc9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import lombok.Data;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.Map;

@Data
public class SeqColComparisonResultEntity {
Expand All @@ -17,23 +17,24 @@ public class SeqColComparisonResultEntity {
private SortedMap<String, String> digests;

/**
* The "arrays" attribute contains three sub-attributes:
* The "attributes" attribute contains three sub-attributes:
* "a_only", "b_only", "a_and_b"*/
private SortedMap<String, List<String>> arrays;
private SortedMap<String, List<String>> attributes;

/**
* The "elements" attribute contains three sub-attributes:
* "total", "a_and_b", "a_and_b_same_order"*/
private SortedMap<String, SortedMap<String, Object>> elements; // The object can be either Integer or Boolean
* The "array_elements" attribute contains four sub-attributes:
* "a_count", "b_count", "a_and_b_count", "a_and_b_same_order"*/
private HashMap<String, TreeMap<String, Object>> array_elements; // The object can be either Integer or Boolean


public SeqColComparisonResultEntity() {
this.digests = new TreeMap<>();
this.arrays = new TreeMap<>();
this.elements = new TreeMap<>();
elements.put("total", new TreeMap<>());
elements.put("a_and_b", new TreeMap<>());
elements.put("a_and_b_same_order", new TreeMap<>());
this.attributes = new TreeMap<>();
this.array_elements = new LinkedHashMap<>();
array_elements.put("a_count", new TreeMap<>());
array_elements.put("b_count", new TreeMap<>());
array_elements.put("a_and_b_count", new TreeMap<>());
array_elements.put("a_and_b_same_order", new TreeMap<>());

}

Expand All @@ -45,11 +46,11 @@ public void putIntoDigests(String seqColId, String digest) {
}

public void putIntoArrays(String key, List<String> value) {
arrays.put(key, value);
attributes.put(key, value);
}

public void putIntoElements(String elementName,String key, Object value) {
SortedMap<String, Object> elementsMap = elements.get(elementName);
elementsMap.put(key, value);
public void putIntoArrayElements(String elementName, String key, Object value) {
SortedMap<String, Object> arrayElementsMap = array_elements.get(elementName);
arrayElementsMap.put(key, value);
}
}
26 changes: 16 additions & 10 deletions src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColService.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,27 +312,33 @@ public SeqColComparisonResultEntity compareSeqCols(
comparisonResult.putIntoArrays("b_only", seqColBUniqueAttributes);
comparisonResult.putIntoArrays("a_and_b", seqColCommonAttributes);

// "elements" attribute | "total"
Integer seqColATotal = seqColAEntityMap.get("lengths").size();
Integer seqColBTotal = seqColBEntityMap.get("lengths").size();
comparisonResult.putIntoElements("total", "a", seqColATotal);
comparisonResult.putIntoElements("total", "b", seqColBTotal);
// "array_elements" attribute | "a"
for (String attribute: seqColAAttributeSet) {
// Looping through each attribute of seqcolA, Eg: "sequences", "lengths", etc...
comparisonResult.putIntoArrayElements("a_count", attribute, seqColAEntityMap.get(attribute).size());
}

// "array_elements" attribute | "b"
for (String attribute: seqColBAttributeSet) {
// Looping through each attribute of seqcolB, Eg: "sequences", "lengths", etc...
comparisonResult.putIntoArrayElements("b_count", attribute, seqColBEntityMap.get(attribute).size());
}

// "elements" attribute | "a_and_b"
// "array_elements" attribute | "a_and_b"
List<String> commonSeqColAttributesValues = getCommonElementsDistinct(seqColAAttributesList, seqColBAttributesList); // eg: ["sequences", "lengths", ...]
for (String element: commonSeqColAttributesValues) {
Integer commonElementsCount = getCommonElementsCount(seqColAEntityMap.get(element), seqColBEntityMap.get(element));
comparisonResult.putIntoElements("a_and_b", element, commonElementsCount);
comparisonResult.putIntoArrayElements("a_and_b_count", element, commonElementsCount);
}

// "elements" attribute | "a_and_b_same_order"
// "array_elements" attribute | "a_and_b_same_order"
for (String attribute: commonSeqColAttributesValues) {
if (lessThanTwoOverlappingElements(seqColAEntityMap.get(attribute), seqColBEntityMap.get(attribute))
|| unbalancedDuplicatesPresent(seqColAEntityMap.get(attribute), seqColBEntityMap.get(attribute))){
comparisonResult.putIntoElements("a_and_b_same_order", attribute, null);
comparisonResult.putIntoArrayElements("a_and_b_same_order", attribute, null);
} else {
boolean attributeSameOrder = check_A_And_B_Same_Order(seqColAEntityMap.get(attribute), seqColBEntityMap.get(attribute));
comparisonResult.putIntoElements("a_and_b_same_order", attribute, attributeSameOrder);
comparisonResult.putIntoArrayElements("a_and_b_same_order", attribute, attributeSameOrder);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ void compareLocalSeqColsTest() {
Map<String, Object> comparisonResult = restTemplate.getForObject(finalRequest, Map.class);
assertNotNull(comparisonResult);
assertNotNull(comparisonResult.get("digests"));
assertNotNull(comparisonResult.get("arrays"));
assertNotNull(comparisonResult.get("elements"));
assertNotNull(comparisonResult.get("attributes"));
assertNotNull(comparisonResult.get("array_elements"));
}

@Test
Expand All @@ -97,7 +97,7 @@ void compareALocalSeqColWithProvidedOneTest() {
Map<String, Object> comparisonResult = restTemplate.postForObject(finlRequest, seqColLevelTwoPostBody, Map.class);
assertNotNull(comparisonResult);
assertNotNull(comparisonResult.get("digests"));
assertNotNull(comparisonResult.get("arrays"));
assertNotNull(comparisonResult.get("elements"));
assertNotNull(comparisonResult.get("attributes"));
assertNotNull(comparisonResult.get("array_elements"));
}
}

0 comments on commit ca90fc9

Please sign in to comment.