-
Notifications
You must be signed in to change notification settings - Fork 3
stringFile
Wang Yunfei edited this page Feb 9, 2017
·
1 revision
stringFile is used to wrap a string as a file ojbect.
from ngslib import stringFile
mstr = ''
with stringFile() as ofh:
print >>ofh, "First line.\nSecond line."
mstr = ofh.getvalue() # save stringFile content to a sting object.
print mstr
Output:
First line. Second line.
with stringFile(mstr) as ifh:
for line in ifh:
print line.rstrip()
Output:
First line. Second line.
from ngslib import IO,stringFile
mstr=">act-1\\nACGATCGTGCATTACGTCGATCGTAGCATGCTAGCTGCGTACGTAGCTTGCTA\\n>egl-1\\nCAGTCTAGCATCGTACGATCGTGCTACGTACGTATCGTACGATCGTACGTAGCT"
for fa in IO.BioReader(stringFile(mstr),'fasta'):
print fa
Output:
>act-1 ACGATCGTGCATTACGTCGATCGTAGCATGCTAGCTGCGTACGTAGCTTGCTA >egl-1 CAGTCTAGCATCGTACGATCGTGCTACGTACGTATCGTACGATCGTACGTAGCT