forked from cjieming/jmtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalleledb_bedbowtie2fastq
executable file
·98 lines (69 loc) · 1.6 KB
/
alleledb_bedbowtie2fastq
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/perl -w
use warnings;
use strict;
use File::Basename;
use Getopt::Long;
use Pod::Usage;
=head1 NAME
bowtie2fastq
=head1 SYNOPSIS
bedbowtie2fastq <bowtie>
Convert bed format that contains bowtie info (output of bowtie2bed) to fastq file
INPUT (bowtie output)
col1: chr
col2: start(0based)
col3: end(1based)
col4: ID#*o*#sequence#*o*#strand#*o*#score
but it doesnt require the first 3 columns; it requires only the 4th.
OUTPUT
fastq
Example:
bedbowtie2fastq file.bed | gzip -c > file.fastq.gz
=head1 DESCRIPTION
=cut
#option variables
my $help;
#initialize options
Getopt::Long::Configure ('bundling');
if(!GetOptions ('h'=>\$help) || scalar(@ARGV)!=1)
{
if ($help)
{
pod2usage(-verbose => 2);
}
else
{
pod2usage(1);
}
}
## input file
my $fn = shift;
## variables
my $fh;
my %reads2seq;
my %reads2strand;
my %reads2score;
## read in file
open($fh, "<$fn") || die "cannot open the file $fn!";
while (my $l = <$fh>) {
chomp($l);
my @t = split(/\t/, $l);
#my $chr = $t[0];
#my $sta = $t[1];
#my $end = $t[2];
my @u = split(/\#\*o\*\#/, $t[3]);
my $id = $u[0];
my $seq = $u[1];
my $strand=$u[2];
my $score = $u[3];
$reads2seq{$id} = $seq;
$reads2score{$id} = $score;
}
### print
for my $ID (sort keys %reads2seq)
{
print "\@$ID\n$reads2seq{$ID}\n+\n$reads2score{$ID}\n";
}
###########################################################################################
## subroutines
###########################################################################################