Skip to content

Commit

Permalink
Added method for single record analysis.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggirelli committed Apr 6, 2018
1 parent 2cb2ba5 commit 7d2e007
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
21 changes: 2 additions & 19 deletions bin/melt_duplex
Original file line number Diff line number Diff line change
Expand Up @@ -181,25 +181,8 @@ def run_fasta(fpath, **kwargs):
# Iterate FASTA records
print_header(**kwargs)
for record in SimpleFastaParser(IH):
record = list(record)
kwargs.update([('name', record[0].split(" ")[0]), ('seq', record[1])])

# Calculate Tm
output = OligoMelt.Duplex.calc_tm(**kwargs)

# Prepare output
if kwargs['fasta_like']:
d = kwargs['fasta_delim']

# Add Tm field to record header
fields = dict(re.findall(r'(tm)%s(.*?);' % d, record[0]))
if "tm" in fields.keys():
record[0] = re.sub(r'(tm)%s(.*?);' % d,
'tm%s%.2f;' % output[4], record[0])
else: record[0] += " tm%s%.2f;" % (d, output[4])

# Output
print(">%s\n%s" % tuple(record))
output = OligoMelt.Duplex.calc_tm_record(record, **kwargs)
if kwargs['fasta_like']: print(">%s\n%s" % tuple(output))
else: print("%s\t%f\t%f\t%f\t%f\t%s" % output)

# Close connection to input file
Expand Down
33 changes: 33 additions & 0 deletions oligo_melting/duplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,39 @@ def calc_tm(seq, name = None, oligo_conc = None, na_conc = None, mg_conc = None,
if not silent: print(output)
return(output)

def calc_tm_record(record, **kwargs):
'''Calculate Tm for a single FASTA record read with SimpleFastaParser.
Args:
record (tuple): (header, seq) tuple.
kwargs: additional arguments to pass to calc_tm
Returns:
tuple: the output of calc_tm.
tuple: (header, seq) if kwargs['fasta_like'].
'''
record = list(record)
kwargs.update([('name', record[0].split(" ")[0]), ('seq', record[1])])

# Calculate Tm
output = OligoMelt.Duplex.calc_tm(**kwargs)

# Prepare output
if kwargs['fasta_like']:
d = kwargs['fasta_delim']

# Add Tm field to record header
fields = dict(re.findall(r'(tm)%s(.*?);' % d, record[0]))
if "tm" in fields.keys():
record[0] = re.sub(r'(tm)%s(.*?);' % d,
'tm%s%.2f;' % output[4], record[0])
else: record[0] += " tm%s%.2f;" % (d, output[4])

# Output
return(record)
else:
return(output)

# END ==========================================================================

################################################################################

0 comments on commit 7d2e007

Please sign in to comment.