-
Notifications
You must be signed in to change notification settings - Fork 2
/
fqNameMapping.pl
executable file
·67 lines (59 loc) · 1.67 KB
/
fqNameMapping.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
#!/usr/bin/env perl
=hey
Author: Shijian Sky Zhang
E-mail: [email protected]
=cut
use 5.012;
use warnings;
use Getopt::Long;
use File::Basename;
my $prefix = 'R';
my $increment = 1;
my $mapBack;
sub usage{
my $scriptName = basename $0;
print <<HELP;
Usage: perl $scriptName INPUT.fq >OUTPUT.sam
If INPUT.fq isn't specified, input from STDIN
Option:
-p --prefix STR The prefix of mapped name[$prefix]
-i --increment INT The initial number of the increment[$increment]
-b --mapBack FILE File with columns of new and original names.
It can be the STDERR generated by $scriptName without -b.
New name in the INPUT file will be mapped back to original name.
-h --help Print this help information
HELP
exit(-1);
}
GetOptions(
'p|prefix=s' => \$prefix,
'i|increment=i' => \$increment,
'b|mapBack=s' => \$mapBack,
'h|help' => sub{usage()}
) || usage();
$ARGV[0] = '-' unless defined $ARGV[0];
open IN, "$ARGV[0]" or die "Can't open $ARGV[0]: $!";
my %mapBack;
if(defined $mapBack){
open MB, "$mapBack" or die "Can't open $mapBack: $!";
while(<MB>){
chomp;
my ($newName, $oriName) = split "\t";
$mapBack{"$newName"} = $oriName;
}
}
while(<IN>){
chomp;
my ($name) = /^@(.+)/;
my $seq = <IN>;
my $plus = <IN>;
my $qual = <IN>;
if(defined $mapBack){
$name = $mapBack{"$name"};
}else{
say STDERR join "\t", ("$prefix$increment", $name);
$name = "$prefix$increment";
$increment++;
}
print '@'. "$name\n$seq$plus$qual";
}