import java.io.*;
import java.util.*;

public class OutFile {

    private boolean RCOIL_PRINTOUT = ShiftXp.RCOIL_PRINTOUT;

    public OutFile() {        
               ; 
    }

    public void savePredCSToFileBMRB(String outfname, StringBuffer sb) {

        String header = "NUM,RES,IUPAC,ATOM,PRED_CS\n"; 

        if (RCOIL_PRINTOUT == true) {
           header = "NUM,RES,IUPAC,ATOM,PRED_CS,RCOIL\n"; 
        }

        try {
            FileWriter fos = new FileWriter( outfname );
            fos.write(header);
            fos.write(sb.toString());
            fos.close();
        } catch(IOException ex){
            ex.printStackTrace();
        }
    }

    public void savePredCSToFileTabular( String outfname, StringBuffer bb, StringBuffer sideCs, StringBuffer sideHs  ) {
        String bbheader = "NUM  RES  HA     H      N        CA      CB      C\n";
        String sideCs_header = "NUM  RES   CD     CD1    CD2    CG     CG1   CG2\n";  
        String sideHs_header = "NUM  RES  HB   HB2  HB3  HD1  HD2  HD21 HD22 HD3  HE   HE1  HE2  HE21 HE22 HE3  HG   HG1  HG12 HG13 HG2  HG3  HZ\n";
        // String sideHs_header = "NUM  RES  HB   HB2  HB3  HD1  HD2  HD21 HD22 HD3  HE   HE1  HE2  HE21 HE22 HE3  HG   HG1  HG12 HG13 HG2  HG3  HZ   HH2   HZ2  HZ3\n";

        try {
            FileWriter fos = new FileWriter( outfname );
            fos.write(bbheader);
            fos.write(bb.toString());
            fos.write("\n");
            fos.write(sideCs_header);
            fos.write(sideCs.toString());
            fos.write("\n");
            fos.write(sideHs_header);
            fos.write(sideHs.toString());
            fos.close();
        } catch(IOException ex){
            ex.printStackTrace();
        }
    }


    public void saveFeatureToFile(String outfname, StringBuffer sb) {
            StringBuffer sbfheader =  new StringBuffer();

            sbfheader.append("pdbid,resnum,iupac,ss,iupac_p,ss_p,iupac_n,ss_n,iupac_p2,iupac_n2,hbond,hbond_p,hbond_n,bturn,");
            sbfheader.append("resASA,fracASA,resVol,fracVol,sideASA,sideFracASA,SFE,"); 
            sbfheader.append("phi,psi,omega,chi,chi2,chi3,phi_p,psi_p,omega_p,chi_p,phi_n,psi_n,omega_n,chi_n,");
            sbfheader.append("phi_p2,psi_p2,omega_p2,chi_p2,phi_n2,psi_n2,omega_n2,chi_n2,");

            sbfheader.append("nn_chi,nn_chi2,nn_chi3,nn_chi_p,nn_chi_n,nn_chi_p2,nn_chi_n2,");
            sbfheader.append("ab_chi,ab_chi2,ab_chi3,ab_chi_p,ab_chi_n,ab_chi_p2,ab_chi_n2,");

            sbfheader.append("sin_phi,sin_psi,sin_omega,sin_chi,sin_chi2,sin_chi3,");
            sbfheader.append("sin_phi_p,sin_psi_p,sin_omega_p,sin_chi_p,sin_phi_n,sin_psi_n,sin_omega_n,sin_chi_n,");
            sbfheader.append("sin_phi_p2,sin_psi_p2,sin_omega_p2,sin_chi_p2,sin_phi_n2,sin_psi_n2,sin_omega_n2,sin_chi_n2,");
            sbfheader.append("cos_phi,cos_psi,cos_omega,cos_chi,cos_chi2,cos_chi3,");
            sbfheader.append("cos_phi_p,cos_psi_p,cos_omega_p,cos_chi_p,cos_phi_n,cos_psi_n,cos_omega_n,cos_chi_n,");
            sbfheader.append("cos_phi_p2,cos_psi_p2,cos_omega_p2,cos_chi_p2,cos_phi_n2,cos_psi_n2,cos_omega_n2,cos_chi_n2,");

            sbfheader.append("theta_donor,theta_acceptor,kappa_donor,kappa_acceptor,");
            sbfheader.append("dbond,dbond_p,dbond_n,ha1dist,ha2dist,hndist,ordist,");
            sbfheader.append("ha1dist_p,ha2dist_p,hndist_p,ordist_p,ha1dist_n,ha2dist_n,hndist_n,ordist_n,");
            sbfheader.append("ha1hb,ha2hb,hnhb,orhb,ha1hb_p,ha2hb_p,hnhb_p,orhb_p,ha1hb_n,ha2hb_n,hnhb_n,orhb_n,");

            sbfheader.append("hs1_phipsi,hs2_phichi,hs3_psichi,hs4_Chi2Chi_n,hs5_ChiChi2,");
            sbfheader.append("hs6_ChiChi_n,hs7_ChiChi_p,hs8_PhiChi_n,hs9_PhiChi_p,hs10_Phi_nChi2,");
            sbfheader.append("hs11_Phi_nChi_n,hs12_Phi_nChi_p,hs13_Phi_nPsi,hs14_Phi_nPsi_n,hs15_Phi_pChi_n,");
            sbfheader.append("hs16_Phi_pChi_p,hs17_PhiPhi_n,hs18_PhiPhi_p,hs19_Phi_pPsi,hs20_Phi_pPsi_p,");
            sbfheader.append("hs21_PhiPsi_n,hs22_PhiPsi_p,hs23_PsiChi_p ,hs24_Psi_nChi,hs25_Psi_nChi_n,");
            sbfheader.append("hs26_Psi_nChi_p,hs27_Psi_pChi,hs28_Psi_pChi_n,hs29_Psi_pChi_p,hs30_PsiPsi_n,hs31_PsiPsi_p,");

            sbfheader.append("hydro,asa,rcoil,rcurr,electrostat,hbondeffect,atomname,sxpred,sumofpyscial_cs");
            sbfheader.append("\n");

        try {
            FileWriter fos = new FileWriter( outfname );
            fos.write(sbfheader.toString());
            fos.write(sb.toString());
            fos.close();
        } catch(IOException ex){
            ex.printStackTrace();
        }
    }


}
