def createRCs(inputFile, outNameVal):
"""Creates a .bed file with the reverse complements of the given set of
sequences."""
# Determine the stem of the input filename.
fileName = str(inputFile).split('.')[0]
# Open input file for reading.
with open(inputFile, 'r') as f:
file_read = [line.strip() for line in f]
# Create list to hold output.
outList = []
# Parse out probe info, flip sequence to RC, and write to output list.
for i in range(0, len(file_read), 1):
chrom = file_read[i].split('\t')[0]
start = file_read[i].split('\t')[1]
stop = file_read[i].split('\t')[2]
probeSeq = file_read[i].split('\t')[3]
RevSeq = Seq(probeSeq, IUPAC.unambiguous_dna).reverse_complement()
Tm = file_read[i].split('\t')[4]
outList.append('%s\t%s\t%s\t%s\t%s' % (chrom, start, stop, RevSeq, Tm))
# Determine the name of the output file.
if outNameVal is None:
outName = '%s_RC' % fileName
else:
outName = outNameVal
# Create the output file.
output = open('%s.bed' % outName, 'w')
# Write the output file
output.write('\n'.join(outList))
output.close()
评论列表
文章目录