-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiCharSearch.java
More file actions
59 lines (53 loc) · 2.21 KB
/
Copy pathMultiCharSearch.java
File metadata and controls
59 lines (53 loc) · 2.21 KB
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
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MultiCharSearch
{
public static void main(String[] args)
{
String filePath ="C:\\Users\\sami0\\OneDrive\\Documents\\Downloads\\KEGGdatabase.txt"; // Change this to the path of your file
String charactersToSearch = "agtc"; // Characters you want to search for
// Initialize counters for each character
int countA = 0, countT = 0, countC = 0, countG = 0;
try (BufferedReader br = new BufferedReader(new FileReader(filePath)))
{
String line;
Pattern pattern = Pattern.compile("[" + charactersToSearch + "]"); // Create regex pattern
while ((line = br.readLine()) != null)
{
Matcher matcher = pattern.matcher(line);
while (matcher.find())
{
char foundChar = matcher.group().charAt(0);
switch (foundChar)
{
case 'a': countA++; break;
case 't': countT++; break;
case 'c': countC++; break;
case 'g': countG++; break;
}
}
}
float totl=countA+countT+countC+countG;
float perA=(countA/totl)*100;
float perT=(countT/totl)*100;
float perC=(countC/totl)*100;
float perG=(countG/totl)*100;
// Display the count of each character
System.out.println("A content : " + countA );
System.out.println("A content(%) : " + perA + "%");
System.out.println("T content : " + countT );
System.out.println("T content(%) : " + perT + "%");
System.out.println("C content : " + countC );
System.out.println("C content(%) : " + perC + "%");
System.out.println("G content : " + countG );
System.out.println("G content(%) : " + perG + "%");
}
catch (IOException e)
{
e.printStackTrace();
}
}
}