-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patho-get-sample-info-from-fasta
executable file
·43 lines (34 loc) · 1.19 KB
/
o-get-sample-info-from-fasta
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2010 - 2012, A. Murat Eren
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# Please read the COPYING file.
import sys
import operator
import Oligotyping.lib.fastalib as u
from Oligotyping.utils.utils import pretty_print as pp
fasta = u.SequenceSource(sys.argv[1])
samples = {}
while next(fasta):
if fasta.pos % 1000 == 0:
sys.stderr.write('\rreads processed so far: %d' % (fasta.pos))
sys.stderr.flush()
sample_name = '_'.join(fasta.id.split('_')[:-1])
if sample_name in samples:
samples[sample_name] += 1
else:
samples[sample_name] = 1
sys.stderr.write('\rSamples and read counts found in the FASTA file:\n')
for sample, read_count in sorted(iter(samples.items()), key=operator.itemgetter(1), reverse = True):
print('%-30s %s' % (sample, pp(read_count)))
print()
print()
print('Total number of samples: ', pp(len(samples)))
print('Total number of reads: ', pp(fasta.pos))
print()
fasta.close()