23
23
import glob
24
24
import pandas as pd
25
25
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 ('~' )
26
28
27
29
class WorkFlow (object ):
28
30
"""Class for implementing a rna/mirna workflow from a set of options"""
@@ -43,16 +45,22 @@ def setup(self):
43
45
self .files = glob .glob (os .path .join (self .path ,'*.fastq' ))
44
46
if len (self .files ) == 0 :
45
47
print ('no fastq files found' )
48
+ if check_snap () == True :
49
+ print (snap_msg )
46
50
return False
47
51
else :
48
52
print ('you should provide at least one file or folder' )
53
+ if check_snap () == True :
54
+ print (snap_msg )
49
55
return False
50
56
self .files = [str (f ) for f in self .files ]
51
57
aligners .BOWTIE_INDEXES = aligners .SUBREAD_INDEXES = self .index_path
52
58
if self .default_params != '' :
53
59
aligners .set_params (self .aligner , self .default_params )
54
60
if not os .path .exists (self .index_path ):
55
61
print ('no such folder for indexes' )
62
+ if check_snap () == True :
63
+ print (snap_msg )
56
64
return False
57
65
if not os .path .exists (self .output ):
58
66
os .mkdir (self .output )
@@ -189,7 +197,7 @@ def map_mirnas(self):
189
197
#novel prediction
190
198
if self .ref_fasta == '' or not os .path .exists (self .ref_fasta ):
191
199
print ('no reference genome file, skipping novel mirna step' )
192
- elif ref_name == None :
200
+ elif ref_name == None or ref_name == '' :
193
201
print ('no index for ref genome, required for novel mirna step' )
194
202
elif check_viennarna () == False :
195
203
print ('Vienna RNA package not installed' )
@@ -413,16 +421,23 @@ def print_help():
413
421
print ('for further information' )
414
422
return
415
423
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 ():
417
432
"""Run mirna test with test files"""
418
433
419
434
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
424
439
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 )
426
441
f1 = os .path .join (base .datadir , 'bovine_plasma_sample.fastq' )
427
442
f2 = os .path .join (base .datadir , 'bovine_serum_sample.fastq' )
428
443
path = os .path .join ('testing' , 'ncrna_map' )
@@ -463,7 +478,11 @@ def main():
463
478
if opts .collapse == True :
464
479
base .collapse_reads (opts .infile )
465
480
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 )
467
486
elif opts .config != None and os .path .exists (opts .config ):
468
487
cp = config .parse_config (opts .config )
469
488
options = config .get_options (cp )
@@ -484,7 +503,7 @@ def main():
484
503
else :
485
504
print_help ()
486
505
elif opts .tests == True :
487
- run_test ()
506
+ test_run ()
488
507
else :
489
508
if opts .config != None :
490
509
conffile = opts .config
0 commit comments