/**
 * Importing and inference of protein functions
 */

import java.util.*;
import java.sql.*;

public class ProteinFunction {
    private Connection con;

    public ProteinFunction() {
	//TODO: Change to your settings
	con = Postgres.getConnection("localhost", "rosetta", "cs329e",
		"");
	if (con == null) {
	    throw new Error("Failed to connect to PostgreSQL server");
	}
    }

    /**
     * Import GO term associations from the GO database.
     * Clear the importedfunction table before executing this method.
     */
    public void importFunction () {
	try {
	    GeneOntology go = new GeneOntology();

	    Statement stmt = con.createStatement();
	    ResultSet rs = stmt.executeQuery(
		    "SELECT t_protein_id, name FROM t_protein");

	    // TODO: write a query template for inserting into
	    // the imported function table
	    PreparedStatement pstmt = con.prepareStatement();

	    // read every protein
	    while (rs.next()) {
		int pid = rs.getInt(1);
		String pname = rs.getString(2);

		// TODO: find all the GO terms. Here the gene product symbol
		// of a protein is its name.
		List terms = ;

		// insert them into the importedfunction table
		// TODO: for each term in the list, fill in the parameters
		// of the prepared statement and execute it.
	    }
	} catch (SQLException ex) {
	    System.err.println(ex);
	}
    }

    public static void main(String[] args) {
	ProteinFunction pf = new ProteinFunction();
	pf.importFunction();
	System.out.println("Protein functions imported from GO");
    }
}
