Member Avatar for Member #680522

Hi,
i need a help to do program.i need to read multiple files and need to print out result in to new file.I had stored my datas in mycomputer/programs(G:)/CNV/(inside this i have 4 folder and each folder consits of number of datas...) plz give me perl script to do this

Dani AI

Generated

Building on 's directory-walk suggestion, here is a compact, practical workflow to compare two microarray CNV files (find matching genomic intervals) and write the matches to a new folder. This expands the thread discussion with steps, pitfalls, and a simple Perl pattern to apply immediately.

Start with a clear workflow:

  • Collect the pair(s) of files to compare using a directory walker (File::Find or File::Find::Rule) or Path::Tiny for simpler path handling.
  • Normalize each record: strip whitespace, normalize chromosome names (drop or add the "chr" prefix consistently), coerce start/end to integers, and ensure start <= end.
  • Decide match criteria: exact start+end equality versus any interval overlap. Exact matches are simplest and fastest; overlaps require interval queries.
  • Stream-processing is important for many files: index one file in memory and stream the other, or use an interval tree or a small local DB if memory is tight.

Minimal Perl pattern for exact start/end matches (conceptual):

# index file A
my %index;
while (<$fhA>) {
  chomp;
  next if /^\s*#/;
  my @f = split /\t/;
  my ($chr,$s,$e) = @f[1,2,3];   # adapt columns to your file layout
  $chr =~ s/^chr//i;
  $index{"$chr:$s:$e"} = join("\t", @f);
}

# compare file B
while (<$fhB>) {
  chomp;
  my @f = split /\t/;
  my ($chr,$s,$e) = @f[1,2,3];
  $chr =~ s/^chr//i;
  if (exists $index{"$chr:$s:$e"}) {
    print $out join("\t", $index{"$chr:$s:$e"}, join("\t", @f)), "\n";
  }
}

Notes, cautions and options:

  • For overlap queries use an interval structure such as Set::IntervalTree rather than brute-force pairwise checks for speed and lower CPU cost.
  • Confirm coordinate base (0 vs 1) and file delimiters before comparing.
  • Create the output folder programmatically (File::Path::make_path or Path::Tiny->spewpath) and include simple logging counts (matches, total lines).
    Further reading: File::Find docs and Set::IntervalTree for overlap queries.

File::Find documentation
Set::IntervalTree on MetaCPAN

Recommended Answers

All 3 Replies

The File::Find module process the multiple sub directories.

use strict;
use warnings;
use File::Find;

my $root_path=qq{G:/CNV}; #Declare your input path

# Recursively it process all the sub directories in $root_path
find(\&process_multiple_dir, $root_path); 

sub process_multiple_dir
{
  if (-f && $File::Find::name =~ m{\.txt$}) # It process .txt format files only
  {
    undef $/;  # Input Record separator

    # Files Handling process 
    open (FIN, "<$File::Find::name") || die "Cannot Open the Input file";
    my $file=<FIN>;  # Assign the file handler to scalar variable
    close (FIN);

    # Change the file name for the output file creation purpose
    $File::Find::name=~ s{\.txt}{_Out.txt};

    # Do your file process here
    # . . . 
    # . . . 
    # . . . 

    # Print the $file contents to new file
    open (FOUT, ">$File::Find::name") || die "Cannot Create the Output file";
    print FOUT $file;
    close (FOUT);
  }
}
Member Avatar for Member #680522

Hi Thanks for your script.am new to programing side,just now am learning,i wll work out and see.

Member Avatar for Member #680522

sir,i did but am not getting,k now i wish to get some script to compare 2 micrarrya data's
1.my computer->program(G:)-> DTATA(folder)->inside this i have 5 folder more each folder consists of 1000 of data
a.microD(folder 1->consits of many data)
b.microA("2 ")
c.microE(3 )
d.microF(4 ")
e.microG(5 ")
like this i have different folder inside main folder DATA
in this i wish to take 2datas d,e folder inside this i have each 10 datas i need to compare these 2 datas i need to find same starting posistion and ending position in these 2 data ,how i need take in put and print the result in new folder..
(sample-id|chromosome|start-pos|end-pos[/U]|num-snp|cnv-length|hmm-state|copy-number|start-snp|end-snp)
in the 2 data also i have same i need to compare this start-pos,and end-postion,
how to take input...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.