Python文件内容替换

任务:
将pep.muscle.fasta.treefile文件中的信息 根据id.list列表内容进行替换,得到result.treefile文件,三个文件的内容如下:

$ cat id.list
Osativa.pep.fasta       rice
Atrichopoda.pep.fasta   Amboralla
Athaliana_TAIR10.pep.fasta      Arabidopsis
Slycopersicum.pep.fasta tomato
punica.pep.fasta        granate
Egrandis.pep.fasta      eucalyptus
guava.pep.fasta gujava
Mdomestica.pep.fasta    apple
vitis.pep.fasta grapewine
Tcacao.pep.fasta        coco
Ptrichocarpa.pep.fasta  populus

$ cat pep.muscle.fasta.treefile 
(Osativa.pep.fasta:0.7285122740,Atrichopoda.pep.fasta:0.5692585718,((((((Athaliana_TAIR10.pep.fasta:0.4839735487,Tcacao.pep.fasta:0.2127061414)99:0.0321810155,Ptrichocarpa.pep.fasta:0.2552459033)99:0.0264356378,Mdomestica.pep.fasta:0.3076468252)49:0.0163425509,(punica.pep.fasta:0.2933220583,(Egrandis.pep.fasta:0.0711148627,guava.pep.fasta:0.0889934650)100:0.1994642920)100:0.1120315891)100:0.0399147692,vitis.pep.fasta:0.2276156813)79:0.0310185150,Slycopersicum.pep.fasta:0.4236594678)100:0.1491173698);

$ cat result.treefile
(rice:0.7285122740,Amboralla:0.5692585718,((((((Arabidopsis:0.4839735487,coco:0.2127061414)99:0.0321810155,populus:0.2552459033)99:0.0264356378,apple:0.3076468252)49:0.0163425509,(granate:0.2933220583,(eucalyptus:0.0711148627,gujava:0.0889934650)100:0.1994642920)100:0.1120315891)100:0.0399147692,grapewine:0.2276156813)79:0.0310185150,tomato:0.4236594678)100:0.1491173698);

方法1:

#利用shell脚本
for n in `cat id.list | sed 's/\t/#/'` ; do sed -i "s/${n%%#*}/${n#*#}/" pep.muscle.fasta.treefile ; done 

方法2:

#python代码
抽空再补充

你可能感兴趣的:(Python文件内容替换)