add two new scripts :
fastaHead and fastaTail
This commit is contained in:
37
src/fastaHead.py
Normal file
37
src/fastaHead.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/local/bin/python
|
||||||
|
'''
|
||||||
|
Created on 15 d<>c. 2009
|
||||||
|
|
||||||
|
@author: coissac
|
||||||
|
'''
|
||||||
|
from obitools.fasta import fastaIterator,formatFasta
|
||||||
|
from obitools.options import getOptionManager
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def addHeadOptions(optionManager):
|
||||||
|
optionManager.add_option('-n','--sequence-count',
|
||||||
|
action="store", dest="count",
|
||||||
|
metavar="###",
|
||||||
|
type="int",
|
||||||
|
default=10,
|
||||||
|
help="Count of first sequences to print")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
optionParser = getOptionManager([addHeadOptions],
|
||||||
|
entryIterator=fastaIterator
|
||||||
|
)
|
||||||
|
|
||||||
|
(options, entries) = optionParser()
|
||||||
|
i=0
|
||||||
|
|
||||||
|
for s in entries:
|
||||||
|
if i < options.count:
|
||||||
|
print formatFasta(s)
|
||||||
|
i+=1
|
||||||
|
else:
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
|
41
src/fastaTail.py
Normal file
41
src/fastaTail.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#!/usr/local/bin/python
|
||||||
|
'''
|
||||||
|
Created on 15 d<>c. 2009
|
||||||
|
|
||||||
|
@author: coissac
|
||||||
|
'''
|
||||||
|
from obitools.fasta import fastaIterator,formatFasta
|
||||||
|
from obitools.options import getOptionManager
|
||||||
|
import collections
|
||||||
|
|
||||||
|
def addHeadOptions(optionManager):
|
||||||
|
optionManager.add_option('-n','--sequence-count',
|
||||||
|
action="store", dest="count",
|
||||||
|
metavar="###",
|
||||||
|
type="int",
|
||||||
|
default=10,
|
||||||
|
help="Count of first sequences to print")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
optionParser = getOptionManager([addHeadOptions],
|
||||||
|
entryIterator=fastaIterator
|
||||||
|
)
|
||||||
|
|
||||||
|
(options, entries) = optionParser()
|
||||||
|
i=0
|
||||||
|
|
||||||
|
queue = collections.deque()
|
||||||
|
|
||||||
|
|
||||||
|
for s in entries:
|
||||||
|
queue.append(s)
|
||||||
|
if len(queue) > options.count:
|
||||||
|
queue.popleft()
|
||||||
|
|
||||||
|
while queue:
|
||||||
|
print formatFasta(queue.popleft())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user