-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCgRatio.java
93 lines (86 loc) · 2.65 KB
/
CgRatio.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* Write a description of CgRatio here.
*
* @author (your name)
* @version (a version number or a date)
*/
import edu.duke.*;
import java.io.*;
public class CgRatio {
public double countCg(String dna){
int cIndex = dna.indexOf("c",0);
int countC = 0;
while(cIndex != -1){
countC++;
cIndex = dna.indexOf("c",cIndex+1);
}
int gIndex = dna.indexOf("g",0);
int countG = 0;
while(gIndex != -1){
countG++;
gIndex = dna.indexOf("g",gIndex+1);
}
System.out.println(countC);
System.out.println(countG);
return (double)countC/countG;
}
public int countCTG(String dna){
int ctgIndex = dna.indexOf("ctg",0);
int count = 0;
while(ctgIndex != -1){
count++;
ctgIndex = dna.indexOf("ctg",ctgIndex+3);
}
return count;
}
public void processGenes(StorageResource sr){
int count = 0;
//finding gene with lenght greater than 9
for(String s : sr.data()){
if(s.length()>9){
System.out.println(s);
count++;
}
}
System.out.println(
"The number of gene with greater than Nine is "+count);
//findding the gene with the cg ratio greater than 0.35;
count =0;
for(String s: sr.data()){
double cg = countCg(s);
if(cg>0.35){
System.out.println(s);
count++;
}
}
System.out.println(
"The gene with CG-Ration greater than 0.35 is "+count);
//finding the longest gene
int geneLongest =0;
for(String s: sr.data()){
int currLength = s.length();
if(geneLongest==0){
geneLongest = currLength;
}
else{
if(currLength>geneLongest){
geneLongest = currLength;
}
else{
System.out.println(s);
}
}
}
}
public void test(){
URLResource page =
new URLResource("https://users.cs.duke.edu/~rodger/GRch38dnapart.fa");
String source = page.asString();
double cIndex =
countCg("cccatggggttctgtaaataactgcctagataataggagagagagagagactgttt");
int count =
countCTG("cccatggggttctgcttaaataactgcctagataataggagagagagagagactgttt");
System.out.println(cIndex);
System.out.println("ctgratio " +count);
}
}