#!usr/bin/perl

#Need probes >title with genotype
#sequence with [snp]

open (FASTA, $ARGV[0]) or die "Cannot open fasta probes";
open (OUT, ">out.txt");

@infile = <FASTA>;
$infile = join "", @infile;
@infile = split ">", $infile;

close FASTA;

	foreach $line (@infile){
		$line =~ s/\s+$//;
		@split_line  = split "\n", $line;

		foreach $part (@split_line){
			if ($part =~ /\[.\/.\]/){
				@split_snp = split /\[|\]/, $part;
				#print $split_snp[0], "\t", $split_snp[1], "\t", $split_snp[2], "\t", $split_snp[3], "\n";

				@split_left = split "", $split_snp[0];
				@split_right = split "", $split_snp[2];

				foreach $base (@split_left){
					unshift @left, $base;
				}
				foreach $base (@left){
                                        $count++;
					if ($count <= 35){
						unshift @back, $base;
					}
                                }
				print OUT @back;
				$count = 0;

				print OUT "[", $split_snp[1], "]";

				foreach $base (@split_right){
                                        $count++;
					if ($count <= 35){
                                                print OUT $base;
                                        }
                                }
				$count = 0;

			}
		}
		print OUT "\t";
		@split_sq = split /\{|\}/, $split_line[0];

		print OUT $split_sq[1], "\t", $split_line[0], "\n";
		undef (@left);
		undef (@back);
	}

close OUT;

open (OUT, "out.txt");

while ($line = <OUT>){
	$line =~ s/\s+$//;

	@split = split "\t", $line;

	@split_seq = split "", $split[0];
	@split_gen = split "", $split[1];
	
	if (scalar @split_seq == 75){
		if (scalar @split_gen > 2){
			print $line, "\n";
			$count++;
		}
	}
}

close OUT;

print $count, "\n";

system "rm out.txt";
