Add gemini.sqlite datatype.

This commit is contained in:
Daniel Blankenberg
2015-01-09 14:48:56 -05:00
parent f83ff130f2
commit b022e92f5b
3 changed files with 64 additions and 2 deletions
+3 -1
View File
@@ -181,7 +181,8 @@
<datatype extension="taxonomy" type="galaxy.datatypes.tabular:Taxonomy" display_in_upload="true"/>
<datatype extension="tabular" type="galaxy.datatypes.tabular:Tabular" display_in_upload="true" description="Any data in tab delimited format (tabular)." description_url="https://wiki.galaxyproject.org/Learn/Datatypes#Tabular_.28tab_delimited.29"/>
<datatype extension="twobit" type="galaxy.datatypes.binary:TwoBit" mimetype="application/octet-stream" display_in_upload="true"/>
<datatype extension="sqlite" type="galaxy.datatypes.binary:SQlite" mimetype="application/octet-stream" display_in_upload="true"/>
<datatype extension="sqlite" type="galaxy.datatypes.binary:SQlite" mimetype="application/octet-stream" display_in_upload="true"/>
<datatype extension="gemini.sqlite" type="galaxy.datatypes.binary:GeminiSQLite" mimetype="application/octet-stream" display_in_upload="True" />
<datatype extension="txt" type="galaxy.datatypes.data:Text" display_in_upload="true" description="Any text file." description_url="https://wiki.galaxyproject.org/Learn/Datatypes#Plain_text"/>
<datatype extension="linecount" type="galaxy.datatypes.data:LineCount" display_in_upload="false"/>
<datatype extension="memexml" type="galaxy.datatypes.xml:MEMEXml" mimetype="application/xml" display_in_upload="true"/>
@@ -271,6 +272,7 @@
-->
<sniffer type="galaxy.datatypes.tabular:Vcf"/>
<sniffer type="galaxy.datatypes.binary:TwoBit"/>
<sniffer type="galaxy.datatypes.binary:GeminiSQLite"/>
<sniffer type="galaxy.datatypes.binary:SQlite"/>
<sniffer type="galaxy.datatypes.binary:Bam"/>
<sniffer type="galaxy.datatypes.binary:Sff"/>
+59 -1
View File
@@ -20,7 +20,7 @@ eggs.require( "bx-python" )
from bx.seq.twobit import TWOBIT_MAGIC_NUMBER, TWOBIT_MAGIC_NUMBER_SWAP, TWOBIT_MAGIC_SIZE
from galaxy.util import sqlite
from galaxy.datatypes.metadata import MetadataElement,ListParameter,DictParameter
from galaxy.datatypes.metadata import MetadataElement, MetadataParameter, ListParameter, DictParameter
from galaxy.datatypes import metadata
import dataproviders
@@ -640,8 +640,66 @@ class SQlite ( Binary ):
return dataproviders.dataset.SQliteDataDictProvider( dataset_source, **settings )
#Binary.register_sniffable_binary_format("sqlite", "sqlite", SQlite)
class GeminiSQLite( SQlite ):
"""Class describing a Gemini Sqlite database """
MetadataElement( name="gemini_version", default='0.10.0' , param=MetadataParameter, desc="Gemini Version",
readonly=True, visible=True, no_value='0.10.0' )
file_ext = "gemini.sqlite"
def set_meta( self, dataset, overwrite = True, **kwd ):
super( GeminiSQLite, self ).set_meta( dataset, overwrite = overwrite, **kwd )
try:
conn = sqlite.connect( dataset.file_name )
c = conn.cursor()
tables_query = "SELECT version FROM version"
result = c.execute( tables_query ).fetchall()
for version, in result:
dataset.metadata.gemini_version = version
# TODO: Can/should we detect even more attributes, such as use of PED file, what was input annotation type, etc.
except Exception, e:
log.warn( '%s, set_meta Exception: %s', self, e )
def sniff( self, filename ):
if super( GeminiSQLite, self ).sniff( filename ):
gemini_table_names = [ "gene_detailed", "gene_summary", "resources", "sample_genotype_counts", "sample_genotypes", "samples",
"variant_impacts", "variants", "version" ]
try:
conn = sqlite.connect( filename )
c = conn.cursor()
tables_query = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name"
result = c.execute( tables_query ).fetchall()
result = map( lambda x: x[0], result )
for table_name in gemini_table_names:
if table_name not in result:
return False
return True
except Exception, e:
log.warn( '%s, sniff Exception: %s', self, e )
return False
def set_peek( self, dataset, is_multi_byte=False ):
if not dataset.dataset.purged:
dataset.peek = "Gemini SQLite Database, version %s" % ( dataset.metadata.gemini_version or 'unknown' )
dataset.blurb = data.nice_size( dataset.get_size() )
else:
dataset.peek = 'file does not exist'
dataset.blurb = 'file purged from disk'
def display_peek( self, dataset ):
try:
return dataset.peek
except:
return "Gemini SQLite Database, version %s" % ( dataset.metadata.gemini_version or 'unknown' )
Binary.register_sniffable_binary_format( "gemini.sqlite", "gemini.sqlite", GeminiSQLite )
# FIXME: We need to register gemini.sqlite before sqlite, since register_sniffable_binary_format and is_sniffable_binary called in upload.py
# ignores sniff order declared in datatypes_conf.xml
Binary.register_sniffable_binary_format("sqlite", "sqlite", SQlite)
class Xlsx(Binary):
"""Class for Excel 2007 (xlsx) files"""
file_ext="xlsx"
+2
View File
@@ -113,6 +113,8 @@ def add_file( dataset, registry, json_file, output_path ):
ext = sniff.guess_ext( dataset.path, is_multi_byte=True )
# Is dataset content supported sniffable binary?
else:
# FIXME: This ignores the declared sniff order in datatype_conf.xml
# resulting in improper behavior
type_info = Binary.is_sniffable_binary( dataset.path )
if type_info:
data_type = type_info[0]