1 #!/home/huxuesong/gentoo/usr/bin/perl -w
6 use Time
::HiRes qw
( gettimeofday tv_interval
);
11 our($opt_i, $opt_o, $opt_v, $opt_b, $opt_m);
13 #our $desc='SoapSort library PCR PE Duplication Remover & Merger (Atom Edition)';
15 \t-i Input file, in format: /^ChrID\\tPos\\t.*\\n\$/
16 \t-m merge list, in format: /^ChrID\\tscaffoldID\\tChrStart\\tChrStop\\n\$/
18 \t-v show verbose info to STDOUT
19 \t-b No pause for batch runs
24 warn "[x]Must specify -i !\n" unless $opt_i;
25 warn "[x]Must specify -m !\n" unless $opt_m;
26 warn "[x]Must specify -o !\n" unless $opt_o;
27 exit 1 unless $opt_i and $opt_o and $opt_m;
29 print STDERR
"From [$opt_i] with [$opt_m] to [$opt_o]\n";
30 unless ($opt_b) {print STDERR
'press [Enter] to continue...'; <>;}
32 my $start_time = [gettimeofday
];
34 unless (-s
$opt_i) {die "[x]Soaplist [$opt_i] is nothing !\n";}
41 my $dbh = DBI
->connect('dbi:SQLite:dbname=:memory:','','',\
%attr) or die $DBI::errstr
;
43 # ChrNew2 scaffold90 1 45293
45 CREATE TABLE IF NOT EXISTS merge
51 # The rowid value can be accessed using one of the special names "ROWID", "OID", or "_ROWID_".
52 for (split /;/,$sql) {
54 $dbh->do($_) or die $dbh->errstr;
60 CREATE INDEX IF NOT EXISTS se ON merge
(start
,end
);
61 CREATE INDEX IF NOT EXISTS c ON merge
(chrid
);
63 for (split /;/,$sql) {
65 $dbh->do($_) or warn $dbh->errstr;
70 my $sthi = $dbh->prepare( 'INSERT INTO merge ( chrid,scaffold,start,end ) VALUES ( ?,?,?,? )' );
71 my $stho = $dbh->prepare( 'SELECT DISTINCT scaffold,start,end FROM merge WHERE chrid=? AND ? BETWEEN start AND end' );
74 open SAMPLE
,'-|',"gzip -dc $opt_m" or die "Error opening $opt_m: $!\n";
77 my ($chrid,$scaffold,$start,$end)=split /\t/;
78 $sthi->execute($chrid,$scaffold,$start,$end);
83 open IN
,'<',$opt_i or die "Error opening $opt_i: $!\n";
84 open OUT
,'>',$opt_o or die "Error opening $opt_o: $!\n";
85 my ($chrid,$pos,$pos2,$scaffold,$scaffold2,$start,$end,$qres,$newpos,$newpos2,@last);
87 # ChrNew1 121900 T T T T W W T T T T T T T T T T W W T T T T T T T - T T T T T T T T T T
88 ($chrid,$pos,$pos2,@last)=split /\t/;
89 $stho->execute($chrid,$pos);
90 $qres = $stho->fetchall_arrayref;
92 warn "No info. for $chrid:$pos, skipped.\n";
94 } elsif ($#$qres != 0) { warn "More than 1 hit, using first.\n" }
95 ($scaffold,$start,$end)=@
{$$qres[0]};
96 $newpos=1+$pos-$start;
98 $stho->execute($chrid,$pos2);
99 $qres = $stho->fetchall_arrayref;
101 warn "No info. for $chrid:$pos, skipped.\n";
103 } elsif ($#$qres != 0) { warn "More than 1 hit, using first.\n" }
104 ($scaffold2,$start,$end)=@
{$$qres[0]};
105 $newpos2=1+$pos2-$start;
106 if ($scaffold ne $scaffold2) {
107 print OUT
"[$scaffold,$scaffold2] ";
108 warn "Diff scaffold happens. ";
110 print OUT
join("\t",$scaffold,$newpos,$newpos2,@last);
115 my $stop_time = [gettimeofday
];
117 print STDERR
"\nTime Elapsed:\t",tv_interval
( $start_time, $stop_time )," second(s).\n";