# HG changeset patch # User jasper # Date 1494349747 14400 # Node ID a55eb751d2d8d4be2d1ab1d70d3992e890df336f Uploaded diff -r 000000000000 -r a55eb751d2d8 test-data/._demo_protein.fasta Binary file test-data/._demo_protein.fasta has changed diff -r 000000000000 -r a55eb751d2d8 test-data/demo_nucs.fasta --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/demo_nucs.fasta Tue May 09 13:09:07 2017 -0400 @@ -0,0 +1,6 @@ +>Alpha +GATGAGGAACGA +>Beta +GATGAGCGT +>Gamma +GATCGG diff -r 000000000000 -r a55eb751d2d8 test-data/demo_protein.fasta --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/demo_protein.fasta Tue May 09 13:09:07 2017 -0400 @@ -0,0 +1,9 @@ +>Alpha +DEER + +>Beta +DER + +>Gamma +DR + diff -r 000000000000 -r a55eb751d2d8 translate.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/translate.py Tue May 09 13:09:07 2017 -0400 @@ -0,0 +1,35 @@ +import sys +import warnings +import argparse +from Bio import SeqIO, SeqRecord, BiopythonWarning +from Bio.Seq import Seq +from Bio.Alphabet import IUPAC + + +warnings.simplefilter("ignore", BiopythonWarning) +parser = argparse.ArgumentParser(description="Translation") +parser.add_argument('-r', action='store', dest='read_frame', type=int) +parser.add_argument('-i', action='store', dest='input_file') +parser.add_argument('-o', action='store', dest='output_file') + +inputs = parser.parse_args() +with open(inputs.output_file, 'w') as f: + for seq_record in SeqIO.parse(inputs.input_file, 'fasta'): + seqid = seq_record.id + name=seq_record.name + description = seq_record.description + if inputs.read_frame > 0: + seq_record = seq_record[(inputs.read_frame - 1):] + elif inputs.read_frame == -1: + seq_record = seq_record.reverse_complement() + elif inputs.read_frame == -2: + seq_record = seq_record.reverse_complement() + seq_record = seq_record[2:] + elif inputs.read_frame == -3: + seq_record = seq_record.reverse_complement() + seq_record = seq_record[1:] + dna = Seq(str(seq_record.seq), IUPAC.ambiguous_dna) + protein = SeqRecord.SeqRecord(seq=dna.translate(), id=seqid, name=name, description=description) + SeqIO.write(protein, f, 'fasta') + f.write('\n') +f.close() diff -r 000000000000 -r a55eb751d2d8 translate.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/translate.xml Tue May 09 13:09:07 2017 -0400 @@ -0,0 +1,31 @@ + + Translate nucleic acid to protein + + biopython + Bio + + + translate.py -i $dna -o $output -r $read_frame + + + + + + + + + + + + + + + + + + + + + + +