// topK sort,write the result to hdfs public void reduce(DoubleWritable key, Iterable<DataPair> values, Context context) throws IOException, InterruptedException { for (DataPair val : values) { if (count < k) { hf.createNewHDFSFile(val.getLigandPath(), val.getVinaResult()); hf.createNewHDFSFile(val.getLogPath(), val.getVinaLog()); int position = val.getLigandPath().lastIndexOf("/"); String ligandName = val.getLigandPath().substring(position + 1); context.write(new DoubleWritable(val.getLigandDouble()), new Text(ligandName)); /* context.write(new DoubleWritable(val.getLigandDouble()), new Text(val.getLigandPath()));*/ count++; } else { break; } } }
/* * (non-Javadoc) * * @see org.apache.hadoop.mapreduce.Mapper#map(KEYIN, VALUEIN, * org.apache.hadoop.mapreduce.Mapper.Context) */ public void map(Object key, Text value, Context context) throws IOException, InterruptedException { String path = value.toString(); String[] sub = value.toString().split("/"); String ligandName = sub[sub.length - 1]; String ligandLocal = "/home/hadoop/vinaJob/" + tmpPath + "/data/" + ligandName; hf.HadoopToLocal(path, ligandLocal); String out = "/home/hadoop/vinaJob/" + tmpPath + "/out/" + ligandName; fo.createDir("/home/hadoop/vinaJob/" + tmpPath + "/out/"); String log = "/home/hadoop/vinaJob/" + tmpPath + "/out/" + ligandName + ".log"; String exceptionPath = "/vinaResult/vinaJobID/" + vinaJobID + "/exception/" + ligandName + ".exception"; String exceptionBackupPath = "/vinaResult/vinaJobID/" + vinaJobID + "/exceptionBackup/" + ligandName + ".exception"; RunVina vinajob = new RunVina(conf2Local, ligandLocal, receptorLocal, seed, out, log, path); String flag = vinajob.runVina(); if ("success".equals(flag)) { String logHdfsPath = "/vinaResult/vinaJobID/" + vinaJobID + "/result/" + ligandName + ".log"; String outHdfsPath = "/vinaResult/vinaJobID/" + vinaJobID + "/result/" + ligandName; String result = fo.readFile(out); String logInfo = fo.readFile(log); try { DataPair data = new DataPair( Double.parseDouble(result.split("\n")[1].split(" ")[1].trim()), outHdfsPath, result, logHdfsPath, logInfo); tree.add(data); if (tree.size() > k) { tree.pollLast(); } } catch (Exception e) { hf.createNewHDFSFile(exceptionPath, path + " bad result"); } } else { hf.createNewHDFSFile(exceptionPath, flag); hf.createNewHDFSFile(exceptionBackupPath, flag); } }