Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python edit distance

I am a molecular biologist using Biopython to analyze mutations in genes and my problem is this:

I have a file containing many different sequences (millions), most of which are duplicates. I need to find the duplicates and discard them, keeping one copy of each unique sequence. I was planning on using the module editdist to calculate the edit distance between them all to determine which ones the duplicates are, but editdist can only work with 2 strings, not files.

Anyone know how I can use that module with files instead of strings?

like image 900
user1513202 Avatar asked Sep 24 '26 16:09

user1513202


1 Answers

Assuming your file consists solely of sequences arranged one sequence per line, I would suggest the following:

seq_file = open(#your file)

sequences = [seq for seq in seq_file]

uniques = list(set(sequences))

Assuming you have the memory for it. How many millions?

ETA:

Was reading the comments above (but don't have comment privs) - assuming the sequence IDs are the same for any duplicates, this will work. If duplicate sequences can different sequence IDs, then would to know which comes first and what is between them in the file.

like image 178
selllikesybok Avatar answered Sep 26 '26 06:09

selllikesybok



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!