#!/usr/bin/perl -w
use strict;
my$tline="";
my@tlist=();
my$tempi=0;
my$tempj=0;
my$tempk=0;
my$pline="";
my@plist=();
my$tid=0;
my%tidx=();
@ARGV==3 or die""."Error in syntax!\n"."   ./filterCopyNum.pl <input.dat> <output.dat> <cutoff_copynum>\n";
my$egFileDat=$ARGV[0];
my$egFileOut=$ARGV[1];
my$egCutOff=$ARGV[2];
my$egHeadLine="";
my@egLine=();
my@egCluster=();
my$egNum=0;
my%egCluster2Num=();
print"Loading data ... ";
open(efIn,"$egFileDat")or die"Error when loading!\n";
while(<efIn>){$tline=$_;
$tline=~s/[\r\n]//g;
@tlist=split(/\t/,$tline);
if($tline=~/^#/){$egHeadLine=$tline;}elsif(@tlist>=23){$tid=$egCluster2Num{"$tlist[2]"};
if(defined$tid){$tid++;}else{$tid=1;}$egCluster2Num{"$tlist[2]"}=$tid;
$egLine[$egNum]=$tline;
$egCluster[$egNum]=$tlist[2];
$egNum++;}}close(efIn);
print" [done] [ClusterNum:".(scalar keys%egCluster2Num)."]\n";
print"Saving data ... ";
$tempj=0;
open(efOut,">$egFileOut")or die"Erro rwhen ssaving!\n";
print efOut"$egHeadLine\n";
for($tempi=0;$tempi<$egNum;$tempi++){$tid=$egCluster2Num{"$egCluster[$tempi]"};
if((defined$tid)and($tid>=$egCutOff)){print efOut "$egLine[$tempi]\n";
$tempj++;}}close(efOut);
print" [done] [Number:$tempj]\n";
