Skip to content

Commit

Permalink
ALS-4461: Remove IOExceptions thrown from FBBIS
Browse files Browse the repository at this point in the history
  • Loading branch information
ramari16 committed Aug 9, 2023
1 parent 88ea1c2 commit df03002
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public abstract class FileBackedByteIndexedStorage <K, V extends Serializable> i
protected ConcurrentHashMap<K, Long[]> index;
protected File storageFile;
protected boolean completed = false;
protected Long maxStorageSize; //leave this in to not break serialization


public FileBackedByteIndexedStorage(Class<K> keyClass, Class<V> valueClass, File storageFile) throws FileNotFoundException {
Expand All @@ -34,7 +33,7 @@ public Set<K> keys(){
return index.keySet();
}

public void put(K key, V value) throws IOException {
public void put(K key, V value) {
if(completed) {
throw new RuntimeException("A completed FileBackedByteIndexedStorage cannot be modified.");
}
Expand All @@ -47,6 +46,8 @@ public void put(K key, V value) throws IOException {
storage.write(out.toByteArray());
recordIndex[1] = storage.getFilePointer() - recordIndex[0];
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
index.put(key, recordIndex);
}
Expand All @@ -72,9 +73,6 @@ public void complete() {
this.completed = true;
}

public boolean isComplete() {
return this.completed;
}
public V get(K key) {
try {
if(this.storage==null) {
Expand Down Expand Up @@ -109,7 +107,7 @@ public V get(K key) {

protected abstract ByteArrayOutputStream writeObject(V value) throws IOException;

public V getOrELse(K key, V defaultValue) throws IOException {
public V getOrELse(K key, V defaultValue) {
V result = get(key);
return result == null ? defaultValue : result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,8 @@ public BucketIndexBySample(VariantStore variantStore, String storageDir) throws

int[] processedPatients = new int[1];
patientIds.parallelStream().forEach((patientId)->{
try {
BigInteger patientMask = new BigInteger(new String(patientBucketCharMasks[patientIds.indexOf(patientId)]),2);
patientBucketMasks.put(patientId, patientMask);
}catch(NumberFormatException e) {
log.error("NFE caught for " + patientId, e);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
BigInteger patientMask = new BigInteger(new String(patientBucketCharMasks[patientIds.indexOf(patientId)]),2);
patientBucketMasks.put(patientId, patientMask);
processedPatients[0] += 1;
int processedPatientsCount = processedPatients[0];
if (processedPatientsCount % 1000 == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private Map<String, FileBackedByteIndexedInfoStore> loadInfoStores(String direct
infoStores.put(filename.replace("_infoStore.javabin", ""), infoStore);
ois.close();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
});
}
Expand Down Expand Up @@ -192,34 +192,30 @@ public FileBackedJsonIndexStorage<Integer, ConcurrentHashMap<String, VariantMask

FileBackedJsonIndexStorage<Integer, ConcurrentHashMap<String, VariantMasks>> merged = new FileBackedStorageVariantMasksImpl(new File(outputDirectory + chromosome + "masks.bin"));
variantMaskStorage1.keys().forEach(key -> {
try {
Map<String, VariantMasks> masks1 = variantMaskStorage1.get(key);
Map<String, VariantMasks> masks2 = variantMaskStorage2.get(key);
if (masks2 == null) {
masks2 = Map.of();
}
Map<String, VariantMasks> masks1 = variantMaskStorage1.get(key);
Map<String, VariantMasks> masks2 = variantMaskStorage2.get(key);
if (masks2 == null) {
masks2 = Map.of();
}

ConcurrentHashMap<String, VariantMasks> mergedMasks = new ConcurrentHashMap<>();
for (Map.Entry<String, VariantMasks> entry : masks1.entrySet()) {
VariantMasks variantMasks2 = masks2.get(entry.getKey());
if (variantMasks2 == null) {
// this will have all null masks, which will result in null when
// appended to a null, or be replaced with an empty bitmask otherwise
variantMasks2 = new VariantMasks();
}
mergedMasks.put(entry.getKey(), append(entry.getValue(), variantMasks2));
ConcurrentHashMap<String, VariantMasks> mergedMasks = new ConcurrentHashMap<>();
for (Map.Entry<String, VariantMasks> entry : masks1.entrySet()) {
VariantMasks variantMasks2 = masks2.get(entry.getKey());
if (variantMasks2 == null) {
// this will have all null masks, which will result in null when
// appended to a null, or be replaced with an empty bitmask otherwise
variantMasks2 = new VariantMasks();
}
// Any entry in the second set that is not in the merged set can be merged with an empty variant mask,
// if there were a corresponding entry in set 1, it would have been merged in the previous loop
for (Map.Entry<String, VariantMasks> entry : masks2.entrySet()) {
if (!mergedMasks.containsKey(entry.getKey())) {
mergedMasks.put(entry.getKey(), append(new VariantMasks(), entry.getValue()));
}
mergedMasks.put(entry.getKey(), append(entry.getValue(), variantMasks2));
}
// Any entry in the second set that is not in the merged set can be merged with an empty variant mask,
// if there were a corresponding entry in set 1, it would have been merged in the previous loop
for (Map.Entry<String, VariantMasks> entry : masks2.entrySet()) {
if (!mergedMasks.containsKey(entry.getKey())) {
mergedMasks.put(entry.getKey(), append(new VariantMasks(), entry.getValue()));
}
merged.put(key, mergedMasks);
} catch (IOException e) {
throw new RuntimeException(e);
}
merged.put(key, mergedMasks);
});

ConcurrentHashMap<String, VariantMasks> mergedMasks = new ConcurrentHashMap<>();
Expand Down

0 comments on commit df03002

Please sign in to comment.