-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathInseed_matching_features.java
More file actions
260 lines (235 loc) · 11.4 KB
/
Inseed_matching_features.java
File metadata and controls
260 lines (235 loc) · 11.4 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package new_datasetsmall;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import jxl.write.WriteException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
//Added
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
//added
import java.io.FileWriter;
import com.csvreader.CsvWriter;
//import java.io.IOExceptio;
/**
*
* @author alisha
*/
public class new_datasetsmall {
public static void main(String[] args) throws IOException, WriteException {
String Path_in = "/home/alisha/Downloads/Final Updated Code+ Libraries/in_positive/";// give the input foleder path
String Path_out = "/home/alisha/Downloads/Final Updated Code+ Libraries/pos_out_lowercase/";// give the output folder path
File folder = new File(Path_in);
File[] listOfFiles = folder.listFiles();
FileWriter writer = null;
for (int f = 0; f < listOfFiles.length; f++) {
System.out.println("Start " + listOfFiles[f].getName());
//if (listOfFiles[f].getName().equalsIgnoreCase("positive0")) {
// Workbook workbook = new SXSSFWorkbook();
//Sheet sheet = workbook.createSheet("Datatypes in Java");
//int rowNum = 0;
CsvWriter csvOutput = new CsvWriter(new FileWriter(Path_out + listOfFiles[f].getName().replace(".fasta", ".csv"),true),',');
// TODO code application logic here
BufferedReader br = null;
FileReader fr = null;
br = new BufferedReader(new FileReader(Path_in + listOfFiles[f].getName()));
//int i = 0;
String sCurrentLine = null;
String miRNA = null;
String Mrna = null;
String Rvalue = null;
String R = null;
int match = 0;
int mismatch =0;
int othermismatch = 0;
int N_AU =0;
int N_GC = 0;
int N_UG = 0;
ArrayList<String> features = new ArrayList<String>();
int n_feat = 0;
int flag1 = 0;
int flag2 = 0;
csvOutput.write("miRNA");
csvOutput.write("Mrna");
csvOutput.write("R");
csvOutput.write("Total-Matches");
csvOutput.write("Total-Mismatces");
csvOutput.write("Total-gc");
csvOutput.write("Total-au");
csvOutput.write("Total-ug");
csvOutput.write("Total-Othermismatces");
csvOutput.endRecord();
while ((sCurrentLine = br.readLine()) != null) {
if (sCurrentLine.contains(">hsa-miR-")) {
String[] temp = sCurrentLine.split("\\s+");
miRNA = temp[0].replaceAll(">", "").trim();
Mrna = temp[1].trim();
flag1 = 1;
// Rvalue.add(temp[2].replaceAll("R:", "").trim());
}else if(sCurrentLine.contains("Forward:")){
R = sCurrentLine;
//System.out.println(R);
R = R.replaceAll(" Forward: Score: ","");
R = R.replaceAll("Q:", "");
R = R.replaceAll("R:", "");
R = R.replaceAll("Align Len ", "");
//System.out.println(R);
R = R.replaceAll("Energy:", "");
//System.out.println(R);
R = R.substring(21);
R = R.replaceAll("to", "");
String[] temp1 = R.split("\\s+");
R = temp1[0].trim()+" "+"to"+" "+temp1[1].trim();
} else if (sCurrentLine.contains("Ref: 5' ")) {
String ref = sCurrentLine;
sCurrentLine = br.readLine();
sCurrentLine = br.readLine();
String query = sCurrentLine;
ref = ref.replaceAll("Ref: 5'", "");
ref = ref.replaceAll("3'", "");
ref = ref.trim();
ref = ref.replaceAll("[A-Z]", "");
ref = ref.replaceAll("[\\-]", "");
ref = ref.trim();
query = query.replaceAll("Query: 3'", "");
query = query.replaceAll("5'", "");
query = query.trim();
query = query.replaceAll("[A-Z]", "");
query = query.replaceAll("-", "");
query = query.trim();
System.out.println("Ref " + ref + " " + query);
// System.out.println(R);
int start = 0;
if (ref.length() == query.length()) {
start = ref.length();
}
/* //features.add(new ArrayList<String>());
int start = -1;
int end = -1;
if (ref.length() == query.length()) {
start = ref.length() - 1;
end = 0;
} else if (ref.length() > query.length()) {
int mis = ref.length() - query.length();
for (int i = 0; i < mis; i++) {
query = "*" + query;
}
start = ref.length() - 1;
end = mis;
}*/
for (int i = 0; i < start; i++) {
if (!ref.isEmpty() && !query.isEmpty()) {
//System.out.println("Length "+ref.length());
//int temp_num = Integer.parseInt(temp[i].trim());
String feat_temp = "";
feat_temp = "" + ref.charAt(i) + query.charAt(i);
//feat_temp=feat_temp+;
features.add(feat_temp);
//System.out.println(feat_temp);
}
}
flag2 = 1;
}
if (flag1 == 1 && flag2 == 1) {
// int colNum = 0;
/* Row row = sheet.createRow(rowNum++);
int colNum = 0;
Cell cell = row.createCell(colNum++);
cell.setCellValue((String) miRNA);
cell = row.createCell(colNum++);
cell.setCellValue((String) Mrna);*/
csvOutput.write(miRNA);
csvOutput.write(Mrna);
//setting up extra condition to check array boundary indices//
for (int j = 0; j < features.size(); j++) {
String feat_temp = features.get(j);
//double feat_num = -2;
if (feat_temp.contentEquals("at") || feat_temp.contentEquals("gc")||feat_temp.contentEquals("ta") || feat_temp.contentEquals("cg")) {
match++;
if(feat_temp.contentEquals("gc")||feat_temp.contentEquals("cg")){
N_GC++;
}
// feat_num = 1;
} else if (feat_temp.contentEquals("au") || feat_temp.contentEquals("ug")) {
//feat_num = 2;
if(feat_temp.contentEquals("ug")||feat_temp.contentEquals("gu")){
N_UG++;
}
if (feat_temp.contentEquals("au")||feat_temp.contentEquals("ua")){
N_AU++;
}
} else if (feat_temp.contentEquals("gt") || feat_temp.contentEquals("tc") || feat_temp.contentEquals("ag") || feat_temp.contentEquals("ac")
|| feat_temp.contentEquals("tu") || feat_temp.contentEquals("cu")||feat_temp.contentEquals("tg") || feat_temp.contentEquals("ct") || feat_temp.contentEquals("ga") || feat_temp.contentEquals("ca")
|| feat_temp.contentEquals("ut") || feat_temp.contentEquals("uc")) {
//feat_num = 0;
mismatch++;
} else if (feat_temp.contentEquals("aa") || feat_temp.contentEquals("tt") || feat_temp.contentEquals("gg") || feat_temp.contentEquals("cc")) {
// feat_num = 0;
othermismatch++;
} else if (feat_temp.contentEquals("A-") || feat_temp.contentEquals("T-") || feat_temp.contentEquals("G-") || feat_temp.contentEquals("C-")) {
// feat_num = -1;
}
}
/* cell = row.createCell(colNum++);
cell.setCellValue((String) R);
cell = row.createCell(colNum++);
cell.setCellValue((int) match);
cell = row.createCell(colNum++);
cell.setCellValue((int) mismatch);
cell = row.createCell(colNum++);
cell.setCellValue((int) N_AU);
cell = row.createCell(colNum++);
cell.setCellValue((int) N_GC);*/
csvOutput.write(R);
csvOutput.write(String.valueOf(match));
csvOutput.write(String.valueOf(mismatch));
csvOutput.write(String.valueOf(N_GC));
csvOutput.write(String.valueOf(N_AU));
csvOutput.write(String.valueOf(N_UG));
csvOutput.write(String.valueOf(othermismatch));
//Start valaues (Again Loop)
//End Values
csvOutput.endRecord();
features.clear();
flag1 = 0;
flag2 = 0;
match =0;
mismatch = 0;
othermismatch = 0;
N_UG = 0;
N_AU =0;
N_GC = 0;
n_feat++;
}
if (n_feat == 22704425) {
break;
}
}
try {
csvOutput.close();
FileOutputStream outputStream = new FileOutputStream("/home/alisha/Downloads/Final Updated Code+ Libraries/pos_out_upparcase/empty.csv");
//workbook.write(outputStream);*/
// workbook.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Done" + listOfFiles[f].getName());
}
}
}