Skip to content
Snippets Groups Projects
Feature.xml 12.8 KiB
Newer Older
  • Learn to ignore specific revisions
  • tjc's avatar
    tjc committed
    <?xml version="1.0" encoding="UTF-8" ?> 
     
    <!DOCTYPE sqlMap 
        PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" 
        "http://ibatis.apache.org/dtd/sql-map-2.dtd"> 
     
    
    <sqlMap namespace="Feature"> 
     
    
      <typeAlias alias="Feature"
    
            type="org.gmod.schema.sequence.Feature"/>
    
      <parameterMap id="schema-cvlist" 
                    class="Feature">
        <parameter property="schema" javaType="java.lang.String"/>
        <parameter property="featureCvTerms" javaType="java.util.List"/>
      </parameterMap> 
    
    tjc's avatar
    tjc committed
    
    
      <resultMap id="select-feature" 
                 class="Feature" groupBy="featureId">
        <result property="timeLastModified" column="timelastmodified"/>
       	<result property="featureId" column="id"/>
       	<result property="featureRelationshipsForSubjectId" 
    
    tjc's avatar
    tjc committed
       	            resultMap="FeatureRelationship.feature_relationship"  /> 
    
      	<result property="featureRelationship.featureByObjectId.featureId" column="object_id"/>
      	<result property="featureRelationship.cvTerm.cvTermId" column="relation_type_id"/>
      	<result property="featureRelationship.rank" column="rank"/>
    
        <result property="featureLoc.strand" column="strand" nullValue="0"/>
        <result property="featureLoc.fmin" column="fmin" nullValue="-1"/>
        <result property="featureLoc.fmax" column="fmax" nullValue="0"/>
        <result property="featureLoc.phase" column="phase"/>
        <result property="uniqueName" column="uniquename"/>
        <result property="cvTerm.cvTermId" column="type_id"/>
        <result property="featureProps" resultMap="FeatureProp.featureprop" />
    
    tjc's avatar
    tjc committed
       <!--
    
        <result property="featureprop.cvTerm.cvTermId" column="prop_type_id" nullValue="0"/>
        <result property="featureprop.value" column="value"/>
        <result property="featureprop.rank" column="prop_rank" nullValue="0"/> 
    
    tjc's avatar
    tjc committed
        -->
    
      </resultMap>
    
    tjc's avatar
    tjc committed
    
    
      <!-- mapping for feature table and lazy loading of feature_dbxref, feature_relationship,
           featureprop, organism tables -->
      <resultMap id="select-feature-lazy" 
                 class="Feature">       
        <result property="timeLastModified" column="timelastmodified"/>
       	<result property="featureId" column="id"/>
        <result property="uniqueName" column="uniquename"/>
        <result property="name" column="name"/>
        <result property="residues" column="residues" />
        <result property="seqLen" column="length" nullValue="-999" />
        <result property="cvTerm" column="type_id" select="selectCvterm" />
        <result property="dbXRef" column="dbXRefId"
                                  select="selectDbXRef" />
        <result property="featureLocsForFeatureId" column="{id=id}" 
                                                   select="getFeatureLoc" />
        <result property="featureProps" column="{feature_id=id}" 
                                           select="selectFeatureProp" />
        <result property="featureDbXRefs" column="{featureId=id}"
                                          select="getFeatureDbXRef" />
        <result property="featureRelationshipsForObjectId" column="{object_id=id}" 
                                           select="getFeatureRelationship" />  
        <result property="featureRelationshipsForSubjectId" column="{subject_id=id}" 
                                           select="getFeatureRelationship" /> 
        <result property="featureSynonyms" column="{feature.uniqueName=uniqueName}" 
                                           select="getLazyFeatureSynonymsByUniquename" />                          
        <result property="organism" column="{organismId=organismId}" 
                                    select="getOrganism" />
      </resultMap>
    
    tjc's avatar
    tjc committed
         
    
      <resultMap id="select-similaritymatch" 
                 class="Feature" groupBy="featureId">       
        <result property="timeLastModified" column="timelastmodified"/>
       	<result property="featureId" column="id"/>
        <result property="uniqueName" column="uniquename"/>
        <result property="name" column="name"/>
        <result property="seqLen" column="length" nullValue="-999" />
        <result property="residues" column="residues" />
        <result property="cvTerm" column="type_id" select="selectCvterm" />
        <result property="featureLocsForFeatureId" resultMap="FeatureLoc.select-location" />
        <result property="featureProps" column="{feature_id=id}" 
                                           select="selectFeatureProp" />
        <result property="analysisFeatures" column="{feature_id=id}" 
                                            select="selectAnalysisFeatures" />                                                
      </resultMap>
    
    tjc's avatar
    tjc committed
        
    
      <resultMap id="select-feature-with-residues-result" 
                 class="Feature">
        <result property="name" column="name"/>
        <result property="uniqueName" column="uniquename"/>
        <result property="featureId" column="feature_id"/>
        <result property="cvTerm.cvTermId" column="type_id"/>
      </resultMap>
    
    tjc's avatar
    tjc committed
         
    
      <!-- SQL --> 
      <!-- get feature -->
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
         <select id="getFeature" parameterClass="Feature" 
    
    tjc's avatar
    tjc committed
                                 resultMap="select-feature">
    
    tjc's avatar
    tjc committed
            SELECT
              timelastmodified, 
    
    tjc's avatar
    tjc committed
              f.feature_id AS id, 
    
    tjc's avatar
    tjc committed
              fr.object_id,
              fr.type_id AS relation_type_id,
    
              fr.rank,
              fr.value AS relation_value,
    
    tjc's avatar
    tjc committed
              fl.strand, 
    
    tjc's avatar
    tjc committed
              fmin, 
              fmax, 
              uniquename,
    
    tjc's avatar
    tjc committed
              f.type_id,  
    
    tjc's avatar
    tjc committed
              fp.type_id AS prop_type_id,
              fp.rank AS prop_rank,
    
    tjc's avatar
    tjc committed
              fp.value,
              fl.phase
    
    tjc's avatar
    tjc committed
            FROM feature f
            LEFT JOIN feature_relationship fr ON fr.subject_id = f.feature_id
            LEFT JOIN featureprop fp          ON fp.feature_id = f.feature_id
            LEFT JOIN featureloc fl           ON f.feature_id  = fl.feature_id
    
    tjc's avatar
    tjc committed
            WHERE
                <dynamic>
    
                 <isGreaterThan property="featureLoc.featureBySrcFeatureId.featureId" compareValue="0"> 
                   srcfeature_id=$featureLoc.featureBySrcFeatureId.featureId$ 
    
    tjc's avatar
    tjc committed
                 </isGreaterThan>
    
    tjc's avatar
    tjc committed
                 <isNotNull property="uniqueName">                        
                   uniquename LIKE #uniqueName# 
    
    tjc's avatar
    tjc committed
                 </isNotNull>
    
    tjc's avatar
    tjc committed
            ORDER BY f.type_id,  uniquename
    
    tjc's avatar
    tjc committed
         </select>
     
    
    tjc's avatar
    tjc committed
         <select id="getLazyFeature" resultMap ="select-feature-lazy" 
    
    tjc's avatar
    tjc committed
                                     parameterClass="Feature">
    
    tjc's avatar
    tjc committed
    	 SELECT
    	    timelastmodified,
    	 	f.feature_id AS id,
    	 	uniquename,
    
    tjc's avatar
    tjc committed
    	 	organism_id AS organismId,
    
    tjc's avatar
    tjc committed
    		f.name,
    
    tjc's avatar
    tjc committed
    	 	f.type_id,
    
    tjc's avatar
    tjc committed
    	 	f.dbxref_id AS dbXRefId,
    
    tjc's avatar
    tjc committed
    		seqlen AS length,
    		residues
    	 FROM feature f
    
    tjc's avatar
    tjc committed
    	 <dynamic>
    	   <isNotNull property="cvTerm.name">
    	     LEFT JOIN cvterm ON f.type_id=cvterm.cvterm_id
    	   </isNotNull>
    	 </dynamic>
    
    tjc's avatar
    tjc committed
    	 WHERE
    	   <dynamic>
    
    tjc's avatar
    tjc committed
              <isGreaterThan property="featureId" compareValue="0"> 
                f.feature_id=$featureId$ AND
    
    tjc's avatar
    tjc committed
              </isGreaterThan>
              
    
    tjc's avatar
    tjc committed
              <isNotNull property="uniqueName">                                 
    
                <isNotNull property="featureSynonyms">
                  <iterate property="featureSynonyms" conjunction="OR" open="(" close=") OR">
                   f.feature_id=#featureSynonyms[].feature.featureId#
    
    tjc's avatar
    tjc committed
                 </iterate>
                </isNotNull>
    
    tjc's avatar
    tjc committed
                ( uniquename LIKE #uniqueName# ESCAPE '/' OR f.name LIKE #uniqueName# ESCAPE '/') AND              
    
    tjc's avatar
    tjc committed
              </isNotNull>
              
    
    tjc's avatar
    tjc committed
              <isGreaterThan property="cvTerm.cvTermId" compareValue="0"> 
    
    tjc's avatar
    tjc committed
                f.type_id=$cvTerm.cvTermId$ AND
    
    tjc's avatar
    tjc committed
              </isGreaterThan>
    
    tjc's avatar
    tjc committed
              
             <isNotNull property="cvTerm.name"> 
                cvterm.name=#cvTerm.name# AND
              </isNotNull>
    
    tjc's avatar
    tjc committed
           </dynamic>
    
    tjc's avatar
    tjc committed
             f.feature_id > 0 
    
    tjc's avatar
    tjc committed
        </select>
    
    
        <select id="getLazyFeatureById" resultMap ="select-feature-lazy" >
    	 SELECT
    	    timelastmodified,
    	 	f.feature_id AS id,
    	 	uniquename,
    	 	organism_id AS organismId,
    		f.name,
    	 	f.type_id,
    
    tjc's avatar
    tjc committed
    	 	f.dbxref_id AS dbXRefId,
    
    		seqlen AS length,
    		residues
    	 FROM feature f
    	 WHERE f.feature_id=$featureId$
        </select>
        
    
        <!-- Returns matches for all features on a given srcfeature -->
    
         <select id="getLazySimilarityMatches" parameterClass="java.lang.Integer" 
                                 resultMap="select-similaritymatch">
            SELECT 
             timelastmodified, 
             f.feature_id AS id, 
             f.uniquename, 
             f.type_id,
             f.name,
    	 	 f.seqlen AS length,
    	 	 f.residues,
             srcfeature_id, fmin, fmax, strand, phase, residue_info, locgroup, rank
           FROM feature f 
           LEFT JOIN featureloc fl ON f.feature_id=fl.feature_id 
           WHERE  f.feature_id IN 
             (   SELECT feature_id FROM featureloc WHERE srcfeature_id IN 
               ( SELECT feature_id  FROM featureloc WHERE srcfeature_id=$value$) ) 
           ORDER BY f.feature_id
         </select>
    
    
         <!-- Returns matches for a list of feature_id's -->
         <select id="getLazySimilarityMatchesByFeatureIds" parameterClass="java.util.List" 
                                 resultMap="select-similaritymatch">
            SELECT 
             timelastmodified, 
             f.feature_id AS id, 
             f.uniquename, 
             f.type_id,
             f.name,
    	 	 f.seqlen AS length,
    	 	 f.residues,
             srcfeature_id, fmin, fmax, strand, phase, residue_info, locgroup, rank
           FROM feature f 
           LEFT JOIN featureloc fl ON f.feature_id=fl.feature_id 
           WHERE  f.feature_id IN 
             (   SELECT feature_id FROM featureloc WHERE srcfeature_id IN
               <iterate open="(" close=")" conjunction=",">
                #[]#
               </iterate>
             ) 
           ORDER BY f.feature_id
         </select>
    
    
    tjc's avatar
    tjc committed
        <select id="getSchema" resultClass="java.lang.String">
    
    tjc's avatar
    tjc committed
           SELECT schema_name FROM information_schema.schemata WHERE schema_name=schema_owner
    
    tjc's avatar
    tjc committed
             ORDER BY schema_name
    
    tjc's avatar
    tjc committed
        </select>
    
    
    tjc's avatar
    tjc committed
        <select id="getResidueType" parameterClass="java.lang.String" 
                resultClass="java.lang.Long">
    
    tjc's avatar
    tjc committed
           SELECT DISTINCT type_id 
    
    tjc's avatar
    tjc committed
           FROM feature 
    
    tjc's avatar
    tjc committed
           WHERE residues notnull
    
    tjc's avatar
    tjc committed
        </select>
    
    
    tjc's avatar
    tjc committed
    
    
        <select id="getResidueFeatures" parameterClass="java.util.Map"
    
    tjc's avatar
    tjc committed
                resultMap="select-feature-with-residues-result">
           SELECT
             name,
    
    tjc's avatar
    tjc committed
             uniquename,
    
    tjc's avatar
    tjc committed
             feature_id,
             type_id
    
           FROM feature WHERE residues notnull AND residues NOT LIKE ''
    
    tjc's avatar
    tjc committed
           <!--
    
    tjc's avatar
    tjc committed
             <iterate prepend="AND" property="cvTermIds" conjunction="OR" open="(" close=")">
               type_id=#cvTermIds[]#
    
    tjc's avatar
    tjc committed
             </iterate>
    
    tjc's avatar
    tjc committed
           ORDER BY abbreviation, type_id 
           -->
    
    tjc's avatar
    tjc committed
        </select>
    
    
    tjc's avatar
    tjc committed
        
    
    tjc's avatar
    tjc committed
        <select id="currval" resultClass="java.lang.Integer" 
                parameterClass="java.lang.String">
    
    tjc's avatar
    tjc committed
          SELECT currval('$value$')
        </select>
    
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
        <!--  WRITE BACK METHODS  -->
        
        <!--  UPDATE  -->
        <update id="updateFeature"
                parameterClass="Feature">
          UPDATE feature
    
    tjc's avatar
    tjc committed
          SET uniquename=#uniqueName#
          <isNotNull property="cvTerm.cvTermId">
            , type_id=$cvTerm.cvTermId$
    
    tjc's avatar
    tjc committed
          </isNotNull>
    
          <isNotNull property="timeLastModified">
            , timelastmodified=#timeLastModified#
    
    tjc's avatar
    tjc committed
          </isNotNull>
    
    tjc's avatar
    tjc committed
          WHERE feature_id=$featureId$
    
    tjc's avatar
    tjc committed
        </update>
    
    tjc's avatar
    tjc committed
        <update id="updateFeatureResidues"
    
                parameterClass="uk.ac.sanger.artemis.chado.FeatureForUpdatingResidues">
                UPDATE feature SET 
                residues=substring(residues from 1 for $startBase$) || 
                         <dynamic>
                         <isNotNull property="newSubSequence">
                           #newSubSequence# ||
                         </isNotNull>
                         </dynamic>
    
    tjc's avatar
    tjc committed
                         substring(residues from $endBase$ for $basesToEnd$),
    
                seqlen=$seqLen$
                WHERE feature_id=$featureId$
    
    tjc's avatar
    tjc committed
        </update>
    
    tjc's avatar
    tjc committed
        
        <!--  INSERT  -->
    
    tjc's avatar
    tjc committed
        <insert id="insertFeature" 
    
    tjc's avatar
    tjc committed
                parameterClass="Feature">
    
    tjc's avatar
    tjc committed
          INSERT INTO feature 
    
    tjc's avatar
    tjc committed
            ( feature_id, organism_id, name, uniquename, type_id
              <isGreaterThan property="seqLen" compareValue="0"> , seqlen </isGreaterThan>
              <isNotNull property="dbXRef.dbXRefId"> , dbxref_id </isNotNull> )
    
    tjc's avatar
    tjc committed
          VALUES
    
    tjc's avatar
    tjc committed
            ( nextval('feature_feature_id_seq'),
    
              $organism.organismId$,
    
    tjc's avatar
    tjc committed
              #name#,
    
    tjc's avatar
    tjc committed
              #uniqueName#,
    
    tjc's avatar
    tjc committed
              $cvTerm.cvTermId$
              <isGreaterThan property="seqLen" compareValue="0"> , $seqLen$ </isGreaterThan>
              <isNotNull property="dbXRef.dbXRefId"> , $dbXRef.dbXRefId$ </isNotNull> )
    
    tjc's avatar
    tjc committed
        </insert>
    
    tjc's avatar
    tjc committed
       <!--
       <update id="updateRegionSequence"
                parameterClass="Feature">
                UPDATE feature SET 
                residues=substring(residues from 1 for $featureLoc.fmin$) || 
                         #residues,jdbcType=text# ||
                         substring(residues from $featureLoc.fmin$ for 
                                   (seqLen + $seqLen$)),
                seqlen=(seqLen+$seqLen$)
                WHERE feature_id=$featureLoc.featureBySrcFeatureId.featureId$
       </update>
       -->
       
    
    tjc's avatar
    tjc committed
       <!--  DELETE  -->
    
    tjc's avatar
    tjc committed
       <delete id="deleteFeature" 
    
    tjc's avatar
    tjc committed
               parameterClass="Feature">
    
    tjc's avatar
    tjc committed
          DELETE FROM feature
    
    tjc's avatar
    tjc committed
          WHERE uniquename=#uniqueName# AND type_id=$cvTerm.cvTermId$
    
    tjc's avatar
    tjc committed
       <delete id="deleteFeatureById" 
               parameterClass="Feature">
          DELETE FROM feature
          WHERE feature_id=$featureId$
       </delete>
    
    tjc's avatar
    tjc committed
    </sqlMap>