Skip to content

Instantly share code, notes, and snippets.

@dahankzter
Created August 7, 2014 15:35
Show Gist options
  • Save dahankzter/03991c3c5eb942d32a4f to your computer and use it in GitHub Desktop.
Save dahankzter/03991c3c5eb942d32a4f to your computer and use it in GitHub Desktop.
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import java.util.stream.Collectors;
import static java.nio.file.Files.lines;
import static java.util.stream.Collectors.groupingBy;
public class gc_count {
public static boolean accept(int value) {
if (value == 'C' || value == 'G') {
return true;
} else if (value == 'A' || value == 'T') {
return true;
}
return false;
}
public static void main(String... args) throws IOException {
long start = System.currentTimeMillis();
Path path = Paths.get("Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa");
Map<Integer,Long> result = lines(path).map(line -> line)
.collect(Collectors.joining("")).chars().
filter(c -> accept(c)).boxed().
collect(groupingBy(Integer::intValue, Collectors.counting()));
long at = result.get(65) + result.get(84);
long gc = result.get(67) + result.get(71);
System.out.printf("GC count %f\n", gc / (double) (at + gc));
System.out.printf("Elapsed %d ms\n", System.currentTimeMillis() - start);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment