Skip to content

Commit d877aac

Browse files
SilinPavelZaal Lyanov
authored andcommitted
style -> java 1.8
1 parent 6698c83 commit d877aac

File tree

3 files changed

+23
-35
lines changed

3 files changed

+23
-35
lines changed

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
apply plugin: 'java'
22
apply plugin:'application'
33

4-
version = '1.4.7'
4+
version = '1.4.8'
55

66

77
repositories {
88
mavenCentral()
99
}
1010

11-
targetCompatibility = "1.7"
12-
sourceCompatibility = "1.7"
11+
targetCompatibility = "1.8"
12+
sourceCompatibility = "1.8"
1313

1414

1515
afterEvaluate {

dist/VarDict-1.4.8.zip

1.6 MB
Binary file not shown.

src/main/java/com/astrazeneca/vardict/VarDict.java

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,40 +31,28 @@ public class VarDict {
3131
final static Pattern SN = Pattern.compile("\\s+SN:(\\S+)");
3232
final static Pattern LN = Pattern.compile("\\sLN:(\\d+)");
3333

34-
private static ThreadLocal<Map<String, SamReader>> threadReaders = new ThreadLocal<Map<String, SamReader>>() {
35-
@Override
36-
protected Map<String, SamReader> initialValue() {
37-
return new HashMap<>();
38-
}
39-
};
34+
private static ThreadLocal<Map<String, SamReader>> threadLocalSAMReaders = ThreadLocal.withInitial(HashMap::new);
4035

41-
synchronized private static SamReader grabReader(String file, ValidationStringency stringency) {
42-
final Map<String, SamReader> fileReaders = threadReaders.get();
43-
if (!fileReaders.containsKey(file)) {
44-
SamReader reader = SamReaderFactory.makeDefault().validationStringency(stringency).open(SamInputResource.of(file));
45-
fileReaders.put(file, reader);
46-
}
47-
return fileReaders.get(file);
36+
synchronized private static SamReader fetchReader(String file, ValidationStringency stringency) {
37+
return threadLocalSAMReaders.get().computeIfAbsent(
38+
file,
39+
(f) -> SamReaderFactory.makeDefault().validationStringency(stringency).open(SamInputResource.of(f))
40+
);
4841
}
4942

50-
private static ThreadLocal<Map<String, IndexedFastaSequenceFile>> threaFasta = new ThreadLocal<Map<String, IndexedFastaSequenceFile>>() {
51-
@Override
52-
protected Map<String, IndexedFastaSequenceFile> initialValue() {
53-
return new HashMap<>();
54-
}
55-
};
43+
private static ThreadLocal<Map<String, IndexedFastaSequenceFile>> threadLocalFastaFiles = ThreadLocal.withInitial(HashMap::new);
5644

57-
synchronized private static IndexedFastaSequenceFile grabFasta(String file) {
58-
final Map<String, IndexedFastaSequenceFile> fileReaders = threaFasta.get();
59-
if (!fileReaders.containsKey(file)) {
60-
try {
61-
IndexedFastaSequenceFile fasta = new IndexedFastaSequenceFile(new File((file)));
62-
fileReaders.put(file, fasta);
63-
} catch (FileNotFoundException e) {
64-
e.printStackTrace();
65-
}
66-
}
67-
return fileReaders.get(file);
45+
synchronized private static IndexedFastaSequenceFile fetchFasta(String file) {
46+
return threadLocalFastaFiles.get().computeIfAbsent(
47+
file,
48+
(f) -> {
49+
try {
50+
return new IndexedFastaSequenceFile(new File((f)));
51+
} catch (FileNotFoundException e) {
52+
throw new IllegalArgumentException("Couldn't open reference file: " + f, e);
53+
}
54+
}
55+
);
6856
}
6957

7058
public static void start(Configuration conf) throws IOException {
@@ -1060,7 +1048,7 @@ static void vardict(Region region, Map<Integer, Vars> vars, String sample, Set<S
10601048
}
10611049

10621050
private static String[] retriveSubSeq(String fasta, String chr, int start, int end) throws IOException {
1063-
IndexedFastaSequenceFile idx = grabFasta(fasta);
1051+
IndexedFastaSequenceFile idx = fetchFasta(fasta);
10641052
ReferenceSequence seq = idx.getSubsequenceAt(chr, start, end);
10651053
byte[] bases = seq.getBases();
10661054
return new String[] { ">" + chr + ":" + start + "-" + end, bases != null ? new String(bases) : "" };
@@ -1370,7 +1358,7 @@ private static class SamView implements AutoCloseable {
13701358

13711359
public SamView(String file, String samfilter, Region region, ValidationStringency stringency) {
13721360

1373-
iterator = grabReader(file, stringency)
1361+
iterator = fetchReader(file, stringency)
13741362
.queryOverlapping(region.chr, region.start, region.end);
13751363
if (!"".equals(samfilter)) {
13761364
filter = Integer.decode(samfilter);

0 commit comments

Comments
 (0)