Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed CrosscheckFingerprints hashing to linked hashing #1892

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/main/java/picard/fingerprint/CrosscheckFingerprints.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -645,8 +644,8 @@ private void remapFingerprints(final Map<FingerprintIdDetails, Fingerprint> fpMa
});

if (CollectionUtil.makeSet(resultingSamples.toArray(new String[0])).size() != resultingSamples.size()) {
final Set<String> duplicates = new HashSet<>();
final Set<String> unique = new HashSet<>();
final Set<String> duplicates = new LinkedHashSet<>();
final Set<String> unique = new LinkedHashSet<>();
resultingSamples.forEach(s -> {
if (unique.add(s)) {
duplicates.add(s);
Expand All @@ -658,7 +657,7 @@ private void remapFingerprints(final Map<FingerprintIdDetails, Fingerprint> fpMa
}

// replace samples with their mapped values:
final Set<FingerprintIdDetails> ids = new HashSet<>(fpMap.keySet());
final Set<FingerprintIdDetails> ids = new LinkedHashSet<>(fpMap.keySet());
ids.forEach(id -> {
// if sample isn't in sampleMap, leave it alone
if (!sampleMap.containsKey(id.sample)) {
Expand Down Expand Up @@ -699,7 +698,7 @@ private void remapFingerprintsFromFiles(final Map<FingerprintIdDetails, Fingerpr

final Map<String, List<FingerprintIdDetails>> fileFpDetailSetMap = fpMap.keySet().stream().collect(Collectors.groupingBy(s -> s.file));

final Map<String, String> fileSampleMap = new HashMap<>();
final Map<String, String> fileSampleMap = new LinkedHashMap<>();
// check that each file in the map points only to one sample
fileFpDetailSetMap.forEach((key, fingerprintIdDetails) -> {
final Set<String> samples = fingerprintIdDetails.stream().map(id -> id.sample).collect(Collectors.toSet());
Expand All @@ -721,8 +720,8 @@ private void remapFingerprintsFromFiles(final Map<FingerprintIdDetails, Fingerpr
});

if (CollectionUtil.makeSet(resultingSamples.toArray(new String[0])).size() != resultingSamples.size()) {
final Set<String> duplicates = new HashSet<>();
final Set<String> unique = new HashSet<>();
final Set<String> duplicates = new LinkedHashSet<>();
final Set<String> unique = new LinkedHashSet<>();
resultingSamples.forEach(s -> {
if (unique.add(s)) {
duplicates.add(s);
Expand All @@ -734,7 +733,7 @@ private void remapFingerprintsFromFiles(final Map<FingerprintIdDetails, Fingerpr
}

// replace samples with their mapped values:
final Set<FingerprintIdDetails> ids = new HashSet<>(fpMap.keySet());
final Set<FingerprintIdDetails> ids = new LinkedHashSet<>(fpMap.keySet());
ids.forEach(id -> {
// if sample isn't in sampleMap, leave it alone
if (!sampleMap.containsKey(id.file)) {
Expand Down Expand Up @@ -772,7 +771,7 @@ private Map<String, String> getStringStringMap(final File sampleMapFile, final S

private Map<Path, Path> getSamplePathToIndexMap(final File indexMapFile, final String inputArgumentName) {
final Map<String, String> indexStringMap = getStringStringMap(indexMapFile, inputArgumentName);
final HashMap<Path, Path> indexPathMap = new LinkedHashMap<Path, Path>();
final LinkedHashMap<Path, Path> indexPathMap = new LinkedHashMap<Path, Path>();
for (Map.Entry<String, String> entry: indexStringMap.entrySet()) {
final Path inputPath;
final Path indexPath;
Expand Down Expand Up @@ -931,7 +930,7 @@ private int checkFingerprintsBySample(final Map<FingerprintIdDetails, Fingerprin
final Map<String, FingerprintIdDetails> sampleToDetail1 = fingerprints1BySample.keySet().stream().collect(Collectors.toMap(id -> id.group, id -> id));
final Map<String, FingerprintIdDetails> sampleToDetail2 = fingerprints2BySample.keySet().stream().collect(Collectors.toMap(id -> id.group, id -> id));

Set<String> samples = new HashSet<>();
Set<String> samples = new LinkedHashSet<>();
samples.addAll(sampleToDetail1.keySet());
samples.addAll(sampleToDetail2.keySet());

Expand Down