Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
"""
%prog some.fasta wanted-list.txt
"""
from Bio import SeqIO
import sys
wanted = [line.strip() for line in open(sys.argv[2])]
seqiter = SeqIO.parse(open(sys.argv[1]), 'fasta')
SeqIO.write((seq for seq in seqiter if seq.id in wanted), sys.stdout, "fasta")
@chahatupreti

This comment has been minimized.

Copy link

@chahatupreti chahatupreti commented Nov 9, 2014

hi,
where is the file being taken as input?
thanks

@johnbkirkpatrick

This comment has been minimized.

Copy link

@johnbkirkpatrick johnbkirkpatrick commented Apr 22, 2016

It takes two input files. The initial comment line addresses that question:
%prog some.fasta wanted-list.txt

For example when I ran this, I typed:
python gistfile1.py my_big_file.fasta just_the_names_I_need.txt

Also, I changed sys.stdout in line 9 to 'output.txt' so it would save to file rather than printing to screen.

@Createanaccountplease

This comment has been minimized.

Copy link

@Createanaccountplease Createanaccountplease commented Dec 7, 2017

I tried changing the sys.stout to an output file name with no luck instead receiving the error that the file name was undefined, is there any possible way to fix this?
Yet if I leave as sys.stdout I am not receiving an output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.