Created
August 7, 2014 15:35
-
-
Save dahankzter/03991c3c5eb942d32a4f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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