Case Operations (upper, lower, swapcase)

Three deterministic operations change the case of sequence characters without altering the underlying bases. XML region tags are preserved intact; only molecular characters are transformed. All three accept an optional region= parameter to restrict the transformation to a named segment.

import poolparty as pp
pp.init()

Examples

upper: uppercase a full sequence

Convert every base of a lowercase sequence to uppercase.

wt = pp.from_seq("atcgatcg")
up = pp.upper(wt)
up.print_library()
up: seq_length=8, num_states=1 ATCGATCG

upper: uppercase a named region only

Only the content of the cre region is uppercased; the flanking lowercase bases remain unchanged.

wt = pp.from_seq("aaaa<cre>atcgatcg</cre>tttt")
up = pp.upper(wt, region="cre")
up.print_library()
up: seq_length=8, num_states=1 aaaa<cre>ATCGATCG</cre>tttt

lower: lowercase a full sequence

Convert every base of an uppercase sequence to lowercase.

wt = pp.from_seq("ATCGATCG")
lo = pp.lower(wt)
lo.print_library()
lo: seq_length=8, num_states=1 atcgatcg

lower: lowercase a named region only

Only the content of the cre region is lowercased; the uppercase flanks are returned unchanged.

wt = pp.from_seq("AAAA<cre>ATCGATCG</cre>TTTT")
lo = pp.lower(wt, region="cre")
lo.print_library()
lo: seq_length=8, num_states=1 AAAA<cre>atcgatcg</cre>TTTT

swapcase: swap a mixed-case sequence

Invert the case of every base: uppercase becomes lowercase and vice versa.

wt = pp.from_seq("ATCGatcg")
sw = pp.swapcase(wt)
sw.print_library()
sw: seq_length=8, num_states=1 atcgATCG

swapcase: visually distinguish a region

Apply lower to the full sequence, then swapcase restricted to the cre region to make that segment stand out in uppercase.

wt = pp.from_seq("AAAA<cre>ATCGATCG</cre>TTTT")
lo = pp.lower(wt)
hi = pp.swapcase(lo, region="cre")
hi.print_library()
hi: seq_length=8, num_states=1 aaaa<cre>ATCGATCG</cre>tttt

See upper(), lower(), and swapcase().