標籤:targe out 好的 檔案中 coding -o gcc gen start
#!/usr/bin/python#-*- coding:utf-8 -*-"處理fasta檔案,將ID號和序列放在一行"import syswith open(sys.argv[1]) as f: fw=open(‘out.fasta‘, ‘w‘) line=f.read() line=line.replace(‘\n‘, ‘‘).replace(‘>‘, ‘\n>‘) for aa in line: fw.write(aa) fw.close()""">chr1|hos107.1#gene1ACACTCCCGGGCCCCCCCCCCCCACCTTTCAAAAAAAAAAAAAAAAATTTTCCCCCCAAAGGGG>chr1|hos107.2#gene2ACACTCCCGGGCCCCCCCCCCCCACCTTTCAAAAAAAAAAAAAAAAATTTTC>chr1|hos107.4#gene3ACACTCCCGGGCCCCCCCCCCCCACCTTTCAAAAAAAAAAAAAAAAATTTTC>chr1|hos107.5#gene4ACACTCCCGGGCCCCCCCCCCCCACCTTTCAAAAAAAAAAAAAAAAATTTTC"""""">chr1|hos107.1#gene1ACACTCCCGGGCCCCCCCCCCCCACCTTTCAAAAAAAAAAAAAAAAATTTTCCCCCCAAAGGGG>chr1|hos107.2#gene2ACACTCCCGGGCCCCCCCCCCCCACCTTTCAAAAAAAAAAAAAAAAATTTTC>chr1|hos107.4#gene3ACACTCCCGGGCCCCCCCCCCCCACCTTTCAAAAAAAAAAAAAAAAATTTTC>chr1|hos107.5#gene4ACACTCCCGGGCCCCCCCCCCCCACCTTTCAAAAAAAAAAAAAAAAATTTTC"""#提取目標序列f=open(‘./out.fasta‘, ‘r‘)fw=open(‘target.fasta‘, ‘w‘) for line in f.readlines(): if line.startswith(‘>chr1|hos107.1‘): fw.write(line)f.close()fw.close()"""可以從上述處理好的單行檔案out.fasta中提取指定目標ID的檔案,並將其寫入到target.fasta檔案中"""#整體思路:#先統一fasta檔案格式從test.fasta----out.fasta#取出目標ID序列:out.fasta----target.fasta
python處理fasta檔案,ID和序列放在一行