package test.com;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class normalization {
public static void main(String[]args)throws Exception{
File file = new File("C:\\Users\\xuchichi\\Desktop\\毕设新方法\\normalization\\SABToSymtomSim.txt");
List<String> AllGene1 = readData1(file);
List<String> AllGene2 = readData2(file);
normalize2(AllGene1);
//normalize2(AllGene1);
}
private static void normalize2(List<String> allGene) throws IOException {
FileWriter writer = new FileWriter("C:\\Users\\xuchichi\\Desktop\\" +
"毕设新方法\\normalization\\CountSimToSymtomSimResult.txt",true);
double Max = -100;
double Min = 100;
for(int i =1;i<allGene.size();i++){
double d = Double.valueOf(allGene.get(i)).doubleValue();
if(d<Min)
Min = d;
if(d>Max)
Max = d;
}
System.out.println(Max+" "+Min);
writer.write(allGene.get(0)+"\n");
for(int i=1;i<allGene.size();i++){
double d = Double.valueOf(allGene.get(i)).doubleValue();
d -= Min;
d/=(Max-Min);
d = 1-d;
System.out.println(d);
writer.write(d+"\n");
writer.flush();
}
writer.close();
}
private static void normalize1(List<String> allGene) throws IOException {
FileWriter writer = new FileWriter("C:\\Users\\xuchichi\\Desktop\\" +
"毕设新方法\\normalization\\CountSimToSymtomSimResult.txt",true);
double Max = -100;
double Min = 100;
for(int i =1;i<allGene.size();i++){
double d = Double.valueOf(allGene.get(i)).doubleValue();
if(d<Min)
Min = d;
if(d>Max)
Max = d;
}
System.out.print(Max+" "+Min);
writer.write(allGene.get(0)+"\n");
for(int i=1;i<allGene.size();i++){
double d = Double.valueOf(allGene.get(i)).doubleValue();
d/=(Max-Min);
System.out.println(d+" "+i);
writer.write(d+"\n");
writer.flush();
}
writer.close();
}
public static String[] cutString(String in) {
return in.split(" ");
}
public static List<String> readData1(File f) throws IOException {
List<String> r = new ArrayList<String>();
if (f.isFile() && f.exists()) {
InputStreamReader reader = new InputStreamReader(
new FileInputStream(f));
BufferedReader bufferR = new BufferedReader(reader);
// String GoTermId = null;
String lineTxt = "";
while ((lineTxt = bufferR.readLine()) != null) {
String[] out = cutString(lineTxt);
String in = out[0];
r.add(in);
}
}
return r;
}
public static List<String> readData2(File f) throws IOException {
List<String> r = new ArrayList<String>();
if (f.isFile() && f.exists()) {
InputStreamReader reader = new InputStreamReader(
new FileInputStream(f));
BufferedReader bufferR = new BufferedReader(reader);
// String GoTermId = null;
String lineTxt = "";
while ((lineTxt = bufferR.readLine()) != null) {
String[] out = cutString(lineTxt);
String in = out[1];
r.add(in);
}
}
return r;
}
}
JAVA 读写文本+ 基本的文本处理(normalize)
最新推荐文章于 2024-06-22 22:45:21 发布