/usr/lib/python2.7/dist-packages/screed/conversion.py is in python-screed 0.9-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | from __future__ import absolute_import
# Copyright (c) 2008-2010, Michigan State University
from .openscreed import ScreedDB
_MAXLINELEN = 80
_null_quality = '\"' # ASCII 34, e.g 75% chance of incorrect read
def GetComments(value):
"""
Returns description or annotations attributes from given
dictionary object
"""
if 'description' in value:
return value['description']
elif 'annotations' in value:
return value['annotations']
else:
return ''
def linewrap(longString):
"""
Given a long string of characters, inserts newline characters
every _MAXLINELEN characters
"""
res = []
begin = 0
while begin < len(longString):
res.append(longString[begin:begin + _MAXLINELEN])
begin += _MAXLINELEN
return '\n'.join(res)
def GenerateQuality(value):
"""
Returns quality from value if it exists. Otherwise, makes
a null quality. Quality is line wrapped to _MAXLINELEN
either way
"""
if 'quality' in value:
return linewrap(value['quality'])
return linewrap(_null_quality * len(str(value['sequence'])))
def ToFastq(dbFile, outputFile):
"""
Opens the screed database file and attempts to dump it
to a FASTQ-formatted text file
"""
outFile = open(outputFile, 'wb')
db = ScreedDB(dbFile)
for value in db.itervalues():
line = '@%s %s\n%s\n+\n%s\n' % (value['name'],
GetComments(value),
linewrap(str(value['sequence'])),
GenerateQuality(value))
outFile.write(line.encode('UTF-8'))
db.close()
outFile.close()
def ToFasta(dbFile, outputFile):
"""
Opens the screed database file and attempts to dump it
to a FASTA-formatted text file
"""
outFile = open(outputFile, 'wb')
db = ScreedDB(dbFile)
for value in db.itervalues():
line = '>%s %s\n%s\n' % (value['name'], GetComments(value),
linewrap(str(value['sequence'])))
outFile.write(line.encode('UTF-8'))
db.close()
outFile.close()
|