随笔分类 - python
摘要:001、分别输出染色体ID、序列和序列的长度 [root@PC1 test02]# ls a.fa test.py [root@PC1 test02]# cat a.fa ## 测试数据 >seq1 AGAAGGGG >seq2 AAACCTTTT >seq3 AAATTTCCGG [root@PC
阅读全文
摘要:01、系统信息 [root@PC1 ~]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) 02、测试python3 [root@PC1 ~]# python3 --version bash: python3: command
阅读全文
摘要:001、python程序报错如下: 002、报错原因(看着缩进是一样的,实际上是不一样的) 003、解决方法 将缩进统一调整为tab键, 对齐即可。 参考:https://blog.51cto.com/yunyaniu/4724938 。
阅读全文
摘要:001、basename:去掉路径名,单独获取文件名 >>> import os.path >>> os.getcwd() '/home/test02' >>> os.listdir() ['a.txt', 'test_dir'] >>> os.path.basename("/home/test02
阅读全文
摘要:001、列出当前的工作路径 >>> import os ## 导入os模块 >>> os.getcwd() ## 列出当前的工作路径 '/home/test02' 02、改变工作路径 >>> os.getcwd() '/home/test02' >>> os.chdir("/home/test03"
阅读全文
摘要:001、format >>> "{0} love {1}.{2}".format("I", "FishC", "com") ## 位置参数 'I love FishC.com' >>> "{a} love {b}.{c}".format(a = "I", b = "FishC", c = "com"
阅读全文
摘要:001、 >>> a = [1, 2, 3] >>> b = [4, 5, 6] >>> c = [7, 8, 9, 10, 11] ## 测试列表 >>> list(zip(a,b)) [(1, 4), (2, 5), (3, 6)] >>> list(zip(a,c)) ## 返回列表元祖 [(
阅读全文
摘要:001、 >>> import re >>> str1 = "ab cd" >>> str1 ## 测试字符串 'ab cd' >>> re.sub(r"\s+", " ", str1) ## 将多个连续的空格压缩为空格 'ab cd' 002、 >>> str2 = "sdaaaaakyh" >>
阅读全文
摘要:01、 002、解决方法 [root@PC1 test2]# conda install pandas
阅读全文
摘要:使用translate()方法进行字符串转换,通常需要先创建一个转换表。转换表可以使用Python内置的str.maketrans()方法创建,也可以手动创建一个字典来实现。 001、生成转换表 >>> table = str.maketrans("135", "QMT") ## 将1转换为Q,3转
阅读全文
摘要:lower只对ASCII起作用。 casefold对更多的语言起作用。 001、 >>> str1 = 'ß' ## 测试字符串 >>> str1 'ß' >>> str1.lower() ## lower 'ß' >>> str1 'ß' >>> str1.casefold() ## casefo
阅读全文
摘要:capitalize将首个字母转换为大写, 其余单词不处理。 title将所有单词的首字符转换为大写。 001、 >>> str1 = "ab cd ef" ## 测试字符串 >>> str1 'ab cd ef' >>> str1.capitalize() ## capitalize函数 'Ab
阅读全文
摘要:001、 [root@PC1 test2]# cat a.fa ## 测试fasta文件 >chr1 aattccgggttgggcccyujjjttt ddeeeegghggii >chr2 8883dsfdkkkfftteeessskkk aaadddfffgggcccgggt33 ddggee
阅读全文
摘要:001、 [root@PC1 test05]# ls a.txt test.py [root@PC1 test05]# cat a.txt ## 测试数据 3333 gene 9999 kkkk gene 7777 8888 gene gene 0000 6666 [root@PC1 test05]
阅读全文
摘要:001、 >>> str1 = "ab" ## 测试字符串 >>> str1 'ab' >>> str1.ljust(10) ## 调整宽度为10, 左侧对齐, 默认用空格填充 'ab ' >>> str1.ljust(10, "+") ## 设置用+号填充 'ab++++++++' >>> str
阅读全文
摘要:001、 >>> list1 = [111, 222, 333] >>> list1 [111, 222, 333] >>> list1 = [str(i) for i in list1] ## 将列表中数值转换为字符串 >>> list1 ['111', '222', '333']
阅读全文
摘要:001、 >>> str1 = "abcdaaab" ## 测试字符串 >>> str1.count("a") ## 统计a出现的次数 4 >>> str1.count("b") 2 >>> str1.count("c") 1 >>> str1.count("a", 0, 4) ## 可以指定统计字
阅读全文
摘要:001、全部转换为大写、或者全部转换为小写 >>> str1 = "abcDEFgh" >>> str1.lower() ### 小写 'abcdefgh' >>> str1.upper() ## 大写 'ABCDEFGH' >>> str1 'abcDEFgh' >>> str1.casefold
阅读全文
摘要:001、 >>> list1 = ["aa", "bb", "cc", "dd", "ee", "ff", "gg"] ## 测试列表 >>> list1 ['aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'gg'] >>> list1[2:] ## 从2开始,一直到最
阅读全文
摘要:001、 [root@PC1 test03]# ls a.fa test.py [root@PC1 test03]# cat a.fa ## 测试fasta文件 ATCGATGC [root@PC1 test03]# cat test.py ## python程序 #!/usr/bin/env py
阅读全文