#!/usr/bin/perl

use strict;
use warnings;

#Use the POSA perl objects
use POSA::Read;
use POSA::Contig;

#What is the file containing the names of all abi-files?
my $file_of_filenames = shift;

#Foreach read: create a POSA::Read object and add it to a @reads array.
my @reads = ();
open FOFN, $file_of_filenames;
foreach my $abi_file ( <FOFN> ) {
  chomp $abi_file;
  my $read = POSA::Read->importFromAbi(name => $abi_file, file => $abi_file);

  push @reads, $read;
}
close FOFN;

#Create a list of POSA::Contig objects based on all POSA::Read objects
my @contigs = POSA::Contig->phrap(reads => \@reads, gap_init_penalty => -6);

#Foreach contig: search for SNPs and produce some output
foreach my $ctg ( @contigs ) {
  #Run the command to annotate SNPs in this contig
  $ctg->searchSnps(rank => 6);

  #Print output
  print $ctg->asGenotypes, "\n";
  print $ctg->asSbe(length => 35), "\n";
  print $ctg->asAlignment, "\n";
  print $ctg->asMipe, "\n";
}
