Last active
December 18, 2015 20:22
-
-
Save wckdouglas/6225adb8e03400d133da to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #/usr/bin/env python | |
| from Bio import SeqIO | |
| import sys | |
| def guessFileType(filename): | |
| if filename.endswith('fasta') or filename.endswith('fa'): | |
| fileType = 'fasta' | |
| elif filename.endswith('fastq') or filename.endswith('fq'): | |
| fileType = 'fastq' | |
| else: | |
| fileType = 'cannot regconize file type [fasta|fastq]' | |
| return fileType | |
| def main(filename): | |
| fileType = guessFileType(filename) | |
| with open(filename,'ru') as seqfile: | |
| for record in SeqIO.parse(seqfile,fileType): | |
| startpos = record.seq.find('ATG') | |
| orf = record.seq[startpos:] | |
| if len(set(record.seq) - {'A','T','C','G','N'}) != 0: | |
| sys.exit('Not DNA sequence') | |
| if len(orf) > 0: | |
| print '>%s\n%s' %(record.id, orf.translate()) | |
| return 0 | |
| if __name__ == '__main__': | |
| if len(sys.argv) != 2: | |
| sys.exit('usage: python %s <filename [fasta|fastq]>' %sys.argv[0]) | |
| main( sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment