PDB檔案頭中時間格式解析
阿新 • • 發佈:2019-02-10
在做生物資訊學時,經常需要使用到Protein Data Bank中的資料,時不時的需要使用PDB檔案中的時間(時間格式為10-MAR-14 (2014年三月10日))將已有資料分成訓練資料和獨立測試資料,時間如何解析是一件比較簡單的事情,為了方便尋找故將這段程式碼貼在這裡。
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">
</span>
private static double parsePDBTimeStr(String pdb_time){ // eg.: 10-MAR-14 System.out.println(pdb_time); double year = Double.parseDouble(pdb_time.substring(7, 9)); if (year > 16){ //將年份換算成4位數 year += 1900; }else{ year += 2000; } String month = pdb_time.substring(3, 6); double mon = 0; if (month.equals("JAN")){ mon = 1; }else if (month.equals("FEB")){ mon = 2; }else if (month.equals("MAR")){ mon = 3; }else if (month.equals("APR")){ mon = 4; }else if (month.equals("MAY")){ mon = 5; }else if (month.equals("JUN")){ mon = 6; }else if (month.equals("JUL")){ mon = 7; }else if (month.equals("AUG")){ mon = 8; }else if (month.equals("SEP")){ mon = 9; }else if (month.equals("OCT")){ mon = 10; }else if (month.equals("NOV")){ mon = 11; }else if (month.equals("DEC")){ mon = 12; } double day = Double.parseDouble(pdb_time.substring(0, 2)); return year*10000+mon*100+day; }