pyfaidx 0.3.7__tar.gz → 0.3.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pyfaidx might be problematic. Click here for more details.
- {pyfaidx-0.3.7 → pyfaidx-0.3.8}/PKG-INFO +28 -4
- {pyfaidx-0.3.7 → pyfaidx-0.3.8}/README.rst +27 -3
- {pyfaidx-0.3.7 → pyfaidx-0.3.8}/pyfaidx/__init__.py +89 -34
- {pyfaidx-0.3.7 → pyfaidx-0.3.8}/pyfaidx/cli.py +18 -9
- {pyfaidx-0.3.7 → pyfaidx-0.3.8}/pyfaidx.egg-info/PKG-INFO +28 -4
- pyfaidx-0.3.8/pyfaidx.egg-info/requires.txt +1 -0
- pyfaidx-0.3.7/pyfaidx.egg-info/requires.txt +0 -3
- {pyfaidx-0.3.7 → pyfaidx-0.3.8}/MANIFEST.in +0 -0
- {pyfaidx-0.3.7 → pyfaidx-0.3.8}/pyfaidx.egg-info/SOURCES.txt +0 -0
- {pyfaidx-0.3.7 → pyfaidx-0.3.8}/pyfaidx.egg-info/dependency_links.txt +0 -0
- {pyfaidx-0.3.7 → pyfaidx-0.3.8}/pyfaidx.egg-info/entry_points.txt +0 -0
- {pyfaidx-0.3.7 → pyfaidx-0.3.8}/pyfaidx.egg-info/top_level.txt +0 -0
- {pyfaidx-0.3.7 → pyfaidx-0.3.8}/setup.cfg +4 -4
- {pyfaidx-0.3.7 → pyfaidx-0.3.8}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 1.1
|
|
2
2
|
Name: pyfaidx
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.8
|
|
4
4
|
Summary: pyfaidx: efficient pythonic random access to fasta subsequences
|
|
5
5
|
Home-page: http://mattshirley.com
|
|
6
6
|
Author: Matthew Shirley
|
|
@@ -36,8 +36,6 @@ Description: |Travis| |PyPI| |Landscape| |Coveralls|
|
|
|
36
36
|
Usage
|
|
37
37
|
-----
|
|
38
38
|
|
|
39
|
-
.. _benchmark: http://www.biostars.org/p/93364/#93390
|
|
40
|
-
|
|
41
39
|
.. code:: python
|
|
42
40
|
|
|
43
41
|
>>> from pyfaidx import Fasta
|
|
@@ -151,6 +149,18 @@ Description: |Travis| |PyPI| |Landscape| |Coveralls|
|
|
|
151
149
|
>NR_104212:1-10
|
|
152
150
|
CCCCGCCCCT
|
|
153
151
|
|
|
152
|
+
Filter functions (returning True) limit the index:
|
|
153
|
+
|
|
154
|
+
.. code:: python
|
|
155
|
+
|
|
156
|
+
# new in v0.3.8
|
|
157
|
+
>>> from pyfaidx import Fasta
|
|
158
|
+
>>> genes = Fasta('tests/data/genes.fasta', filt_function = lambda x: x[0] == 'N')
|
|
159
|
+
>>> genes.keys()
|
|
160
|
+
dict_keys(['NR_104212', 'NM_001282543', 'NR_104216', 'NR_104215', 'NM_001282549', 'NM_000465', 'NM_001282545', 'NM_001282548'])
|
|
161
|
+
>>> genes['XM_005249644']
|
|
162
|
+
KeyError: XM_005249644 not in tests/data/genes.fasta.
|
|
163
|
+
|
|
154
164
|
Or just get a Python string:
|
|
155
165
|
|
|
156
166
|
.. code:: python
|
|
@@ -231,6 +241,10 @@ Description: |Travis| |PyPI| |Landscape| |Coveralls|
|
|
|
231
241
|
>NM_001282543.1:300-320
|
|
232
242
|
GTAATTGTGTAAGTGACTGCA
|
|
233
243
|
|
|
244
|
+
$ faidx --full-names tests/data/genes.fasta NM_001282543.1:201-210
|
|
245
|
+
>NM_001282543.1| Homo sapiens BRCA1 associated RING domain 1 (BARD1), transcript variant 2, mRNA
|
|
246
|
+
CTCGTTCCGC
|
|
247
|
+
|
|
234
248
|
$ faidx --no-names tests/data/genes.fasta NM_001282543.1:201-210 NM_001282543.1:300-320
|
|
235
249
|
CTCGTTCCGC
|
|
236
250
|
GTAATTGTGTAAGTGACTGCA
|
|
@@ -254,6 +268,16 @@ Description: |Travis| |PyPI| |Landscape| |Coveralls|
|
|
|
254
268
|
..................
|
|
255
269
|
..................
|
|
256
270
|
|
|
271
|
+
$ faidx --regex "^NM_00128254[35]" genes.fasta
|
|
272
|
+
>NM_001282543.1
|
|
273
|
+
..................
|
|
274
|
+
..................
|
|
275
|
+
..................
|
|
276
|
+
>NM_001282545.1
|
|
277
|
+
..................
|
|
278
|
+
..................
|
|
279
|
+
..................
|
|
280
|
+
|
|
257
281
|
$ faidx --lazy tests/data/genes.fasta NM_001282543.1:5460-5480
|
|
258
282
|
>NM_001282543.1:5460-5480
|
|
259
283
|
AAAAAAANNNNNNNNNNNNNN
|
|
@@ -332,7 +356,7 @@ Description: |Travis| |PyPI| |Landscape| |Coveralls|
|
|
|
332
356
|
|
|
333
357
|
|
|
334
358
|
Changelog
|
|
335
|
-
|
|
359
|
+
---------
|
|
336
360
|
|
|
337
361
|
Please see the `releases <https://github.com/mdshw5/pyfaidx/releases>`_ for a
|
|
338
362
|
comprehensive list of version changes.
|
|
@@ -28,8 +28,6 @@ This package is tested under Linux, MacOS, and Windows using Python 3.2-3.4, 2.7
|
|
|
28
28
|
Usage
|
|
29
29
|
-----
|
|
30
30
|
|
|
31
|
-
.. _benchmark: http://www.biostars.org/p/93364/#93390
|
|
32
|
-
|
|
33
31
|
.. code:: python
|
|
34
32
|
|
|
35
33
|
>>> from pyfaidx import Fasta
|
|
@@ -143,6 +141,18 @@ Custom key functions provide cleaner access:
|
|
|
143
141
|
>NR_104212:1-10
|
|
144
142
|
CCCCGCCCCT
|
|
145
143
|
|
|
144
|
+
Filter functions (returning True) limit the index:
|
|
145
|
+
|
|
146
|
+
.. code:: python
|
|
147
|
+
|
|
148
|
+
# new in v0.3.8
|
|
149
|
+
>>> from pyfaidx import Fasta
|
|
150
|
+
>>> genes = Fasta('tests/data/genes.fasta', filt_function = lambda x: x[0] == 'N')
|
|
151
|
+
>>> genes.keys()
|
|
152
|
+
dict_keys(['NR_104212', 'NM_001282543', 'NR_104216', 'NR_104215', 'NM_001282549', 'NM_000465', 'NM_001282545', 'NM_001282548'])
|
|
153
|
+
>>> genes['XM_005249644']
|
|
154
|
+
KeyError: XM_005249644 not in tests/data/genes.fasta.
|
|
155
|
+
|
|
146
156
|
Or just get a Python string:
|
|
147
157
|
|
|
148
158
|
.. code:: python
|
|
@@ -223,6 +233,10 @@ For usage type ``faidx -h``.
|
|
|
223
233
|
>NM_001282543.1:300-320
|
|
224
234
|
GTAATTGTGTAAGTGACTGCA
|
|
225
235
|
|
|
236
|
+
$ faidx --full-names tests/data/genes.fasta NM_001282543.1:201-210
|
|
237
|
+
>NM_001282543.1| Homo sapiens BRCA1 associated RING domain 1 (BARD1), transcript variant 2, mRNA
|
|
238
|
+
CTCGTTCCGC
|
|
239
|
+
|
|
226
240
|
$ faidx --no-names tests/data/genes.fasta NM_001282543.1:201-210 NM_001282543.1:300-320
|
|
227
241
|
CTCGTTCCGC
|
|
228
242
|
GTAATTGTGTAAGTGACTGCA
|
|
@@ -246,6 +260,16 @@ For usage type ``faidx -h``.
|
|
|
246
260
|
..................
|
|
247
261
|
..................
|
|
248
262
|
|
|
263
|
+
$ faidx --regex "^NM_00128254[35]" genes.fasta
|
|
264
|
+
>NM_001282543.1
|
|
265
|
+
..................
|
|
266
|
+
..................
|
|
267
|
+
..................
|
|
268
|
+
>NM_001282545.1
|
|
269
|
+
..................
|
|
270
|
+
..................
|
|
271
|
+
..................
|
|
272
|
+
|
|
249
273
|
$ faidx --lazy tests/data/genes.fasta NM_001282543.1:5460-5480
|
|
250
274
|
>NM_001282543.1:5460-5480
|
|
251
275
|
AAAAAAANNNNNNNNNNNNNN
|
|
@@ -324,7 +348,7 @@ A lower-level Faidx class is also available:
|
|
|
324
348
|
|
|
325
349
|
|
|
326
350
|
Changelog
|
|
327
|
-
|
|
351
|
+
---------
|
|
328
352
|
|
|
329
353
|
Please see the `releases <https://github.com/mdshw5/pyfaidx/releases>`_ for a
|
|
330
354
|
comprehensive list of version changes.
|
|
@@ -21,7 +21,7 @@ if PY2:
|
|
|
21
21
|
|
|
22
22
|
dna_bases = re.compile(r'([ACTGNactgnYRWSKMDVHBXyrwskmdvhbx]+)')
|
|
23
23
|
|
|
24
|
-
__version__ = '0.3.
|
|
24
|
+
__version__ = '0.3.8'
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
class FastaIndexingError(Exception):
|
|
@@ -160,7 +160,7 @@ class Sequence(object):
|
|
|
160
160
|
return (g + c) / len(self.seq)
|
|
161
161
|
|
|
162
162
|
|
|
163
|
-
class IndexRecord(namedtuple('IndexRecord', ['rlen', 'offset', 'lenc', 'lenb'])):
|
|
163
|
+
class IndexRecord(namedtuple('IndexRecord', ['rlen', 'offset', 'lenc', 'lenb', 'bend', 'prev_bend'])):
|
|
164
164
|
__slots__ = ()
|
|
165
165
|
|
|
166
166
|
def __getitem__(self, key):
|
|
@@ -176,7 +176,7 @@ class Faidx(object):
|
|
|
176
176
|
""" A python implementation of samtools faidx FASTA indexing """
|
|
177
177
|
def __init__(self, filename, default_seq=None, key_function=None,
|
|
178
178
|
as_raw=False, strict_bounds=False, read_ahead=None,
|
|
179
|
-
mutable=False, split_char=None):
|
|
179
|
+
mutable=False, split_char=None, filt_function=None):
|
|
180
180
|
"""
|
|
181
181
|
filename: name of fasta file
|
|
182
182
|
key_function: optional callback function which should return a unique
|
|
@@ -192,6 +192,7 @@ class Faidx(object):
|
|
|
192
192
|
self.file = open(filename, 'rb')
|
|
193
193
|
self.indexname = filename + '.fai'
|
|
194
194
|
self.key_function = key_function if key_function else lambda rname: rname
|
|
195
|
+
self.filt_function = filt_function if filt_function else lambda x: True
|
|
195
196
|
self.as_raw = as_raw
|
|
196
197
|
self.default_seq = default_seq
|
|
197
198
|
self.strict_bounds = strict_bounds
|
|
@@ -229,10 +230,15 @@ class Faidx(object):
|
|
|
229
230
|
def read_fai(self, split_char):
|
|
230
231
|
duplicate_ids = []
|
|
231
232
|
with open(self.indexname) as index:
|
|
233
|
+
prev_bend = 0
|
|
232
234
|
for line in index:
|
|
233
|
-
line = line.
|
|
235
|
+
line = line.rstrip()
|
|
234
236
|
rname, rlen, offset, lenc, lenb = line.split('\t')
|
|
237
|
+
rlen, offset, lenc, lenb = map(int, (rlen, offset, lenc, lenb))
|
|
238
|
+
newlines = rlen // lenc * (lenb - lenc)
|
|
239
|
+
bend = offset + newlines + rlen
|
|
235
240
|
rname = self.key_function(rname).split(split_char)
|
|
241
|
+
rname = filter(self.filt_function, rname)
|
|
236
242
|
for key in rname:
|
|
237
243
|
if key in self.index and not split_char:
|
|
238
244
|
raise ValueError('Duplicate key "%s"' % rname)
|
|
@@ -240,10 +246,8 @@ class Faidx(object):
|
|
|
240
246
|
duplicate_ids.append(key)
|
|
241
247
|
continue
|
|
242
248
|
else:
|
|
243
|
-
self.index[key] = IndexRecord(
|
|
244
|
-
|
|
245
|
-
lenc,
|
|
246
|
-
lenb)))
|
|
249
|
+
self.index[key] = IndexRecord(rlen, offset, lenc, lenb, bend, prev_bend)
|
|
250
|
+
prev_bend = bend
|
|
247
251
|
for dup in duplicate_ids:
|
|
248
252
|
self.index.pop(dup, None)
|
|
249
253
|
|
|
@@ -254,15 +258,15 @@ class Faidx(object):
|
|
|
254
258
|
raise FastaIndexingError("Line length of fasta"
|
|
255
259
|
" file is not "
|
|
256
260
|
"consistent! "
|
|
257
|
-
|
|
258
|
-
|
|
261
|
+
"Inconsistent line found in >{0} at "
|
|
262
|
+
"line {1:n}.".format(rname, bad_lines[0] + 1))
|
|
259
263
|
elif len(bad_lines) == 1: # check that the line is previous line
|
|
260
264
|
if bad_lines[0] + 1 != i:
|
|
261
265
|
raise FastaIndexingError("Line length of fasta"
|
|
262
266
|
" file is not "
|
|
263
267
|
"consistent! "
|
|
264
|
-
|
|
265
|
-
|
|
268
|
+
"Inconsistent line found in >{0} at "
|
|
269
|
+
"line {1:n}.".format(rname, bad_lines[0] + 1))
|
|
266
270
|
|
|
267
271
|
with open(self.filename, 'r') as fastafile:
|
|
268
272
|
with open(self.indexname, 'w') as indexfile:
|
|
@@ -358,19 +362,16 @@ class Faidx(object):
|
|
|
358
362
|
|
|
359
363
|
|
|
360
364
|
# Calculate offset (https://github.com/samtools/htslib/blob/20238f354894775ed22156cdd077bc0d544fa933/faidx.c#L398)
|
|
361
|
-
|
|
362
|
-
newlines_before = int((start0 - 1) / i.lenc *
|
|
363
|
-
(i.lenb - i.lenc)) if start0 > 0 else 0
|
|
365
|
+
newlines_before = int((start0 - 1) / i.lenc * (i.lenb - i.lenc)) if start0 > 0 else 0
|
|
364
366
|
newlines_to_end = int(end / i.lenc * (i.lenb - i.lenc))
|
|
365
367
|
newlines_inside = newlines_to_end - newlines_before
|
|
366
368
|
seq_blen = newlines_inside + seq_len
|
|
367
369
|
bstart = i.offset + newlines_before + start0
|
|
368
|
-
bend = i.offset + newlines_total + i.rlen
|
|
369
370
|
self.file.seek(bstart)
|
|
370
371
|
|
|
371
|
-
if bstart + seq_blen > bend and not self.strict_bounds:
|
|
372
|
-
seq_blen = bend - bstart
|
|
373
|
-
elif bstart + seq_blen > bend and self.strict_bounds:
|
|
372
|
+
if bstart + seq_blen > i.bend and not self.strict_bounds:
|
|
373
|
+
seq_blen = i.bend - bstart
|
|
374
|
+
elif bstart + seq_blen > i.bend and self.strict_bounds:
|
|
374
375
|
raise FetchError("Requested end coordinate {0:n} outside of {1}. "
|
|
375
376
|
"\n".format(end, rname))
|
|
376
377
|
if seq_blen > 0:
|
|
@@ -435,7 +436,6 @@ class FastaRecord(object):
|
|
|
435
436
|
def __init__(self, name, fa):
|
|
436
437
|
self.name = name
|
|
437
438
|
self._fa = fa
|
|
438
|
-
self._len = self._fa.faidx.index[self.name].rlen
|
|
439
439
|
|
|
440
440
|
def __getitem__(self, n):
|
|
441
441
|
"""Return sequence from region [start, end)
|
|
@@ -478,7 +478,7 @@ class FastaRecord(object):
|
|
|
478
478
|
return 'FastaRecord("%s")' % (self.name)
|
|
479
479
|
|
|
480
480
|
def __len__(self):
|
|
481
|
-
return self.
|
|
481
|
+
return self._fa.faidx.index[self.name].rlen
|
|
482
482
|
|
|
483
483
|
def __str__(self):
|
|
484
484
|
return str(self[:])
|
|
@@ -486,17 +486,14 @@ class FastaRecord(object):
|
|
|
486
486
|
@property
|
|
487
487
|
def long_name(self):
|
|
488
488
|
""" Read the actual defline from self._fa.faidx mdshw5/pyfaidx#54 """
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
defline_end = self._fa.faidx.index[self.name].offset
|
|
498
|
-
self._fa.faidx.file.seek(defline_start)
|
|
499
|
-
return self._fa.faidx.file.read(defline_end - defline_start).decode()[1:-1]
|
|
489
|
+
index_record = self._fa.faidx.index[self.name]
|
|
490
|
+
prev_bend = index_record.prev_bend
|
|
491
|
+
newline_len = index_record.lenb - index_record.lenc
|
|
492
|
+
if prev_bend > 0:
|
|
493
|
+
prev_bend += newline_len # account for newline
|
|
494
|
+
defline_end = index_record.offset
|
|
495
|
+
self._fa.faidx.file.seek(prev_bend)
|
|
496
|
+
return self._fa.faidx.file.read(defline_end - prev_bend).decode()[1:-1]
|
|
500
497
|
|
|
501
498
|
class MutableFastaRecord(FastaRecord):
|
|
502
499
|
def __init__(self, name, fa):
|
|
@@ -530,7 +527,7 @@ class MutableFastaRecord(FastaRecord):
|
|
|
530
527
|
|
|
531
528
|
|
|
532
529
|
class Fasta(object):
|
|
533
|
-
def __init__(self, filename, default_seq=None, key_function=None, as_raw=False, strict_bounds=False, read_ahead=None, mutable=False, split_char=None):
|
|
530
|
+
def __init__(self, filename, default_seq=None, key_function=None, as_raw=False, strict_bounds=False, read_ahead=None, mutable=False, split_char=None, filt_function=None):
|
|
534
531
|
"""
|
|
535
532
|
An object that provides a pygr compatible interface.
|
|
536
533
|
filename: name of fasta file
|
|
@@ -539,7 +536,8 @@ class Fasta(object):
|
|
|
539
536
|
self.mutable = mutable
|
|
540
537
|
self.faidx = Faidx(filename, key_function=key_function, as_raw=as_raw,
|
|
541
538
|
default_seq=default_seq, strict_bounds=strict_bounds,
|
|
542
|
-
read_ahead=read_ahead, mutable=mutable, split_char=split_char
|
|
539
|
+
read_ahead=read_ahead, mutable=mutable, split_char=split_char,
|
|
540
|
+
filt_function=filt_function)
|
|
543
541
|
self.keys = self.faidx.index.keys
|
|
544
542
|
if not self.mutable:
|
|
545
543
|
self.records = dict([(rname, FastaRecord(rname, self)) for rname in self.keys()])
|
|
@@ -584,6 +582,63 @@ class Fasta(object):
|
|
|
584
582
|
self.faidx.__exit__(*args)
|
|
585
583
|
|
|
586
584
|
|
|
585
|
+
class FastaVariant(Fasta):
|
|
586
|
+
""" Return consensus sequence from FASTA and VCF inputs
|
|
587
|
+
"""
|
|
588
|
+
def __init__(self, filename, vcf_file, het=False, hom=True, **kwargs):
|
|
589
|
+
try:
|
|
590
|
+
import pysam
|
|
591
|
+
except ImportError:
|
|
592
|
+
raise ImportError("pysam must be installed for VCF Consensus.")
|
|
593
|
+
try:
|
|
594
|
+
import vcf
|
|
595
|
+
except ImportError:
|
|
596
|
+
raise ImportError("PyVCF must be installed for VCF Consensus.")
|
|
597
|
+
self.vcf = vcf.Reader(filename=vcf_file)
|
|
598
|
+
if len(self.vcf.samples) > 1:
|
|
599
|
+
raise ValueError("VCF file must contain only one sample!")
|
|
600
|
+
if het and hom:
|
|
601
|
+
self.gt_type = set((1, 2))
|
|
602
|
+
elif het:
|
|
603
|
+
self.gt_type = set((1,))
|
|
604
|
+
elif hom:
|
|
605
|
+
self.gt_type = set((2,))
|
|
606
|
+
else:
|
|
607
|
+
self.gt_type = set((0,))
|
|
608
|
+
super(FastaVariant, self).__init__(filename, **kwargs)
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
def __repr__(self):
|
|
612
|
+
return 'FastaVariant("%s", "%s", gt="%s")' % (self.filename, self.vcf.filename, str(self.gt_type))
|
|
613
|
+
|
|
614
|
+
def get_seq(self, name, start, end):
|
|
615
|
+
"""Return a sequence by record name and interval [start, end).
|
|
616
|
+
Replace positions with polymorphism with variant.
|
|
617
|
+
Coordinates are 0-based, end-exclusive.
|
|
618
|
+
"""
|
|
619
|
+
seq = self.faidx.fetch(name, start, end)
|
|
620
|
+
if self.faidx.as_raw:
|
|
621
|
+
seq_mut = list(seq)
|
|
622
|
+
del seq
|
|
623
|
+
else:
|
|
624
|
+
seq_mut = list(seq.seq)
|
|
625
|
+
del seq.seq
|
|
626
|
+
var = self.vcf.fetch(name, start, end)
|
|
627
|
+
for record in var:
|
|
628
|
+
if record.is_snp: # skip indels
|
|
629
|
+
sample = record.samples[0]
|
|
630
|
+
if sample.gt_type in self.gt_type:
|
|
631
|
+
alt = record.ALT[0]
|
|
632
|
+
i = (record.POS - 1) - (start - 1)
|
|
633
|
+
seq_mut[i:i + len(alt)] = str(alt)
|
|
634
|
+
# slice the list in case we added an MNP in last position
|
|
635
|
+
if self.faidx.as_raw:
|
|
636
|
+
return ''.join(seq_mut[:end - start + 1])
|
|
637
|
+
else:
|
|
638
|
+
seq.seq = ''.join(seq_mut[:end - start + 1])
|
|
639
|
+
return seq
|
|
640
|
+
|
|
641
|
+
|
|
587
642
|
def wrap_sequence(n, sequence, fillvalue=''):
|
|
588
643
|
args = [iter(sequence)] * n
|
|
589
644
|
for line in zip_longest(fillvalue=fillvalue, *args):
|
|
@@ -21,6 +21,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."""
|
|
|
21
21
|
import argparse
|
|
22
22
|
import sys
|
|
23
23
|
import os.path
|
|
24
|
+
import re
|
|
24
25
|
from pyfaidx import Faidx, Fasta, wrap_sequence, FetchError, ucsc_split, bed_split
|
|
25
26
|
|
|
26
27
|
keepcharacters = (' ', '.', '_')
|
|
@@ -30,7 +31,8 @@ def write_sequence(args):
|
|
|
30
31
|
_, ext = os.path.splitext(args.fasta)
|
|
31
32
|
if ext:
|
|
32
33
|
ext = ext[1:] # remove the dot from extension
|
|
33
|
-
|
|
34
|
+
filt_function = re.compile(args.regex).search
|
|
35
|
+
fasta = Fasta(args.fasta, default_seq=args.default_seq, strict_bounds=not args.lazy, split_char=args.delimiter, filt_function=filt_function)
|
|
34
36
|
|
|
35
37
|
regions_to_fetch, split_function = split_regions(args)
|
|
36
38
|
if not regions_to_fetch:
|
|
@@ -61,7 +63,11 @@ def fetch_sequence(args, fasta, name, start=None, end=None):
|
|
|
61
63
|
sequence = sequence.complement
|
|
62
64
|
if args.reverse:
|
|
63
65
|
sequence = sequence.reverse
|
|
64
|
-
if
|
|
66
|
+
if args.no_names:
|
|
67
|
+
pass
|
|
68
|
+
elif args.full_names:
|
|
69
|
+
yield ''.join(['>', fasta[name].long_name, '\n'])
|
|
70
|
+
else:
|
|
65
71
|
if start or end:
|
|
66
72
|
yield ''.join(['>', sequence.longname, '\n'])
|
|
67
73
|
else:
|
|
@@ -105,17 +111,20 @@ def main(ext_args=None):
|
|
|
105
111
|
parser.add_argument('fasta', type=str, help='FASTA file')
|
|
106
112
|
parser.add_argument('regions', type=str, nargs='*', help="space separated regions of sequence to fetch e.g. chr1:1-1000")
|
|
107
113
|
parser.add_argument('-b', '--bed', type=argparse.FileType('r'), help="bed file of regions")
|
|
108
|
-
parser.add_argument('--stats', action="store_true", default=False, help="print basic stats
|
|
114
|
+
parser.add_argument('-i', '--stats', action="store_true", default=False, help="print basic stats FASTA sequences. default: %(default)s")
|
|
109
115
|
parser.add_argument('-c', '--complement', action="store_true", default=False, help="complement the sequence. default: %(default)s")
|
|
110
116
|
parser.add_argument('-r', '--reverse', action="store_true", default=False, help="reverse the sequence. default: %(default)s")
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
parser.add_argument('--
|
|
117
|
+
names = parser.add_mutually_exclusive_group()
|
|
118
|
+
names.add_argument('-n', '--no-names', action="store_true", default=False, help="omit sequence names from output. default: %(default)s")
|
|
119
|
+
names.add_argument('-f', '--full-names', action="store_true", default=False, help="output full names including description. default: %(default)s")
|
|
120
|
+
parser.add_argument('-x', '--split-files', action="store_true", default=False, help="write each region to a separate file (names are derived from regions)")
|
|
121
|
+
parser.add_argument('-l', '--lazy', action="store_true", default=False, help="fill in --default-seq for missing ranges. default: %(default)s")
|
|
122
|
+
parser.add_argument('-s', '--default-seq', type=check_seq_length, default='N', help='default base for missing positions and masking. default: %(default)s')
|
|
115
123
|
parser.add_argument('-d', '--delimiter', type=str, default=None, help='delimiter for splitting names to multiple values (duplicate names will be discarded). default: %(default)s')
|
|
124
|
+
parser.add_argument('-g', '--regex', type=str, default='.*', help='regular expression for filtering non-matching sequence names. default: %(default)s')
|
|
116
125
|
masking = parser.add_mutually_exclusive_group()
|
|
117
|
-
masking.add_argument('--mask-with-default-seq', action="store_true", default=False, help="mask the FASTA file using
|
|
118
|
-
masking.add_argument('--mask-by-case', action="store_true", default=False, help="mask the FASTA file by changing to lowercase. default: %(default)s")
|
|
126
|
+
masking.add_argument('-m', '--mask-with-default-seq', action="store_true", default=False, help="mask the FASTA file using --default-seq default: %(default)s")
|
|
127
|
+
masking.add_argument('-M', '--mask-by-case', action="store_true", default=False, help="mask the FASTA file by changing to lowercase. default: %(default)s")
|
|
119
128
|
parser.add_argument('--version', action="version", version=__version__, help="print pyfaidx version number")
|
|
120
129
|
# print help usage if no arguments are supplied
|
|
121
130
|
if len(sys.argv)==1 and not ext_args:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 1.1
|
|
2
2
|
Name: pyfaidx
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.8
|
|
4
4
|
Summary: pyfaidx: efficient pythonic random access to fasta subsequences
|
|
5
5
|
Home-page: http://mattshirley.com
|
|
6
6
|
Author: Matthew Shirley
|
|
@@ -36,8 +36,6 @@ Description: |Travis| |PyPI| |Landscape| |Coveralls|
|
|
|
36
36
|
Usage
|
|
37
37
|
-----
|
|
38
38
|
|
|
39
|
-
.. _benchmark: http://www.biostars.org/p/93364/#93390
|
|
40
|
-
|
|
41
39
|
.. code:: python
|
|
42
40
|
|
|
43
41
|
>>> from pyfaidx import Fasta
|
|
@@ -151,6 +149,18 @@ Description: |Travis| |PyPI| |Landscape| |Coveralls|
|
|
|
151
149
|
>NR_104212:1-10
|
|
152
150
|
CCCCGCCCCT
|
|
153
151
|
|
|
152
|
+
Filter functions (returning True) limit the index:
|
|
153
|
+
|
|
154
|
+
.. code:: python
|
|
155
|
+
|
|
156
|
+
# new in v0.3.8
|
|
157
|
+
>>> from pyfaidx import Fasta
|
|
158
|
+
>>> genes = Fasta('tests/data/genes.fasta', filt_function = lambda x: x[0] == 'N')
|
|
159
|
+
>>> genes.keys()
|
|
160
|
+
dict_keys(['NR_104212', 'NM_001282543', 'NR_104216', 'NR_104215', 'NM_001282549', 'NM_000465', 'NM_001282545', 'NM_001282548'])
|
|
161
|
+
>>> genes['XM_005249644']
|
|
162
|
+
KeyError: XM_005249644 not in tests/data/genes.fasta.
|
|
163
|
+
|
|
154
164
|
Or just get a Python string:
|
|
155
165
|
|
|
156
166
|
.. code:: python
|
|
@@ -231,6 +241,10 @@ Description: |Travis| |PyPI| |Landscape| |Coveralls|
|
|
|
231
241
|
>NM_001282543.1:300-320
|
|
232
242
|
GTAATTGTGTAAGTGACTGCA
|
|
233
243
|
|
|
244
|
+
$ faidx --full-names tests/data/genes.fasta NM_001282543.1:201-210
|
|
245
|
+
>NM_001282543.1| Homo sapiens BRCA1 associated RING domain 1 (BARD1), transcript variant 2, mRNA
|
|
246
|
+
CTCGTTCCGC
|
|
247
|
+
|
|
234
248
|
$ faidx --no-names tests/data/genes.fasta NM_001282543.1:201-210 NM_001282543.1:300-320
|
|
235
249
|
CTCGTTCCGC
|
|
236
250
|
GTAATTGTGTAAGTGACTGCA
|
|
@@ -254,6 +268,16 @@ Description: |Travis| |PyPI| |Landscape| |Coveralls|
|
|
|
254
268
|
..................
|
|
255
269
|
..................
|
|
256
270
|
|
|
271
|
+
$ faidx --regex "^NM_00128254[35]" genes.fasta
|
|
272
|
+
>NM_001282543.1
|
|
273
|
+
..................
|
|
274
|
+
..................
|
|
275
|
+
..................
|
|
276
|
+
>NM_001282545.1
|
|
277
|
+
..................
|
|
278
|
+
..................
|
|
279
|
+
..................
|
|
280
|
+
|
|
257
281
|
$ faidx --lazy tests/data/genes.fasta NM_001282543.1:5460-5480
|
|
258
282
|
>NM_001282543.1:5460-5480
|
|
259
283
|
AAAAAAANNNNNNNNNNNNNN
|
|
@@ -332,7 +356,7 @@ Description: |Travis| |PyPI| |Landscape| |Coveralls|
|
|
|
332
356
|
|
|
333
357
|
|
|
334
358
|
Changelog
|
|
335
|
-
|
|
359
|
+
---------
|
|
336
360
|
|
|
337
361
|
Please see the `releases <https://github.com/mdshw5/pyfaidx/releases>`_ for a
|
|
338
362
|
comprehensive list of version changes.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
six
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|