001、 方法1
root@PC1:/home/test3# ls a.txt test.py root@PC1:/home/test3# cat a.txt ## 测试文件 ACTGCCCTAAGTGCTCCTTCTGGC 2 ATAAGGTGCATCTAGTGCAGATA 25 TGAGGTAGTAGTTTGTGCTGTTT 100 TCCTACGAGTTGCATGGATTC 4 root@PC1:/home/test3# cat test.py ## 测试程序 #!/usr/bin/python in_file = open("a.txt", "r") dict1 = {} line = 0 for i in in_file: line += 1 i = i.strip() temp = i.strip().split() key = ">" + "ESB" + "_" + str(line) + "_" + "x" + temp[-1] dict1[key] = temp[0] for i,j in dict1.items(): print(i) print(j) root@PC1:/home/test3# python test.py ## 执行程序 >ESB_1_x2 ACTGCCCTAAGTGCTCCTTCTGGC >ESB_2_x25 ATAAGGTGCATCTAGTGCAGATA >ESB_3_x100 TGAGGTAGTAGTTTGTGCTGTTT >ESB_4_x4 TCCTACGAGTTGCATGGATTC
002、方法2
root@PC1:/home/test3# ls a.txt test.py root@PC1:/home/test3# cat a.txt ## 测试数据 ACTGCCCTAAGTGCTCCTTCTGGC 2 ATAAGGTGCATCTAGTGCAGATA 25 TGAGGTAGTAGTTTGTGCTGTTT 100 TCCTACGAGTTGCATGGATTC 4 root@PC1:/home/test3# cat test.py ## 测试程序 #!/usr/bin/python in_file = open("a.txt", "r") lines = in_file.readlines() dict1 = {} for i in lines: temp = i.strip().split() seq = temp[0] dict1[seq] = temp[1] num = 1 for i,j in dict1.items(): print(">" + "ESB" + "_" + str(num) + "_" + "x" + j) print(i) root@PC1:/home/test3# python test.py ## 运行程序 >ESB_1_x2 ACTGCCCTAAGTGCTCCTTCTGGC >ESB_1_x25 ATAAGGTGCATCTAGTGCAGATA >ESB_1_x100 TGAGGTAGTAGTTTGTGCTGTTT >ESB_1_x4 TCCTACGAGTTGCATGGATTC
参考:https://www.jianshu.com/p/2475c3240a67
标签:test3,Seq,python,PC1,测序,##,ESB,home,root From: https://www.cnblogs.com/liujiaxin2018/p/16585627.html