在很多时候,你会想要让你的程序与用户(可能是你自己)交互。你会从用户那里得到输入,然后打印一些结果。我们可以分别使用raw_input和print语句来完成这些功能。
a = raw_input("Please input a string\n> ")
print "The string you typed in is: ", a
Please input a string
> a
The string you typed in is: a
print "这是一个保留例子,仅供玩耍\n"
lucky_num = 5
c = 0
while True:
b = int(raw_input("Please input a number to check if you are \
lucky enough to guess right: \n"))
if b == lucky_num:
print "\nYour are so smart!!! ^_^ ^_^"
#----------------------------------------------------
#--------------------------------------------------------
else:
print "\nSorry, but you are not right. %>_<%"
while 1:
c = raw_input("Do you want to try again? [Y/N] \n")
if c == 'Y':
try_again = 1
break
elif c == 'N':
try_again = 0
break
else:
print "I can not understand you, please check your input. \n"
continue
#----------------------------------------------------
if try_again:
print "\nHere comes another run. Enjoy!\n"
continue
else:
print "\nBye-bye\n"
break
这是一个保留例子,仅供玩耍
Please input a number to check if you are lucky enough to guess right:
5
Your are so smart!!! ^_^ ^_^
Please input a number to check if you are lucky enough to guess right:
7
Sorry, but you are not right. %>_<%
Do you want to try again? [Y/N]
Y
Here comes another run. Enjoy!
Please input a number to check if you are lucky enough to guess right:
8
Sorry, but you are not right. %>_<%
Do you want to try again? [Y/N]
N
Bye-bye
文件读写是最常见的输入和输出操作。你可以实用file
或open
来实现。
print "新建一个文件"
context = '''The best way to learn python contains two steps:
1. Rember basic things mentionded here masterly.
2. Practise with real demands.
'''
print "以写入模式(w)打开一个文件并命名为(Test_file.txt)"
fh = open("Test_file.txt","w")
print >>fh, context
#fh.write(context)
fh.close() #文件操作完成后必须关闭文件句柄
新建一个文件
以写入模式(w)打开一个文件并命名为(Test_file.txt)
print "以只读模式(r)读入一个名为(Test_file.txt)的文件"
print
for line in open("Test_file.txt"):
print line
以只读模式(r)读入一个名为(Test_file.txt)的文件
The best way to learn python contains two steps:
1. Rember basic things mentionded here masterly.
2. Practise with real demands.
print '''避免中间空行的输出。
从文件中读取的每一行都带有一个换行符,
而Python的print默认会在输出结束时加上换行符,
因此打印一行会空出一行。为了解决这个问题,有下面两套方案。'''
print "在print语句后加上逗号(,)可以阻止Python对每次输出自动添加的换行符"
print
for line in open("Test_file.txt"):
print line,
print
print "去掉每行自身的换行符"
for line in open("Test_file.txt"):
print line.strip()
避免中间空行的输出。
从文件中读取的每一行都带有一个换行符,
而Python的print默认会在输出结束时加上换行符,
因此打印一行会空出一行。为了解决这个问题,有下面两套方案。
在print语句后加上逗号(,)可以阻止Python对每次输出自动添加的换行符
The best way to learn python contains two steps:
1. Rember basic things mentionded here masterly.
2. Practise with real demands.
去掉每行自身的换行符
The best way to learn python contains two steps:
1. Rember basic things mentionded here masterly.
2. Practise with real demands.
1. FASTA文件格式
>seq_name_1 sequence1 >seq_name_2 sequence2
2. FASTQ文件格式
@HWI-ST1223:80:D1FMTACXX:2:1101:1243:2213 1:N:0:AGTCAA TCTGTGTAGCCNTGGCTGTCCTGGAACTCACTTTGTAGACCAGGCTGGCATGCA + BCCFFFFFFHH#4AFHIJJJJJJJJJJJJJJJJJIJIJJJJJGHIJJJJJJJJJ
cat.py
读入文件,并输出到屏幕 2.用到的知识点给定FASTQ格式的文件(test1.fq), 写一个程序 cat.py
读入文件,并输出到屏幕
3.写程序 splitName.py
, 读入test2.fa, 并取原始序列名字第一个空格前的名字为处理后的序列名字,输出到屏幕
4.写程序 formatFasta.py
, 读入test2.fa,把每条FASTA序列连成一行然后输出
5.写程序 formatFasta-2.py
, 读入test2.fa,把每条FASTA序列分割成80个字母一行的序列
6.写程序 sortFasta.py
, 读入test2.fa, 并取原始序列名字第一个空格前的名字为处理后的序列名字,排序后输出
7.提取给定名字的序列
grepFasta.py
, 提取fasta.name中名字对应的test2.fa的序列,并输出到屏幕。grepFastq.py
, 提取fastq.name中名字对应的test1.fq的序列,并输出到文件。 8.写程序 screenResult.py
, 筛选test.expr中foldChange大于2的基因并且padj小于0.05的基,可以输出整行或只输出基因名字
9.写程序 transferMultipleColumToMatrix.py
将文件(multipleColExpr.txt)中基因在多个组织中的表达数据转换为矩阵形式
10.写程序 reverseComplementary.py
计算序列 ACGTACGTACGTCACGTCAGCTAGAC
的反向互补序列
11.写程序 collapsemiRNAreads.py
转换smRNA-Seq的测序数据
12.简化的短序列匹配程序 (map.py) 把short.fa中的序列比对到ref.fa, 输出短序列匹配到ref.fa文件中哪些序列的哪些位置
备注:
关于程序调试: