public static void main(String[] args) throws Exception {
File file = new File("C:\\Users\\xuchichi\\Desktop\\method3\\123.txt");
List<String> gene1 = readGeneName1(file);
List<String> gene2 = readGeneName2(file);
List<String> weight = readGeneName3(file);
HashSet<String> geneId = insertGene(gene1,gene2);//读二元关系
List<String> geneID = new ArrayList<String>(geneId);
int n = geneID.size();
float [][]arr = new float[n][n];
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
arr[i][j] = 0;
//initial(arr,gene1,gene2,weight,geneID);//初始化矩阵
//ComputePath_IR_Whole((float) 0.2,arr,n);//迭代更新矩阵并将结果写入文件
File file2 = new File("C:\\Users\\xuchichi\\Desktop\\method3\\456.txt");
List <String> sim = readFileOne(file2);//读基因相似度
readGeneSet(geneID,sim);
// for(int i =0;i<n;i++)
// System.out.println(geneID.get(i)+" "+i);
}
private static List<String> readFileOne(File file2) throws IOException{
// TODO Auto-generated method stub
List<String> r = new ArrayList<String>();
if (file2.isFile() && file2.exists()) {
InputStreamReader reader = new InputStreamReader(
new FileInputStream(file2));
BufferedReader bufferR = new BufferedReader(reader);
// String GoTermId = null;
String lineTxt = "";
int count =0;
while((lineTxt = bufferR.readLine()) != null){
count++;
if(count==6){
String[] out = cutString(lineTxt);
for(String s:out)
r.add(s);
break;
}
lineTxt = "";
}
}
return r;
}
public static void readGeneSet(List<String> geneID,List <String> sim) throws IOException{
File file2= new File("C:\\Users\\xuchichi\\Desktop\\method3\\result.txt");
FileWriter out = new FileWriter(file2);
System.out.println(geneID.size()+" "+sim.size());
for(int i =0;i<geneID.size();i++){
System.out.println(geneID.get(5)+" "+geneID.get(i)+sim.get(i));
out.write(geneID.get(5)+"\t"+geneID.get(i)+"\t"+sim.get(i)+"\n");
}
}
public static void initial(float[][]arr,List<String>gene1,List<String>gene2,
List<String>weight,List<String>geneId){
for(int i=0;i<gene1.size();i++){
String str1 = gene1.get(i);
String str2 = gene2.get(i);
int x=-1;
int y=-1;
for(int j=0;j<geneId.size();j++){
if(str1.equals(geneId.get(j)))
x = j;
if(str2.equals(geneId.get(j)))
y = j;
}
arr[x][y] = Float.valueOf(weight.get(i));
//System.out.println(i+" "+str1+" "+str2+" "+x+" "+y+" "+arr[x][y]);
}
}
public static List<String> readGeneName1(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> readGeneName2(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;
}
public static List<String> readGeneName3(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[2];
r.add(in);
}
}
return r;
}
public static String[] cutString(String in) {
return in.split(" ");
}
public static HashSet<String>insertGene(List<String>list1,List<String>list2){
HashSet<String> res = new HashSet<String>();
for(int i =0;i<list1.size();i++){
res.add(list1.get(i));
res.add(list2.get(i));
}
return res;
}
文本处理,将交互组数据转化成邻接矩阵
最新推荐文章于 2024-06-23 12:15:05 发布