#!/usr/bin/perl $CHR_NUM = $ARGV[0]; $file_location = "/home/ALL.chr$CHR_NUM.phase1_release_v3.20101123.snps_indels_svs.genotypes.vcf.gz"; for $x (1..75) { open (FH, "/home/raj/HAPLOTYPES_JAN_2015/PROG_1_Approach_2/C22-$x")|| die "Cannot"; while (){ chomp $_; push (@{$x} , $_);#this loop opens the 75 files with identifier and stores in arrays } } open(IN, "zcat $file_location |") || die "can't open CHROMOSOME $CHR_NUM input file 1000G!"; $g=1; $z=0; while () { $choice = 1; $x=$g; $y=$z; chomp $_; $counter ++; LABEL: if ($choice == 1){ if ($counter > 29) { # print "$_\n"; @currentline = split (/\t/, $_); #print "$currentline[1]\n"; for $r($x..75) { # $r will be used as the names for files 1-75 for $t ($y..$#$r) { if ($currentline[1] == $$r[$t]) { open ($r,">>$r"); print $r "$_\n"; $z = $t++; $choice = 0; goto LABEL; } } } } } if ($z >= $#$x){ $g = $x++; $z = $y = 0; close $r; if ($x==76){# last; } } }