#!/usr/bin/perl use Bio::SeqIO; use Bio::SeqUtils; #================================= #Script to trim trailing Xs leftover from incomplete codons #at the end of a DNA sequence. #NB: Will only translate in 1st frame and only trim X's from end #briandotoakleyatarsdotusdadotgov #k.purdy at warwick.ac dot uk #================================= #---define input file---- $usage = "\n\nUsage: $0 filename\n\n"; my $input_file = $ARGV[0] or die $usage; my $seqin = Bio::SeqIO->new(-file => $input_file, -format => 'fasta' ); $output_file='seqs_trimmed_of_Xs.fas'; $out = Bio::SeqIO->new(-file => ">$output_file", -format => 'fasta'); print "\nScript is running...\n"; while (my $seqobj = $seqin->next_seq()) { $nuc_length = $seqobj->length; $full_codon_nuc_length = $nuc_length/3; if ($full_codon_nuc_length =~ /\d+\.33/) { $chop=1; } elsif ($full_codon_nuc_length =~ /\d+\.66/) { $chop=2; } elsif ($full_codon_nuc_length =~ /\d+/) { $chop=0; } print "\n",$seqobj->id," Trimming $chop"; $trunc_seqobj=$seqobj->trunc(1,($nuc_length-$chop)); $out->write_seq($trunc_seqobj); } print "\n\nTrimmed sequences written to: ", $output_file,"\n";