newbie here!
I have a text file containing fasta headers (about 1.5K; abc.txt):
>CP008746 location=complement(3239792..3241504),organism=Methanosarcina barkeri CM1,definition=methyl-coenzyme M reductase alpha subunit McrA
>CP009530 location=complement(2979486..2981198),organism=Methanosarcina barkeri 227,definition=Methyl coenzyme M reductase alpha subunit
And I want to remove all besides the first section:
>CP008746
>CP009530
I've been learning Python over the holidays, so I've written (Python3.7.6):
with open("abc.txt","r+") as data_file:
for line in data_file:
data=line.split()
del data[1:]
print(data)
This gives me the output I want, but I'm not sure how to output the results straight to a new file - I've tried print(data, file=data_file)
, but it just outputs a few of my lines instead of all. I've gotten around this by copy-pasting manually to a new file but there must be a way to automatically output everything, right?
Any help is much appreciated and I apologise if this has already been answered...!
Thank you!