MCPcopy Index your code
hub / github.com/apache/groovy / knucleotide

Class knucleotide

benchmark/bench/knucleotide.java:11–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9import java.util.concurrent.*;
10
11public class knucleotide {
12 String sequence;
13 int count = 1;
14
15 knucleotide(String sequence) {
16 this.sequence = sequence;
17 }
18
19 static ArrayList<Callable< Map<String, knucleotide> > > createFragmentTasks(final String sequence, int[] fragmentLengths) {
20 ArrayList<Callable<Map<String, knucleotide>>> tasks = new ArrayList<Callable<Map<String, knucleotide>>>();
21 for (int fragmentLength : fragmentLengths) {
22 for (int index=0; index<fragmentLength; index++) {
23 final int offset = index;
24 final int finalFragmentLength = fragmentLength;
25 tasks.add(new Callable<Map<String, knucleotide>>() {
26 public Map<String, knucleotide> call() {
27 return createFragmentMap(sequence, offset, finalFragmentLength);
28 }
29 });
30 }
31 }
32 return tasks;
33 }
34
35 static Map<String, knucleotide> createFragmentMap(String sequence, int offset, int fragmentLength) {
36 HashMap<String, knucleotide> map = new HashMap<String, knucleotide>();
37 int lastIndex = sequence.length() - fragmentLength + 1;
38 for (int index=offset; index<lastIndex; index+=fragmentLength) {
39 String temp = sequence.substring(index, index + fragmentLength);
40 knucleotide fragment = (knucleotide)map.get(temp);
41 if (fragment != null)
42 fragment.count++;
43 else
44 map.put(temp, new knucleotide(temp));
45 }
46
47 return map;
48 }
49
50 // Destructive!
51 static Map<String, knucleotide> sumTwoMaps(Map<String, knucleotide> map1, Map<String, knucleotide> map2) {
52 for (Map.Entry<String, knucleotide> entry : map2.entrySet()) {
53 knucleotide sum = (knucleotide)map1.get(entry.getKey());
54 if (sum != null)
55 sum.count += entry.getValue().count;
56 else
57 map1.put(entry.getKey(), entry.getValue());
58 }
59 return map1;
60 }
61
62 static String writeFrequencies(Map<String, knucleotide> frequencies) {
63 ArrayList<knucleotide> list = new ArrayList<knucleotide>(frequencies.size());
64 int sum = 0;
65 for (knucleotide fragment : frequencies.values()) {
66 list.add(fragment);
67 sum += fragment.count;
68 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…