Can someone please write this in python3? use strict; use warnings; use Bio::Seq
ID: 3829890 • Letter: C
Question
Can someone please write this in python3?
use strict;
use warnings;
use Bio::Seq;
use Bio::SeqIO;
# open the gff file
open (MYFILE,'/home/jorvis1/Saccharomyces_cerevisiae_S288C.annotation.gff');
# declare the variables used in the program
my @f;
my $type;
my $g;
my $l;
my $output;
# Read the file, and store it in scalar variable l
while (my $l = <MYFILE>)
{
chomp $l;
# Create an array @f to spilt the file in columns
@f = split (" ", $l);
#Store the value of f at 2 which would be the gene column in scalar variable ty$
$type = $f[3];
$g = $f[9]; # Store the value of f at 9 which would be the notes column i$
if ($type eq 'gene') #Create a conditional loop for the keyword gene in$
{
if ($g eq 'YAR003W') # Additional secondary loop to look for ge$
{
my $start = $f[4]; #if loop condition true store start, end & strand in scalar
my $end = $f[5];
my $strand = $f[7];
my $fasta = $l->seq($strand, $start, $end)
#store the specific coordinates for the fasta in $fasta
# Store the Fasta in $output
my $output = <STDOUT>->(
-seq => $fasta,);
#Display output, this should display the Fasta file f$
print $output;
}
}
}
close (MYFILE);
Explanation / Answer
The GFF file can be read in Python using BioPython library. For doing that, we need the file to be read or atleast the column names in the file so as to read and print the file contents.
Please provide the input file.
An example of BioPython is as below: (an example)
from Bio import SeqIO
from BCBio.SeqIO.GFFIO import GFFFeatureAdder
with open(seq_file) as seq_handle:
seq_dict = SeqIO.to_dict(SeqIO.parse(seq_handle, "fasta"))
feature_adder = GFFFeatureAdder(seq_dict)
cds_limit_info = dict(
gff_types = [('Coding_transcript', 'gene'),
('Coding_transcript', 'mRNA'),
('Coding_transcript', 'CDS')],
gff_id = ['I']
)
with open(gff_file) as gff_handle:
feature_adder.add_features(gff_handle, cds_limit_info)
final_rec = feature_adder.base['I']