-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsingled2paired.pl
77 lines (68 loc) · 1.75 KB
/
singled2paired.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env perl
use strict;
use warnings;
use autodie;
use IO::Zlib;
use Getopt::Long;
Getopt::Long::GetOptions(
'help|h' => sub { Getopt::Long::HelpMessage(0) },
'in|i=s' => \my $in_fq,
'length|l=s' => \my $length,
'R1|1=s' => \my $out_fq1,
'R2|2=s' => \my $out_fq2,
) or Getopt::Long::HelpMessage(1);
sub SPLIT_STR {
my ( $STR, $LENGTH ) = @_;
my $STR_LENGTH = length $STR;
my @READS;
for ( my $SEED = 0 ; $SEED + $LENGTH <= $STR_LENGTH ; $SEED += 1 ) {
push @READS, substr( $STR, $SEED, $LENGTH );
}
return ( $READS[0], $READS[-1] );
}
sub SEQ_REV_COMP {
my $SEQ = reverse shift;
$SEQ =~ tr/Uu/Tt/;
return ( $SEQ =~ tr/AGCTagct/TCGAtcga/r );
}
my $in_fh;
if ( $in_fq =~ /.gz$/ ) {
$in_fh = IO::Zlib->new( $in_fq, "rb" );
}
else {
open( $in_fh, "<", $in_fq );
}
my $out_fh1;
if ( $out_fq1 =~ /.gz$/ ) {
$out_fh1 = IO::Zlib->new( $out_fq1, "wb9" );
}
else {
open( $out_fh1, ">", $out_fq1 );
}
my $out_fh2;
if ( $out_fq2 =~ /.gz$/ ) {
$out_fh2 = IO::Zlib->new( $out_fq2, "wb9" );
}
else {
open( $out_fh2, ">", $out_fq2 );
}
while (<$in_fh>) {
my $qname = $_;
chomp($qname);
my @qntemp = split( /\s+/, $qname );
my $sequence = <$in_fh>;
chomp($sequence);
my $t = <$in_fh>;
chomp($t);
my $quality = <$in_fh>;
chomp($quality);
if ( $length <= length($sequence) ) {
my ( $seq1, $seq2 ) = SPLIT_STR( $sequence, $length );
my ( $qua1, $qua2 ) = SPLIT_STR( $quality, $length );
$seq2 = SEQ_REV_COMP($seq2);
$qua2 = reverse($qua2);
print $out_fh1 "$qntemp[0] 1 @qntemp[1..$#qntemp]\n$seq1\n$t\n$qua1\n";
print $out_fh2 "$qntemp[0] 2 @qntemp[1..$#qntemp]\n$seq2\n$t\n$qua2\n";
}
}
__END__