-
Notifications
You must be signed in to change notification settings - Fork 0
/
host_vir_pair.pl
136 lines (120 loc) · 3.74 KB
/
host_vir_pair.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/perl
=head1 Name
host_vir_pair.pl
version:1
Date, Sep.04.2012
Contact: [email protected]
=head1 Description
Find reads pair that span virus integration sites in host genome
=head1 Usage
perl host_vir_pair.pl virSoapSe hostSoapPe hostSoapSe pairSpan unmapPair
Arguments explained
virSoapSe: file directory for virus SOAP single-end alignment output
hostSoapPe: file dir for host SOAP paired-end output
hostSoapSe: file dir for host SOAP single-end output
pairSpan: output containing paired reads than align to both host and virus genome
unmapPair: output containing potential PE with one mate map to virus genome but the other unmap to host genome. NA in current version
=cut
use strict;
use warnings;
use Getopt::Long;
my ($virSoapFile,$hostSoapPe, $hostSoapSe, $pairSpan, $outUnmap) = @ARGV;
GetOptions(
"virSoapSe" => \$virSoapFile,
"hostSoapPe" => \$hostSoapPe,
"hostSoapSe" => \$hostSoapSe,
"pairSpan" => \$pairSpan,
"unmapPair" => \$outUnmap
);
die `pod2text $0` unless $virSoapFile && $hostSoapPe && $hostSoapSe && $pairSpan && $outUnmap;
my (%id);
my ($fhHBV, $fhHostPe, $fhHostSe, $fhUnmap);
#--------------------- open virus soap file-----------------
if ($virSoapFile =~ /\.gz$/){
open $fhHBV, "gzip -dc $virSoapFile|" or die $!;
}else{
open $fhHBV, $virSoapFile or die $!;
}
#---------------------read virus soap file--------------
while (<$fhHBV>){
chomp;
next if /^\s+$/;
my @tmp = split;
my ($id, $strand) = $tmp[0] =~ /^(\S+)([12])$/;
if ($id{$id}){
delete $id{$id};
}else{
$id{$id} = $_;
}
}
close $fhHBV;
#--------------------read hostSoapPe, get read ids and check the %id for span--------
if ($hostSoapPe =~ /\.gz$/){
open $fhHostPe, "gzip -dc $hostSoapPe|" or die $!;
}else{
open $fhHostPe, $hostSoapPe or die $!;
}
my $fhout;
open $fhout, ">$pairSpan" or die $!;
while (<$fhHostPe>){
chomp;
next if /^\s+$/;
my @tmp = split;
my ($id, $strand) = $tmp[0] =~ /^(\S+)([12])$/;
next unless $id && $strand;
if($id{$id}){
my ($hbvReadStr) = $id{$id} =~ /^\S+?([12])\t/;
print $fhout "$_\t$id{$id}\n" if ($strand!=$hbvReadStr);
}
}
close $fhHostPe;
close $fhout;
#--------------------read hostSoapSe, get read ids and check the %id for span---------
if ($hostSoapSe =~ /\.gz$/){
open $fhHostSe, "gzip -dc $hostSoapSe|" or die $!;
}else{
open $fhHostSe, $hostSoapSe or die $!;
}
open $fhout, ">>$pairSpan" or die $!;
while (<$fhHostSe>){
chomp;
next if /^\s+$/;
my @tmp = split;
my ($id, $strand) = $tmp[0] =~ /^(\S+)([12])$/;
next unless $id && $strand;
print $fhout "$_\t$id{$id}\n" if ($id{$id} && $strand ne $id{$id}); # if hostMapSe read pair with virusmap, print them. first column hostMap, second column virusmap
delete $id{$id};
}
close $fhHostSe;
close $fhout;
#---------------------open host soap unmap file-----------
#my $tmp = `file $hostUnmapFile`;
#if ($tmp =~ /gzip/){
# open $fhUnmap, "gzip -dc $hostUnmapFile|" or die $!;
#}else{
# open $fhUnmap, $hostUnmapFile or die $!;
#}
#open $fhout, ">$outUnmap.virus" or die $!;
#open my $fhout2, ">$outUnmap.host" or die $!;
#
#if (keys %id){
# while (my $line = <$fhUnmap>){ # fhUnmap reads hostUnmap
# chomp $line;
# my $seq = <$fhUnmap>;
# chomp $seq;
# my ($id, $strand) = $line =~ /^>(\S+)([12])$/;
# die unless $id && $strand;
#
# next unless $id{$id}; # hash id keys are readID in HBV map file ; if the read from hostUnmap doesn't pair with HBVmap, next
## if the current read pairs with other reads in hostUnmap, do the remaining
# my @tmp = split /\t/, $id{$id}; # split HBVmap soap line
# next if $tmp[0] eq "$id$strand";
#
# print $fhout ">$tmp[0]\n$tmp[1]\n"; # HBVmap
# print $fhout2 ">$id$strand\n$seq\n" ;# hostUnMap these two reads pair
#
# delete $id{$id};
# }
#}
#close $fhUnmap;
#close $fhout;