文本处理,将交互组数据转化成邻接矩阵

	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;
	}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值