Skip to content

Commit 2f42302

Browse files
committed
fixes for snap
1 parent 7d8e1b1 commit 2f42302

File tree

6 files changed

+46
-23
lines changed

6 files changed

+46
-23
lines changed

setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
'pysam>=0.10.0',
1010
'HTSeq>=0.6',
1111
'bx-python>=0.5',
12-
'forgi==0.20']
12+
'forgi==1.1',
13+
'logging_exceptions']
1314

1415
major, minor, micro = sys.version_info[:3]
1516
if major == '2':

smallrnaseq/aligners.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,23 @@ def set_params(aligner, params=None):
4949
global SUBREAD_PARAMS
5050
SUBREAD_PARAMS = params
5151

52-
def build_bowtie_index(fastafile, path):
53-
"""Build a bowtie index"""
52+
def build_bowtie_index(fastafile, path=None):
53+
"""Build a bowtie index
54+
Args:
55+
fastafile: file input
56+
path: folder to place index files
57+
"""
5458

55-
name = os.path.splitext(fastafile)[0]
59+
name = os.path.splitext(os.path.basename(fastafile))[0]
60+
name = os.path.join(path, name)
61+
if not os.path.exists(path):
62+
os.makedirs(path)
5663
cmd = 'bowtie-build -f %s %s' %(fastafile, name)
5764
try:
5865
result = subprocess.check_output(cmd, shell=True, executable='/bin/bash')
5966
except subprocess.CalledProcessError as e:
6067
print (str(e.output))
6168
return
62-
files = glob.glob(name+'*.ebwt')
63-
utils.move_files(files, path)
6469
print ('built bowtie index for %s' %fastafile)
6570
return
6671

@@ -120,4 +125,4 @@ def subread_align(infile, ref, outfile):
120125
print (cmd)
121126
result = subprocess.check_output(cmd, shell=True, executable='/bin/bash',
122127
stderr= subprocess.STDOUT)
123-
return
128+
return

smallrnaseq/app.py

+28-9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import glob
2424
import pandas as pd
2525
from smallrnaseq import config, base, analysis, utils, aligners, novel, plotting, de
26+
snap_msg = 'when running from a snap you should use your home folder for reading/writing'
27+
home = os.path.expanduser('~')
2628

2729
class WorkFlow(object):
2830
"""Class for implementing a rna/mirna workflow from a set of options"""
@@ -43,16 +45,22 @@ def setup(self):
4345
self.files = glob.glob(os.path.join(self.path,'*.fastq'))
4446
if len(self.files) == 0:
4547
print ('no fastq files found')
48+
if check_snap() == True:
49+
print (snap_msg)
4650
return False
4751
else:
4852
print ('you should provide at least one file or folder')
53+
if check_snap() == True:
54+
print (snap_msg)
4955
return False
5056
self.files = [str(f) for f in self.files]
5157
aligners.BOWTIE_INDEXES = aligners.SUBREAD_INDEXES = self.index_path
5258
if self.default_params != '':
5359
aligners.set_params(self.aligner, self.default_params)
5460
if not os.path.exists(self.index_path):
5561
print ('no such folder for indexes')
62+
if check_snap() == True:
63+
print (snap_msg)
5664
return False
5765
if not os.path.exists(self.output):
5866
os.mkdir(self.output)
@@ -189,7 +197,7 @@ def map_mirnas(self):
189197
#novel prediction
190198
if self.ref_fasta == '' or not os.path.exists(self.ref_fasta):
191199
print ('no reference genome file, skipping novel mirna step')
192-
elif ref_name == None:
200+
elif ref_name == None or ref_name == '':
193201
print ('no index for ref genome, required for novel mirna step')
194202
elif check_viennarna() == False:
195203
print ('Vienna RNA package not installed')
@@ -413,16 +421,23 @@ def print_help():
413421
print ('for further information')
414422
return
415423

416-
def run_test():
424+
def check_snap():
425+
"""Check if inside a snap"""
426+
427+
if 'SNAP_COMMON' in os.environ:
428+
return True
429+
return False
430+
431+
def test_run():
417432
"""Run mirna test with test files"""
418433

419434
print ('running miRNA counting test')
420-
indpath = 'testing/indexes'
421-
aligners.BOWTIE_INDEXES = indpath
422-
if not os.path.exists(indpath):
423-
os.makedirs(indpath)
435+
idxpath = 'testing/indexes'
436+
if check_snap() == True:
437+
idxpath = os.path.join(home, idxpath)
438+
aligners.BOWTIE_INDEXES = idxpath
424439
lib1 = os.path.join(base.datadir, 'bosTau8-tRNAs.fa')
425-
aligners.build_bowtie_index(lib1, path=indpath)
440+
aligners.build_bowtie_index(lib1, path=idxpath)
426441
f1 = os.path.join(base.datadir, 'bovine_plasma_sample.fastq')
427442
f2 = os.path.join(base.datadir, 'bovine_serum_sample.fastq')
428443
path = os.path.join('testing', 'ncrna_map')
@@ -463,7 +478,11 @@ def main():
463478
if opts.collapse == True:
464479
base.collapse_reads(opts.infile)
465480
elif opts.build != None:
466-
build_indexes(opts.build, 'indexes')
481+
idxpath = 'indexes'
482+
if check_snap() == True:
483+
idxpath = os.path.join(home, 'indexes')
484+
build_indexes(opts.build, idxpath)
485+
print ('wrote index to folder %s' %idxpath)
467486
elif opts.config != None and os.path.exists(opts.config):
468487
cp = config.parse_config(opts.config)
469488
options = config.get_options(cp)
@@ -484,7 +503,7 @@ def main():
484503
else:
485504
print_help()
486505
elif opts.tests == True:
487-
run_test()
506+
test_run()
488507
else:
489508
if opts.config != None:
490509
conffile = opts.config

smallrnaseq/base.py

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
datadir = os.path.join(path, 'data')
4141
MIRBASE = os.path.join(datadir, 'miRBase_all.csv')
4242

43-
4443
def first(x):
4544
return x.iloc[0]
4645

smallrnaseq/utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ def combine_aligned_reads(path, idx, filenames=None):
539539
#print(f)
540540
name = os.path.splitext(os.path.basename(f))[0]
541541
samfile = os.path.join(path, '%s_%s.sam' %(name,idx))
542+
#print (samfile)
542543
if not os.path.exists(samfile):
543544
print ('no sam file')
544545
continue
@@ -716,7 +717,7 @@ def get_bg(seq, struct=None):
716717
bg.from_dotbracket(struct)
717718
#print (bg.struct)
718719
try:
719-
bg.seq = seq
720+
bg.seq = seq
720721
return bg
721722
except Exception as e:
722723
print (e)

snap/snapcraft.yaml

+3-5
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,22 @@ icon: gui/icon.png
1414
apps:
1515
smallrnaseq:
1616
command: bin/smallrnaseq
17-
plugs: [home,x11,network-bind]
17+
plugs: [home,network-bind]
1818
parts:
1919
part1:
2020
#required for bx-python to build
2121
plugin: python
2222
python-version: python3
2323
python-packages:
2424
[numpy]
25-
stage-packages:
26-
[libblas3,libopenblas-dev]
2725
smallrnaseq:
2826
plugin: python
2927
python-version: python3
3028
source: ../
3129
python-packages:
32-
[Cython,scipy,matplotlib]
30+
[scipy,matplotlib]
3331
build-packages:
3432
[zlib1g-dev,liblzo2-dev]
3533
stage-packages:
36-
[swig3.0,bowtie,ncbi-blast+,samtools,vienna-rna]
34+
[bowtie,ncbi-blast+,samtools,vienna-rna,python3-rna]
3735
after: [part1]

0 commit comments

Comments
 (0)