Skip to content

Commit

Permalink
Deleting outdated .gridsscache files
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Cameron committed May 21, 2021
1 parent b92f08e commit f6c6bfe
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*
*/
public class TwoBitBufferedReferenceSequenceFile implements ReferenceSequenceFile, ReferenceLookup {
private static final long serialVersionUID = -8769790295923840212L;
private static final Log log = Log.getInstance(TwoBitBufferedReferenceSequenceFile.class);
private final ReferenceSequenceFile underlying;
private final PackedReferenceSequence[] referenceIndexLookup;
Expand Down Expand Up @@ -47,19 +48,24 @@ public byte getBase(int referenceIndex, int position) {
}
return seq.get(position - 1);
}
public synchronized void load(File file) {
public synchronized boolean load(File file) {
ImmutableMap.Builder<String, PackedReferenceSequence> builder = ImmutableMap.<String, PackedReferenceSequence>builder();
try(FileInputStream fis = new FileInputStream(file)) {
try(ObjectInputStream ois = new ObjectInputStream(fis)) {
for (int i = 0; i < referenceIndexLookup.length; i++) {
referenceIndexLookup[i] = (PackedReferenceSequence)ois.readObject();
try (ObjectInputStream ois = new ObjectInputStream(fis)) {
for (int i = 0; i < referenceIndexLookup.length; i++) {
referenceIndexLookup[i] = (PackedReferenceSequence) ois.readObject();
builder.put(referenceIndexLookup[i].name, referenceIndexLookup[i]);
}
}
cache = builder.build();
return true;
} catch (java.io.InvalidClassException e) {
log.info("Deleting out of date cache file " + file);
file.delete();
} catch (Exception e) {
log.error("Error loading reference genome from cache " + file, e);
}
return false;
}
public synchronized void save(File file) {
if (file.exists()) {
Expand Down Expand Up @@ -152,8 +158,12 @@ private synchronized PackedReferenceSequence addToCache(String contig) {
if (cacheFile != null) {
if (cacheFile.exists()) {
log.info("Loading reference genome from cache " + cacheFile);
load(cacheFile);
log.info("Loading reference genome complete");
boolean loadStatus = load(cacheFile);
if (loadStatus) {
log.info("Loading reference genome complete");
} else {
log.info("Failed to load reference genome from cache file.");
}
} else {
if (!cacheFile.getParentFile().canWrite()) {
log.warn("Cannot write to " + cacheFile + " not persisting 2bit compressed reference genome cache");
Expand Down

0 comments on commit f6c6bfe

Please sign in to comment.