-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexcelsheet.java
More file actions
122 lines (101 loc) · 4.38 KB
/
Copy pathexcelsheet.java
File metadata and controls
122 lines (101 loc) · 4.38 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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class excelsheet
{
public static void main(String[] args)
{
String csvFile = "KEGGresult.csv";
String filePath ="C:\\Users\\sami0\\OneDrive\\Documents\\Downloads\\KEGGdatabase.txt"; // 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, countat = 0, countgc = 0;
try (BufferedReader br = new BufferedReader(new FileReader(filePath)))
{
String line;
FileWriter writer = new FileWriter(csvFile);
writer.write("Sequence,Total content,A content,A content(%),T content,T content(%),C content,C content(%),G content,G content(%),No. of AT dimers,No. of GC dimers"+"\n"); // Writing the header
writer.write("\n");
String wordToFind1 = "at";
String regex1 = Pattern.quote(wordToFind1) ;
Pattern pattern1 = Pattern.compile(regex1);
String wordToFind2 = "gc";
String regex2 = Pattern.quote(wordToFind2) ;
Pattern pattern2 = Pattern.compile(regex2);
Pattern pattern = Pattern.compile("[" + charactersToSearch + "]"); // Create regex pattern
for(int i=1;i<=30;i++)
{
while ((line = br.readLine()) != null)
{
if (line.trim().isEmpty())
{
break;
}
Matcher matcher1 = pattern1.matcher(line);
while(matcher1.find())
{
countat++;
}
Matcher matcher2 = pattern2.matcher(line);
while(matcher2.find())
{
countgc++;
}
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 percentage of each character
System.out.println("Sequence "+i);
System.out.println("Total content : " + totl );
System.out.print("A content : " + counta+" " );
System.out.println("A content(%) : " + pera + "%");
System.out.print("T content : " + countt +" ");
System.out.println("T content(%) : " + pert + "%");
System.out.print("C content : " + countc +" ");
System.out.println("C content(%) : " + perc + "%");
System.out.print("G content : " + countt +" ");
System.out.println("G content(%) : " + perg + "%");
System.out.println("No. of AT dimers : " + countat );
System.out.println("No. of GC dimers : " + countgc );
System.out.println();
// Writing data rows
writer.write(i+","+totl+","+counta+","+pera+","+countt+","+pert+","+countc+","+perc+","+countg+","+perg+","+countat+","+countgc+"\n");
writer.write("\n");
counta = 0;
countt = 0;
countc = 0;
countg = 0;
countat = 0;
countgc = 0;
}
System.out.println("Excel File successfully created");
writer.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}