comparison ontology.py @ 0:b4db4eaf8fff draft default tip

Uploaded
author jorrit
date Tue, 12 Feb 2013 14:41:25 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:b4db4eaf8fff
1 """
2 Ontology datatypes
3
4 """
5 import pkg_resources
6 pkg_resources.require( "bx-python" )
7
8 import logging, os, sys, time, tempfile, shutil
9 import data
10 from galaxy import util
11 from galaxy.datatypes.sniff import *
12 from galaxy.web import url_for
13 from cgi import escape
14 import urllib
15 from bx.intervals.io import *
16 from galaxy.datatypes import metadata
17 from galaxy.datatypes.metadata import MetadataElement
18 from galaxy.datatypes.tabular import Tabular
19 import math
20
21 log = logging.getLogger(__name__)
22
23 class Ontology( data.Text ):
24 """Any ontology Format"""
25 file_ext = "ontology"
26
27 def init_meta( self, dataset, copy_from=None ):
28 data.Text.init_meta( self, dataset, copy_from=copy_from )
29
30
31 class Obo( Ontology ):
32 """OBO Format"""
33 file_ext = "obo"
34
35 def init_meta( self, dataset, copy_from=None ):
36 data.Text.init_meta( self, dataset, copy_from=copy_from )
37 def sniff( self, filename ):
38 """
39 Determines whether the file is in OBO format
40 """
41 headers = get_headers( filename, '\n' )
42 try:
43 for hdr in headers:
44 if hdr and hdr[0].startswith( 'format-version:' ) :
45 return True
46 return False
47 except:
48 return False
49
50 class Owl( Ontology ):
51 """OWL"""
52 file_ext = "owl"
53
54 def init_meta( self, dataset, copy_from=None ):
55 data.Text.init_meta( self, dataset, copy_from=copy_from )
56 def sniff( self, filename ):
57 """
58 Determines whether the file is in OWL RDF-XML format
59 """
60 headers = get_headers( filename, '\n' )
61 try:
62 for hdr in headers:
63 if hdr and hdr[0].find( '<owl' ) > -1 :
64 return True
65 if hdr and hdr[0].find( 'http://www.w3.org/2002/07/owl' ) > -1 :
66 return True
67 return False
68 except:
69 return False
70
71
72 class OwlRdfXML( Owl ):
73 """OWL RDF/XML"""
74
75 def init_meta( self, dataset, copy_from=None ):
76 data.Text.init_meta( self, dataset, copy_from=copy_from )
77 def sniff( self, filename ):
78 """
79 Determines whether the file is in OWL RDF-XML format
80 """
81 headers = get_headers( filename, '\n' )
82 try:
83 for hdr in headers:
84 if hdr and hdr[0].find( '<owl:Ontology' ) > -1 :
85 return True
86 return False
87 except:
88 return False
89
90