Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fasta quality file creation and fasta to phylip conversion

  • Loading branch information...
commit c3162a67412a1a92207a98577851db1ac3d8a097 1 parent c093205
Joseph Hughes authored
Showing with 124 additions and 0 deletions.
  1. +63 −0 Fasta2Phylip.pl
  2. +13 −0 README
  3. +48 −0 fastaQual2fastq.pl
View
63 Fasta2Phylip.pl
@@ -0,0 +1,63 @@
+#!/usr/bin/perl -w
+
+#obtained from Yu-Wei's Bioinformatics playground
+#http://yuweibioinfo.blogspot.com/2009/01/fasta-to-phylip-converter.html
+use strict;
+
+MFAtoPHYLIP($ARGV[0]);
+
+sub MFAtoPHYLIP
+{
+ my $inline;
+ my $outfile = "$_[0]\.phy";
+ my $count = 0;
+ my $len;
+ my $substate = 0;
+ my @subheader;
+ my @subcontent;
+ my $m;
+ my $n;
+
+ open (FILE, "<$_[0]");
+ while (defined($inline = <FILE>))
+ {
+ chomp($inline);
+ if ($inline =~ /^>([A-Za-z0-9.\-_:]+)/)
+ {
+ $subheader[$count] = $1;
+ $subcontent[$count] = "";
+ $count++;
+ }
+ else
+ {
+ $subcontent[$count - 1] = $subcontent[$count - 1] . " $inline";
+ }
+ }
+ close (FILE);
+
+ # Calculate the content length
+ $n = length($subcontent[0]);
+ $len = $n;
+ for ($m = 0; $m < $n; $m++)
+ {
+ if (substr($subcontent[0], $m, 1) eq " ")
+ {
+ $len--;
+ }
+ }
+
+ open (FILE, ">$outfile");
+ print FILE " $count $len\n";
+ for ($m = 0; $m < $count; $m++)
+ {
+ $len = 10 - length($subheader[$m]);
+ print FILE "$subheader[$m]";
+ for ($n = 0; $n < $len; $n++)
+ {
+ print FILE " ";
+ }
+ print FILE " $subcontent[$m]\n";
+ }
+ close (FILE);
+}
+
View
13 README
@@ -2,6 +2,7 @@ Consensus.pl by Joseph Hughes, University of Glasgow
Consensus.pl is a perl script which creates consensus sequences from a fasta alignement.
This script uses use Bioperl modules.
+
Usage: Consensus.pl <list of arguments>
-in <txt> - the input alignment in fasta format
-out <txt> - the directory path for the output consensus in fasta format
@@ -15,3 +16,15 @@ perl ../../Script/Consensus.pl -in alignment.fasta -out ../Consensus/consensus.f
It is best to run this from within the directory where you have your alignment so that the
identifier of the consensus sequence in the output does not have a path direcotry name.
+======================
+fastaQual2fastq.pl
+A perl script to convert FASTA + QUAL files to FASTQ
+
+Usage: fastaQual2fastq.pl path/to/input/file
+The input file must have the extension .fasta or .fna and the associated quality file
+must have the same name with extension .qual
+=====================
+Fasta2Phylip.pl
+A perl script to convert a fasta file to phylip format for running PHYML or RaxML for example.
+
+Usage: Fasta2Phylip.pl path/to/input/fastafile
View
48 fastaQual2fastq.pl
@@ -0,0 +1,48 @@
+#!/usr/bin/perl
+# a perl script to convert FASTA + QUAL files to FASTQ
+
+use warnings;
+use strict;
+use File::Basename;
+
+my $inFasta = $ARGV[0];
+my $baseName = basename($inFasta, qw/.fasta .fna/);
+my $inQual = $baseName . ".qual";
+my $outFastq = $baseName . ".fastq";
+
+my %seqs;
+
+$/ = ">";
+
+open (FASTA, "<$inFasta");
+my $junk = (<FASTA>);
+
+while (my $frecord = <FASTA>) {
+ chomp $frecord;
+ my ($fdef, @seqLines) = split /\n/, $frecord;
+ my $seq = join '', @seqLines;
+ $seqs{$fdef} = $seq;
+}
+
+close FASTA;
+
+open (QUAL, "<$inQual");
+$junk = <QUAL>;
+open (FASTQ, ">$outFastq");
+
+while (my $qrecord = <QUAL>) {
+ chomp $qrecord;
+ my ($qdef, @qualLines) = split /\n/, $qrecord;
+ my $qualString = join ' ', @qualLines;
+ my @quals = split / /, $qualString;
+ print FASTQ "@","$qdef\n";
+ print FASTQ "$seqs{$qdef}\n";
+ print FASTQ "+\n";
+ foreach my $qual (@quals) {
+ print FASTQ chr($qual + 33);
+ }
+ print FASTQ "\n";
+}
+
+close QUAL;
+close FASTQ;
Please sign in to comment.
Something went wrong with that request. Please try again.