Skip to content
Snippets Groups Projects
DatabaseDocument.java 99.1 KiB
Newer Older
tjc's avatar
tjc committed
/* DatabaseDocument.java
 *
tjc's avatar
tjc committed
 * created: 2005
tjc's avatar
tjc committed
 *
 * This file is part of Artemis
 * 
tjc's avatar
tjc committed
 * Copyright (C) 2005  Genome Research Limited
tjc's avatar
tjc committed
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

package uk.ac.sanger.artemis.util;

import uk.ac.sanger.artemis.Options;
import uk.ac.sanger.artemis.io.ChadoCanonicalGene;
import uk.ac.sanger.artemis.io.DocumentEntry;
tjc's avatar
tjc committed
import uk.ac.sanger.artemis.io.GFFStreamFeature;
import uk.ac.sanger.artemis.io.PartialSequence;
tjc's avatar
tjc committed
import uk.ac.sanger.artemis.io.Range;
import uk.ac.sanger.artemis.io.ReadFormatException;
tjc's avatar
tjc committed
import uk.ac.sanger.artemis.chado.ArtemisUtils;
tjc's avatar
tjc committed
import uk.ac.sanger.artemis.chado.ChadoCvTermView;
import uk.ac.sanger.artemis.chado.FeatureForUpdatingResidues;
import uk.ac.sanger.artemis.chado.IBatisDAO;
import uk.ac.sanger.artemis.chado.JdbcDAO;
import uk.ac.sanger.artemis.chado.GmodDAO;
import uk.ac.sanger.artemis.chado.ChadoTransaction;
import uk.ac.sanger.artemis.components.database.DatabaseEntrySource;
import uk.ac.sanger.artemis.components.genebuilder.GeneUtils;
tjc's avatar
tjc committed
import uk.ac.sanger.artemis.components.Splash;
tjc's avatar
tjc committed

import org.gmod.schema.sequence.Feature;
import org.gmod.schema.sequence.FeatureProp;
import org.gmod.schema.sequence.FeatureLoc;
tjc's avatar
tjc committed
import org.gmod.schema.sequence.FeaturePub;
import org.gmod.schema.sequence.FeatureRelationship;
import org.gmod.schema.sequence.FeatureSynonym;
import org.gmod.schema.sequence.FeatureCvTerm;
import org.gmod.schema.sequence.FeatureCvTermProp;
tjc's avatar
tjc committed
import org.gmod.schema.sequence.FeatureCvTermDbXRef;
tjc's avatar
tjc committed
import org.gmod.schema.sequence.FeatureCvTermPub;
import org.gmod.schema.cv.Cv;
import org.gmod.schema.cv.CvTerm;
tjc's avatar
tjc committed
import org.gmod.schema.general.Db;
import org.gmod.schema.general.DbXRef;
tjc's avatar
tjc committed
import org.gmod.schema.organism.Organism;
tjc's avatar
tjc committed
import org.gmod.schema.pub.PubDbXRef;
import org.gmod.schema.pub.Pub;
import org.postgresql.largeobject.LargeObjectManager;

import com.ibatis.common.jdbc.SimpleDataSource;
tjc's avatar
tjc committed
import java.sql.*;
import java.text.SimpleDateFormat;
tjc's avatar
tjc committed
import java.io.*;
tjc's avatar
tjc committed
import java.net.ConnectException;
tjc's avatar
tjc committed
import java.net.InetAddress;
tjc's avatar
tjc committed
import java.util.Collections;
import java.util.Comparator;
tjc's avatar
tjc committed
import java.util.HashSet;
tjc's avatar
tjc committed
import java.util.Hashtable;
tjc's avatar
tjc committed
import java.util.Set;
import java.util.Vector;
tjc's avatar
tjc committed
import java.util.Enumeration;
tjc's avatar
tjc committed
import java.util.List;
import java.util.Iterator;
tjc's avatar
tjc committed
import java.util.Collection;

tjc's avatar
tjc committed
import javax.swing.JOptionPane;
tjc's avatar
tjc committed
import javax.swing.JPasswordField;
tjc's avatar
tjc committed

/**
tjc's avatar
tjc committed
 * Objects of this class are Documents created from a relational database.
 */
public class DatabaseDocument extends Document
tjc's avatar
tjc committed
{
  private String name = null;
tjc's avatar
tjc committed

  /** source feature_id */
  private String srcFeatureId = "1";
tjc's avatar
tjc committed

  /** database schema */
  private String schema = "public";

  private static Hashtable cvterms;
tjc's avatar
tjc committed
  
  private InputStreamProgressListener progress_listener;
tjc's avatar
tjc committed

tjc's avatar
tjc committed
  /** JDBC DAO */
  private JdbcDAO jdbcDAO = null;

  /** iBatis DAO */
  private static IBatisDAO connIB = null;
tjc's avatar
tjc committed

tjc's avatar
tjc committed
  private ByteBuffer[] gff_buffer;
tjc's avatar
tjc committed

tjc's avatar
tjc committed
  private ByteBuffer gff_buff;
tjc's avatar
tjc committed

tjc's avatar
tjc committed
  /** entries to split into - each is given a name and the features within the entry */
tjc's avatar
tjc committed
  private static String[][][] TYPES = 
tjc's avatar
tjc committed
  { 
      { {"repeats"}   , {"repeat_region", "direct_repeat"} }, 
      { {"EST"}       , {"EST_match", "match_part"} },
      { {"contig+gap"}, {"contig", "gap"}}
  };
tjc's avatar
tjc committed

  /** true if splitting the GFF into entries */
tjc's avatar
tjc committed
  private boolean splitGFFEntry;
tjc's avatar
tjc committed

tjc's avatar
tjc committed
  private boolean iBatis = false;
tjc's avatar
tjc committed

tjc's avatar
tjc committed
  private JPasswordField pfield;
tjc's avatar
tjc committed
  
  private boolean singleSchema = true;
tjc's avatar
tjc committed

  private List schema_list;
  
tjc's avatar
tjc committed
  private static List organismNames;
  
  private boolean gene_builder;
  
  // include children in reading from the database
  private boolean readChildren = true;
  
tjc's avatar
tjc committed
  // range to retrieve features for
tjc's avatar
tjc committed
  private Range range;
  
  private Feature geneFeature;
  
tjc's avatar
tjc committed
  private Hashtable idFeatureStore;
  
  private boolean lazyFeatureLoad = true;
  
tjc's avatar
tjc committed
  public static String EXONMODEL  = "exon-model";
  public static String TRANSCRIPT = "mRNA";
  public static boolean CHADO_INFER_CDS = false;
  /** list of controlled_curation CV names */
  private static Vector cvControledCuratioNames;
  
  private static CvTermThread cvThread;
  
tjc's avatar
tjc committed
  // controlled vocabulary
  /** controlled_curation controlled vocabulary */
tjc's avatar
tjc committed
  public static String CONTROLLED_CURATION_TAG_CVNAME = 
tjc's avatar
tjc committed
                                 "CC_";
  /**  controlled vocabulary */
tjc's avatar
tjc committed
  public static String PRODUCTS_TAG_CVNAME = "genedb_products";
tjc's avatar
tjc committed
  public static String RILEY_TAG_CVNAME = "RILEY";
tjc's avatar
tjc committed
  
tjc's avatar
tjc committed
  private static org.apache.log4j.Logger logger4j = 
    org.apache.log4j.Logger.getLogger(DatabaseDocument.class);
tjc's avatar
tjc committed

tjc's avatar
tjc committed
  
tjc's avatar
tjc committed
  /**
tjc's avatar
tjc committed
   * 
   * Create a new Document from a database.
   * 
   * @param location
   *          This should be a URL string giving:
   *          jdbc:postgresql://host:port/datbase_name?user=username
   * 
   */
tjc's avatar
tjc committed
  public DatabaseDocument(String location, JPasswordField pfield)
tjc's avatar
tjc committed
  {
    super(location);
tjc's avatar
tjc committed
    this.pfield = pfield;

tjc's avatar
tjc committed
    if(location.indexOf('=') > -1)
      this.schema = location.substring( location.indexOf('=')+ 1);
    
    if(System.getProperty("ibatis") != null ||
       System.getProperty("jdbc") == null)
tjc's avatar
tjc committed
    {
tjc's avatar
tjc committed
      iBatis = true;
tjc's avatar
tjc committed
      System.setProperty("chado", location);
tjc's avatar
tjc committed
    }
tjc's avatar
tjc committed
    initMDC(this);
tjc's avatar
tjc committed
  }

tjc's avatar
tjc committed
  /**
tjc's avatar
tjc committed
   * 
   * Create a new Document from a database.
   * 
   * @param location
Loading
Loading full blame...