#!/usr/bin/perl
#
# Name: chop.pl
# Purpose: to break input sequences longer than the Picky limit of
#          16,384 bp to multiple fragments in order to process them
#          with Picky.
# Usage: ./chop.pl long_sequence_input > chopped_sequence_output
# Created: 05/09/2005
# Copyright: (c) 2005 Hui-Hsien Chou <hhchou@iastate.edu>
# License: See LICENSE.pdf or visit <www.complex.iastate.edu>

use strict;
use warnings;

my $width = 70;
my $batch = int 16384/$width;
$batch *= $width;
my $name;
my $seq = "";

while (<>) {
  chomp;
  if (/^>/) {
    output($name, $seq) if length $seq;
    $seq = "";
    $name = $_;
  } else {
    $seq .= $_;
  }
}
output($name, $seq) if length $seq;

sub output {
  my ($name,$seq) = @_;

  for (my $i=0; $i<length($seq)-50; $i+=$batch) {
    print "$name\n"; # you can modify here to get different names
    for (my $j=0; $i+$j<length($seq) && $j<$batch; $j+=$width) {
      print substr($seq, $i+$j, $width), "\n";
    }
  }
}
