view scripts/MultifastaFromBlast.pl @ 6:20ff3dca457f draft default tip

planemo upload commit 6857c749c21f580c828aba3543e294b69d32b662
author iss
date Mon, 23 Oct 2023 11:45:36 +0000
parents c6bab5103a14
children
line wrap: on
line source

#!/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;
}