#!/usr/bin/perl
$infile1 = 'file.txt';
$infile2 = 'cpg2.txt';
$outfile7 = 'out10.txt';
open IN10, "< $infile1" or die "Can't open $infile1 : $!";
open IN11, "< $infile2" or die "Can't open $infile2 : $!";
open OUT7, "> $outfile7" or die "Can't open $outfile7 : $!";
my %chromes;
my %chromes1;
while (<IN10>) {
chomp;
my ($arrayid,$ncrnaid1,$ncrnaid2,$ncrnaid3,$ncrnaid4,$ncrnaid5,$ncrnaid6,$ncrnaid7,$ncrnaid8,$ncrnaid9, $ncrnaid10,$ncrnaid11,$ncrnaid12, $chrom,$start,$end,$cstrand,$en,$esi,$est) = split /\t/;
my $rec = {arrayid => $arrayid,
ncrnaid1 => $ncrnaid1,
ncrnaid2 => $ncrnaid2,
ncrnaid3 => $ncrnaid3,
ncrnaid4 => $ncrnaid4,
ncrnaid5 => $ncrnaid5,
ncrnaid6 => $ncrnaid6,
ncrnaid7 => $ncrnaid7,
ncrnaid8 => $ncrnaid8,
ncrnaid9 => $ncrnaid9,
ncrnaid10 => $ncrnaid10,
ncrnaid11 => $ncrnaid11,
ncrnaid12 => $ncrnaid12,
start => $start,
end => $end,
cstrand => $cstrand,
en => $en,
esi => $esi,
est => $est};
push @{$chromes{$chrom}}, $rec;
}
my @arrayids;
sub input {
my @attrs =qw(chrom start);
while (<IN10>) {
chomp;
my %rec;
@rec{@attrs} = split /\t/;
push @arrayids,\%rec;
}
}
foreach my $chrom (sort keys %chromes){
my $count = scalar @{$chromes{$chrom}};
print OUT7 "$chrom\t$count\t\n\n";
print OUT7 map {"\t\t$_->{start}\t\n"} @{$chromes{$chrom}};
}
#########################################
while (<IN11>) {
chomp;
my ($cchrom,$middle) = split /\t/;
my $cpg = {middle => $middle};
push @{$chromes1{$cchrom}}, $cpg;
}
my @cpgids;
sub input {
my @cpgs =qw(cchrom middle);
while (<IN11>) {
chomp;
my %cpg;
@cpg{@cpgs} = split /\t/;
push @cpgids,\%cpg;
}
}
foreach my $cchrom (sort keys %chromes1){
my $count = scalar @{$chromes1{$cchrom}};
print OUT7 "$cchrom\t$count\t\n\n";
print OUT7 map {"\t\t$_->{middle}\t\n"} @{$chromes1{$cchrom}};
}
#my @set = $start; #callin $start from $start (file1)
#my @vals = $middle; #calling $middle from $middle (file2)
#my @vals_sorted = sort {$a <=> $b} @vals;
#foreach my $n (@set) {
# print "Closest to $n = ", shift @vals_sorted, "\n";
}
close IN10;
close IN11;
close OUT7;
Last edited by nogu0001; 02-24-2009 at 02:23 AM..