Created
March 31, 2014 19:14
-
-
Save cathalgarvey/9899930 to your computer and use it in GitHub Desktop.
Simplified method of searching for forward/reverse-complement sequence in a multi-sequence file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from Bio import SeqIO | |
from Bio.Seq import Seq | |
filename = sys.argv[1] | |
usersequence = Seq(sys.argv[2]) | |
usersequence = usersequence.upper() | |
user_reverse = usersequence.reverse_complement() | |
records = SeqIO.parse(filename, "fasta") | |
matches = [] | |
rev_matches = [] | |
for record in records: | |
rec_sequence = record.seq.upper() | |
if usersequence in rec_sequence: | |
matches.append(record) | |
if user_reverse in rec_sequence: | |
rev_matches.append(record) | |
print("Forward matches:") | |
for match in matches: | |
print(match) | |
print('===========================') | |
print("Reverse Complement Matches:") | |
for match in rev_matches: | |
print(match) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment