
#interleave two separate files of paired reads



sub toFasta{
	
	open F1, "<".$R1;
	open OutF, ">".$R1.".fasta";
	@arr1=<F1>;
	my $size=@arr1;
	my $index=1;
	for ($count=0;$count<$size;$count=$count+4){
		print OutF ">unpaired".$index."\n".$arr1[$count+1];
		$index=$index+1;
	}
    close(F1);
    close(OutF);
	
	
}

sub interleaveFastqtoFasta{
	
	open F1, "<".$R1;
	open F2, "<".$R2;
	open OutF, ">".$R1."_".$R2.".fasta";
	@arr1=<F1>;
	@arr2=<F2>;
	my $size=@arr1;
	my $index=1;
	for ($count=0;$count<$size;$count=$count+4){
		print OutF ">read".$index."_left\n".$arr1[$count+1];
		print OutF ">read".$index."_right\n".$arr2[$count+1];
		$index=$index+1;
	}
    close(F1);
    close(F2);
    close(OutF);
	
	
}
sub interleave{
	open F1, "<".$R1;
	open F2, "<".$R2;
	open OutF, ">".$R1."_".$R2.".fastq";
	@arr1=<F1>;
	@arr2=<F2>;
	my $size=@arr1;
	for ($count=0;$count<$size;$count=$count+4){
		print OutF $arr1[$count].$arr1[$count+1].$arr1[$count+2].$arr1[$count_3];
		print OutF $arr2[$count].$arr2[$count+1].$arr2[$count+2].$arr2[$count_3];
	}
    close(F1);
    close(F2);
    close(OutF);
	
}

our $R1=shift;
#our $R2=shift;
toFasta();
#&interleaveFastqtoFasta();
#&interleave();