changeset 0:a55eb751d2d8 draft

Uploaded
author jasper
date Tue, 09 May 2017 13:09:07 -0400
parents
children 2513dbc3385d
files test-data/._demo_protein.fasta test-data/demo_nucs.fasta test-data/demo_protein.fasta translate.py translate.xml
diffstat 5 files changed, 81 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
Binary file test-data/._demo_protein.fasta has changed
--- /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
--- /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
+
--- /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()
--- /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 @@
+<tool id="dna_protein_transle" name="Translate DNA to protein" version="1.0">
+    <description>Translate nucleic acid to protein </description>
+    <requirements>
+        <requirement type="package" version="1.69">biopython</requirement>
+        <requirement type="python-module">Bio</requirement>
+    </requirements>
+    <command interpreter="python" >
+        translate.py -i $dna -o $output -r $read_frame
+    </command>
+    <inputs>
+        <param name="dna" type="data" format="fasta" label="DNA fasta file" help="DNA fasta file" />
+        <param name="read_frame" type="select" label="Choose a read frame">
+          <option value="1">1</option>
+          <option value="2">2</option>
+          <option value="3">3</option>
+          <option value="-1">-1</option>
+          <option value="-2">-2</option>
+          <option value="-3">-3</option>
+        </param>
+    </inputs>
+    <outputs>
+        <data name="output" type="data" format="fasta"/>
+    </outputs>
+    <tests>
+        <test>
+            <param name="dna" file="demo_nucs.fasta" />
+            <param name="read_frame" type="select" value="1" />
+            <output name="output" file="demo_protein.fasta" />
+        </test>
+    </tests>
+</tool>