Mercurial > repos > iuc > snpeff
comparison lib/galaxy/datatypes/snpeff.py @ 0:e8adfc4c0a6b draft
Uploaded
author | iuc |
---|---|
date | Wed, 11 Dec 2013 08:53:32 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e8adfc4c0a6b |
---|---|
1 """ | |
2 SnpEff datatypes | |
3 """ | |
4 import os,os.path,re,sys | |
5 import galaxy.datatypes.data | |
6 from galaxy.datatypes.data import Text | |
7 from galaxy.datatypes.metadata import MetadataElement | |
8 | |
9 class SnpEffDb( Text ): | |
10 """Class describing an IGV tiled data file (TDF) .tdf binary file""" | |
11 file_ext = "snpeffdb" | |
12 MetadataElement( name="genome_version", default=None, desc="Genome Version", readonly=True, visible=True, no_value=None ) | |
13 MetadataElement( name="regulation", default=[], desc="Regulation Names", readonly=True, visible=True, no_value=[] ) | |
14 MetadataElement( name="annotation", default=[], desc="Annotation Names", readonly=True, visible=True, no_value=[] ) | |
15 | |
16 def __init__( self, **kwd ): | |
17 Text.__init__( self, **kwd ) | |
18 | |
19 def set_meta( self, dataset, **kwd ): | |
20 Text.set_meta(self, dataset, **kwd ) | |
21 data_dir = dataset.extra_files_path | |
22 ## search data_dir/genome_version for files | |
23 regulation_pattern = 'regulation_(.+).bin' | |
24 # annotation files that are included in snpEff by a flag | |
25 annotations_dict = {'nextProt.bin' : '-nextprot','motif.bin': '-motif'} | |
26 regulations = [] | |
27 annotations = [] | |
28 if data_dir and os.path.isdir(data_dir): | |
29 for root, dirs, files in os.walk(data_dir): | |
30 for fname in files: | |
31 if fname.startswith('snpEffectPredictor'): | |
32 # if snpEffectPredictor.bin download succeeded | |
33 genome_version = os.path.basename(root) | |
34 dataset.metadata.genome_version = genome_version | |
35 else: | |
36 m = re.match(regulation_pattern,fname) | |
37 if m: | |
38 name = m.groups()[0] | |
39 regulations.append(name) | |
40 elif fname in annotations_dict: | |
41 value = annotations_dict[fname] | |
42 name = value.lstrip('-') | |
43 annotations.append(name) | |
44 dataset.metadata.regulation = regulations | |
45 dataset.metadata.annotation = annotations | |
46 |