public static void main(String[] args) { getFile(); if (fastaFile != null) { totalCount = countBase(getSequence(fastaFile), 'A') + countBase(getSequence(fastaFile), 'G') + countBase(getSequence(fastaFile), 'C') + countBase(getSequence(fastaFile), 'T'); System.out.println(getHeader(fastaFile)); System.out.printf("A: == (%1$1.0f%%)\r\n", (float) (countBase( getSequence(fastaFile), 'A') / totalCount) * 100); } else { System.out.println("Invalid FASTA file chosen."); } }
getFile(); - This just prompts the user to input the FASTA file.
countBase(String sequence, char base); - This returns how many times the char base appears in the sequence.
getSequence(File file); - This returns a certain part of the file (a String).
My issue is this line:
System.out.printf("A: == (%1$1.0f%%)\r\n", (float) (countBase( getSequence(fastaFile), 'A') / totalCount) * 100);
I need it to print it out like: A: == (45%), A: == (37%) etc. For some reason it keeps returning 0%. Though when I do a test for the countBase(); return for 'A', it tells me there are 242 character A's in the total count (which in this case is 511) which is (I did this via calculator: count / total * 100 - what I am trying to do but it isn't working) 47%. My question is how can I fix the above line to do that for me?
Thanks.