Mercurial > repos > cstrittmatter > test_galtrakr_eurl_vtec_wgs_pt_23
diff scripts/MultifastaFromBlast.pl @ 0:8be2feb96994
"planemo upload commit cb65588391944306ff3cb32a23e1c28f65122014"
author | cstrittmatter |
---|---|
date | Fri, 11 Mar 2022 15:50:35 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/MultifastaFromBlast.pl Fri Mar 11 15:50:35 2022 -0500 @@ -0,0 +1,44 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use English; + +# Parse arguments +my ($inputs, $output) = @ARGV; +# Run program +unlink $output; +my @infiles = split( /,/, $inputs ); +foreach(@infiles) { + transformFileContent($_, $output); +} + +# read input file and write multifasta with sequence (forward or reverse complement) +sub transformFileContent { + my ($infile, $outfile) = @_; + open my $if, '<', $infile or die "Cannot open : $infile!"; + open my $of, '>>', $outfile or die "Cannot open : $outfile!"; + my @lines = <$if>; + close $if; + foreach(@lines) { + my @elems = split( /\t/, $_ ); + print $of ">$elems[0]\n"; + chomp $elems[2]; + if ($elems[1] == 1) { + print $of "$elems[2]\n"; + } + else { + my $revcomp = reverseComplement($elems[2]); + print $of "$revcomp\n"; + } + } + close $of; + return 0; +} + +# calculate reverse complement +sub reverseComplement { + my ($DNA) = @_; + my $revcom = reverse $DNA; + $revcom =~ tr/ACGTacgt/TGCAtgca/; + return $revcom; +}