G'day xxArwaxx,

"any ideas if there is a BioPerl module that can do that, or how to approach this problem ?"

I'm not familiar with the BioPerl modules; however, based on your problem description, a script to achieve this is very straightforward:

#!/usr/bin/env perl -l use strict; use warnings; use autodie; use Text::CSV; my $ref_file = 'pm_1079751_reference.csv'; my @gen_files = qw{pm_1079751_source1.gen pm_1079751_source2.gen}; my $allele_sep = '-'; my %ref_data; my $ref_csv = Text::CSV::->new; open my $ref_fh, '<', $ref_file; while (my $row = $ref_csv->getline($ref_fh)) { $ref_data{$row->[0]} = join $allele_sep, @$row[1,2]; } close $ref_fh; for my $gen_file (@gen_files) { my $gen_csv = Text::CSV::->new({allow_whitespace => 1}); open my $gen_fh, '<', $gen_file; while (my $row = $gen_csv->getline($gen_fh)) { next unless exists $ref_data{$row->[2]}; if ($ref_data{$row->[2]} eq join $allele_sep, @$row[3,4]) { print join(',' => @$row[2,3,4]), "\n\tfound in '$gen_file':\n\t\t", join ', ' => @$ +row; } } close $gen_fh; }

You stated the file you've already created is in CSV format, so I've used the Text::CSV module to parse it.

[Side note: CSV files have, by convention, a .csv extension, not a .txt extension (as you indicated you used).]

Your description of the .gen files seems to indicate a CSV format so I've used Text::CSV for these as well. If that's a false assumption on my part, you'll need to make some code changes; however, the logic I've used shouldn't need reworking.

Using these test files:

$ cat pm_1079751_reference.csv 34787638,A,C 34787800,A,G
$ cat pm_1079751_source1.gen C1, M1, 99999999, A, C, ... source1 info ... C1, M2, 34787638, A, G, ... source1 info ... C1, M3, 34787800, A, C, ... source1 info ... C1, M4, 34787800, A, G, ... source1 info ...
$ cat pm_1079751_source2.gen C1, M1, 99999999, A, C, ... source2 info ... C1, M2, 34787638, A, G, ... source2 info ... C1, M4, 34787800, A, G, ... source2 info ... C1, M3, 34787638, A, C, ... source2 info ...

I get this output:

34787800,A,G found in 'pm_1079751_source1.gen': C1, M4, 34787800, A, G, ... source1 info ... 34787800,A,G found in 'pm_1079751_source2.gen': C1, M4, 34787800, A, G, ... source2 info ... 34787638,A,C found in 'pm_1079751_source2.gen': C1, M3, 34787638, A, C, ... source2 info ...

-- Ken


In reply to Re: bioperl module to extract specific nucleotides given chromosome and exact location of that nucleotide by kcott
in thread bioperl module to extract specific nucleotides given chromosome and exact location of that nucleotide by xxArwaxx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.