Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class ComputeGCContent {
- private static double getGCContent(String dna) {
- int gc = 0;
- for (char symbol : dna.toCharArray()) {
- if (symbol == 'G' || symbol == 'C') {
- gc++;
- }
- }
- return (double) gc / dna.length() * 100;
- }
- public static void main(String[] args) throws IOException {
- Scanner in = new Scanner(new File("input.txt"));
- PrintWriter out = new PrintWriter("output.txt");
- String maxID = "";
- double maxGC = 0.0;
- while (in.hasNextLine()) {
- String currentID = in.nextLine();
- String currentDNA = "";
- while (in.hasNextLine() && !in.hasNext(">.*")) {
- currentDNA += in.nextLine();
- }
- double currentGC = getGCContent(currentDNA);
- if (currentGC > maxGC) {
- maxID = currentID;
- maxGC = currentGC;
- }
- }
- out.println(maxID + " " + maxGC);
- in.close();
- out.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement