annotate termenrichment.py @ 1:646b05282962

Uploaded
author jorrit
date Tue, 12 Feb 2013 13:46:10 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
646b05282962 Uploaded
jorrit
parents:
diff changeset
1 """
646b05282962 Uploaded
jorrit
parents:
diff changeset
2 Term enrichment datatypes
646b05282962 Uploaded
jorrit
parents:
diff changeset
3
646b05282962 Uploaded
jorrit
parents:
diff changeset
4 """
646b05282962 Uploaded
jorrit
parents:
diff changeset
5 import pkg_resources
646b05282962 Uploaded
jorrit
parents:
diff changeset
6 pkg_resources.require( "bx-python" )
646b05282962 Uploaded
jorrit
parents:
diff changeset
7
646b05282962 Uploaded
jorrit
parents:
diff changeset
8 import logging, os, sys, time, tempfile, shutil
646b05282962 Uploaded
jorrit
parents:
diff changeset
9 import data
646b05282962 Uploaded
jorrit
parents:
diff changeset
10 from galaxy import util
646b05282962 Uploaded
jorrit
parents:
diff changeset
11 from galaxy.datatypes.sniff import *
646b05282962 Uploaded
jorrit
parents:
diff changeset
12 from galaxy.web import url_for
646b05282962 Uploaded
jorrit
parents:
diff changeset
13 from cgi import escape
646b05282962 Uploaded
jorrit
parents:
diff changeset
14 import urllib
646b05282962 Uploaded
jorrit
parents:
diff changeset
15 from bx.intervals.io import *
646b05282962 Uploaded
jorrit
parents:
diff changeset
16 from galaxy.datatypes import metadata
646b05282962 Uploaded
jorrit
parents:
diff changeset
17 from galaxy.datatypes.metadata import MetadataElement
646b05282962 Uploaded
jorrit
parents:
diff changeset
18 from galaxy.datatypes.tabular import Tabular
646b05282962 Uploaded
jorrit
parents:
diff changeset
19 import math
646b05282962 Uploaded
jorrit
parents:
diff changeset
20
646b05282962 Uploaded
jorrit
parents:
diff changeset
21 log = logging.getLogger(__name__)
646b05282962 Uploaded
jorrit
parents:
diff changeset
22
646b05282962 Uploaded
jorrit
parents:
diff changeset
23 class TermEnrichmentResult( data.Text ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
24 """Any term enrichment format"""
646b05282962 Uploaded
jorrit
parents:
diff changeset
25 file_ext = "enrichment"
646b05282962 Uploaded
jorrit
parents:
diff changeset
26
646b05282962 Uploaded
jorrit
parents:
diff changeset
27 def init_meta( self, dataset, copy_from=None ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
28 data.Text.init_meta( self, dataset, copy_from=copy_from )
646b05282962 Uploaded
jorrit
parents:
diff changeset
29
646b05282962 Uploaded
jorrit
parents:
diff changeset
30
646b05282962 Uploaded
jorrit
parents:
diff changeset
31 class TerfTab( TermEnrichmentResult ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
32 """TERF TSV Format"""
646b05282962 Uploaded
jorrit
parents:
diff changeset
33 file_ext = "terf"
646b05282962 Uploaded
jorrit
parents:
diff changeset
34
646b05282962 Uploaded
jorrit
parents:
diff changeset
35 def init_meta( self, dataset, copy_from=None ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
36 data.Text.init_meta( self, dataset, copy_from=copy_from )
646b05282962 Uploaded
jorrit
parents:
diff changeset
37 def sniff( self, filename ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
38 """
646b05282962 Uploaded
jorrit
parents:
diff changeset
39 Determines whether the file is in TERF format
646b05282962 Uploaded
jorrit
parents:
diff changeset
40 """
646b05282962 Uploaded
jorrit
parents:
diff changeset
41 headers = get_headers( filename, '\n' )
646b05282962 Uploaded
jorrit
parents:
diff changeset
42 try:
646b05282962 Uploaded
jorrit
parents:
diff changeset
43 for hdr in headers:
646b05282962 Uploaded
jorrit
parents:
diff changeset
44 if hdr and hdr[0].startswith( '##terf-version' ) :
646b05282962 Uploaded
jorrit
parents:
diff changeset
45 return True
646b05282962 Uploaded
jorrit
parents:
diff changeset
46 return False
646b05282962 Uploaded
jorrit
parents:
diff changeset
47 except:
646b05282962 Uploaded
jorrit
parents:
diff changeset
48 return False
646b05282962 Uploaded
jorrit
parents:
diff changeset
49
646b05282962 Uploaded
jorrit
parents:
diff changeset
50
646b05282962 Uploaded
jorrit
parents:
diff changeset
51