Skip to content

Commit 6a9bca7

Browse files
authored
Merge pull request #134 from HadrienG/1.4.5
1.4.5
2 parents 9b65a3b + feca2b7 commit 6a9bca7

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

iss/app.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def generate_reads(args):
8585
if args.draft:
8686
logger.warning('--draft is in early experimental stage.')
8787
logger.warning(
88-
'--draft disables --abundance_file and --coverage')
88+
'disabling --abundance_file, --coverage and --n_genomes')
8989
logger.warning('Defaulting to --abundance.')
9090
genome_files.extend(args.draft)
9191
if args.ncbi and args.n_genomes_ncbi:
@@ -124,13 +124,22 @@ def generate_reads(args):
124124
genome_files,
125125
output=genome_file)
126126

127+
# for n_genomes we use reservoir sampling to draw random genomes
128+
# from the concatenated genome file. We then override the file.
129+
if args.n_genomes and not args.draft and not args.ncbi:
130+
genome_count = util.count_records(genome_file)
131+
genome_files = [genome for genome in util.reservoir(
132+
SeqIO.parse(genome_file, 'fasta'),
133+
genome_count,
134+
args.n_genomes)]
135+
SeqIO.write(genome_files, genome_file, 'fasta')
136+
127137
assert os.stat(genome_file).st_size != 0
128138
f = open(genome_file, 'r')
129139
with f: # count the number of records
130140
genome_list = util.count_records(f)
131141
except IOError as e:
132142
logger.error('Failed to open genome(s) file:%s' % e)
133-
raise
134143
sys.exit(1)
135144
except AssertionError as e:
136145
logger.error('Genome(s) file seems empty: %s' % genome_file)
@@ -182,11 +191,8 @@ def generate_reads(args):
182191
f = open(genome_file, 'r') # re-opens the file
183192
with f:
184193
fasta_file = SeqIO.parse(f, 'fasta')
185-
if args.n_genomes and not args.ncbi:
186-
n = args.n_genomes[0][0]
187-
else:
188-
n = None
189-
for record in util.reservoir(fasta_file, genome_list, n):
194+
195+
for record in fasta_file:
190196
# generate reads for records
191197
try:
192198
species_abundance = abundance_dic[record.id]
@@ -391,7 +397,6 @@ def main():
391397
'--n_genomes',
392398
'-u',
393399
type=int,
394-
action='append',
395400
metavar='<int>',
396401
help='How many genomes will be used for the simulation. is set with \
397402
--genomes/-g or/and --draft to take random genomes from the \
@@ -545,4 +550,4 @@ def main():
545550
logger = logging.getLogger(__name__)
546551
logger.debug(e)
547552
parser.print_help()
548-
# raise # extra traceback to uncomment if all hell breaks lose
553+
raise # extra traceback to uncomment if all hell breaks lose

iss/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.4.4'
1+
__version__ = '1.4.5'

0 commit comments

Comments
 (0)