Commit aa7ee8d3 authored by bow's avatar bow

Add script examples

parent 67276f19
def calc_gc_percent(seq):
at_count, gc_count = 0, 0
for char in seq:
if char in ('A', 'T'):
at_count += 1
elif char in ('G', 'C'):
gc_count += 1
return gc_count * 100.0 / (gc_count + at_count)
print "The sequence 'CAGG' has a %GC of {:.2f}".format(calc_gc_percent("CAGG"))
#!/usr/bin/env python
def calc_gc_percent(seq):
at_count, gc_count = 0, 0
for char in seq:
if char in ('A', 'T'):
at_count += 1
elif char in ('G', 'C'):
gc_count += 1
return gc_count * 100.0 / (gc_count + at_count)
print "The sequence 'CAGG' has a %GC of {:.2f}".format(calc_gc_percent("CAGG"))
#!/usr/bin/env python
import sys
def calc_gc_percent(seq):
at_count, gc_count = 0, 0
for char in seq:
if char in ('A', 'T'):
at_count += 1
elif char in ('G', 'C'):
gc_count += 1
return gc_count * 100.0 / (gc_count + at_count)
input_seq = sys.argv[1]
print "The sequence '{}' has a %GC of {:.2f}".format(input_seq, calc_gc_percent(input_seq))
#!/usr/bin/env python
import sys
def calc_gc_percent(seq):
at_count, gc_count = 0, 0
for char in seq.upper():
if char in ('A', 'T'):
at_count += 1
elif char in ('G', 'C'):
gc_count += 1
return gc_count * 100.0 / (gc_count + at_count)
input_seq = sys.argv[1]
print "The sequence '{}' has a %GC of {:.2f}".format(input_seq, calc_gc_percent(input_seq))
#!/usr/bin/env python
import sys
def calc_gc_percent(seq):
"""
Calculates the GC percentage of the given sequence.
Arguments:
- seq - the input sequence (string).
Returns:
- GC percentage (float).
"""
at_count, gc_count = 0, 0
# change input to all caps to allow for non-capital
# input sequence.
for char in seq.upper():
if char in ('A', 'T'):
at_count += 1
elif char in ('G', 'C'):
gc_count += 1
return gc_count * 100.0 / (gc_count + at_count)
input_seq = sys.argv[1]
print "The sequence '{}' has a %GC of {:.2f}".format(input_seq, calc_gc_percent(input_seq))
#!/usr/bin/env python
import sys
def calc_gc_percent(seq):
"""
Calculates the GC percentage of the given sequence.
Arguments:
- seq - the input sequence (string).
Returns:
- GC percentage (float).
"""
at_count, gc_count = 0, 0
# change input to all caps to allow for non-capital
# input sequence.
for char in seq.upper():
if char in ('A', 'T'):
at_count += 1
elif char in ('G', 'C'):
gc_count += 1
else:
raise ValueError("Unexpected character found: {}. Only "
"ACTGs are allowed.".format(char))
return gc_count * 100.0 / (gc_count + at_count)
input_seq = sys.argv[1]
print "The sequence '{}' has a %GC of {:.2f}".format(input_seq, calc_gc_percent(input_seq))
#!/usr/bin/env python
import sys
def calc_gc_percent(seq):
"""
Calculates the GC percentage of the given sequence.
Arguments:
- seq - the input sequence (string).
Returns:
- GC percentage (float).
"""
at_count, gc_count = 0, 0
# change input to all caps to allow for non-capital
# input sequence.
for char in seq.upper():
if char in ('A', 'T'):
at_count += 1
elif char in ('G', 'C'):
gc_count += 1
else:
raise ValueError("Unexpected character found: {}. Only "
"ACTGs are allowed.".format(char))
# Corner case handling: empty input sequence.
try:
return gc_count * 100.0 / (gc_count + at_count)
except ZeroDivisionError:
return 0.0
input_seq = sys.argv[1]
print "The sequence '{}' has a %GC of {:.2f}".format(input_seq, calc_gc_percent(input_seq))
#!/usr/bin/env python
import sys
def calc_gc_percent(seq):
"""
Calculates the GC percentage of the given sequence.
Arguments:
- seq - the input sequence (string).
Returns:
- GC percentage (float).
"""
at_count, gc_count = 0, 0
# change input to all caps to allow for non-capital
# input sequence.
for char in seq.upper():
if char in ('A', 'T'):
at_count += 1
elif char in ('G', 'C'):
gc_count += 1
else:
raise ValueError("Unexpected character found: {}. Only "
"ACTGs are allowed.".format(char))
# Corner case handling: empty input sequence.
try:
return gc_count * 100.0 / (gc_count + at_count)
except ZeroDivisionError:
return 0.0
if __name__ == '__main__':
input_seq = sys.argv[1]
print "The sequence '{}' has a %GC of {:.2f}".format(input_seq, calc_gc_percent(input_seq))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment