In [ ]:
import random #module random
n = 20
to_be_guessed = int(n * random.random()) + 1
guess = 0
while guess != to_be_guessed:
guess = int(input("New number: "))
if guess > 0:
if guess > to_be_guessed:
print("Number too large")
elif guess < to_be_guessed:
print("Number too small")
else:
print("Sorry that you're giving up!")
break
else:
print("Congratulation. You made it!")
In [1]:
def file_read(fname):
with open (fname, "r") as myfile:
data=myfile.readlines()
print(data)
file_read('Sample1.fasta')
In [16]:
with open('Python1.txt', 'r') as song:
for line in song:
print(line.upper(), end='')
In [17]:
song_uppercase=open('Python1_uc.txt', 'w')
with open('Python1.txt', 'r') as song:
for line in song:
print(line.upper(), end='', file=song_uppercase)
song_uppercase.close()
In [18]:
color = ['TP53','TNF','EGFR','VEGFA']
with open('genes.txt', "w") as myfile:
for c in color:
myfile.write("%s\n" % c)
content = open('genes.txt')
print(content.read())
In [5]:
enzymes = { 'EcoRI':'GAATTC','AvaII':'GGACC', 'BisI':'GCATGCGC' , 'SacII': r'CCGCGG','BamHI': 'GGATCC'}
keyOptions = []
for key in enzymes.keys():
keyOptions.append(key)
print(keyOptions)
chosen = input("From the list of enzymes above, Type enzyme name to modify the motif:\n")
if chosen in keyOptions:
enzyme = input("What is your favorite thing in the category you chose?\n")
enzymes[chosen] = enzyme
print(enzymes)
print('\nDone.\n')
Open and print the reverse complement of each sequence in "Python1_Seqeunces.txt". Each line is the following format: seqName\tsequence\n. Make sure to print the output in fasta format including the sequence name and a note in the description that this is the reverse complement. Print to STDOUT and capture the output into a file with a command line redirect '>'.
Remember is is always a good idea to start with a test set for which you know the correct output.
In [10]:
with open('Python1_Seq.txt', 'r') as sf:
for line in sf:
identifier, sequence = line.rstrip().split("\t")
sequence_RC = sequence.replace('A', 't')
sequence_RC = sequence.replace('T', 'a')
sequence_RC = sequence.replace('C', 'g')
sequence_RC = sequence.replace('G', 'c')
# sequence_RC = sequence_RC.upper()[::-1]
print(">{}_reverse_complement\n{}".format(identifier,sequence))
In [19]:
n_lines=0
n_chars=0
with open('Python1_FASTAQ.fastq', 'r') as fq:
for line in fq:
line=line.rstrip()
n_lines+=1
n_chars+=len(line)
print("There are {} lines and {} characters in the file.\nThe average line length is {}".format(n_lines, n_chars, n_chars/n_lines))