ablakely has asked for the wisdom of the Perl Monks concerning the following question:
Here's my code:
Right now I am just getting an empty file for an output. If I replace /$seq/ with /AAA/ or any other literal, it works just fine.#!/usr/bin/perl -w my $seq; open (SEQ, "<$ARGV[0]"); open (REP, "<$ARGV[1]"); open (OUT, ">$ARGV[2]"); while (<SEQ>){ $seq = $_; while (<REP>){ print OUT if /$seq/; } } close (SEQ); close (REP); close (OUT);
I'm sure its something easy, but I've been googling all afternoon to no avail.
Here are examples of the contents of the SEQ and REP files:
Thanks for your help!SEQ: AELIVQPELK REP: 1 116.68 116.68 48.2199996709824 26.8999993801117 21.17 +99994111061 ENST00000379802_141 [201 - 8954] cdna:known chromos +ome:GRCh37:6:7541808:7586950:1 gene:ENSG00000096696 gene_biotype:prot +ein_coding transcript_biotype:protein_coding 2 99.00000 +09536743 AELIVQPELK -5.64623987884261E-05 1138.65991 +210938 570.3372 1138.65979003906 570.337158203125 2 14 + 2.1.1.3480.1 1 0.7224 -1 -1
Update: Got what I wanted with the following code. Thanks for the input everyone, it was helpful. I was unaware of the mechanics of a while loop using an open file as a condition. I'm sure its still a little messy but I'm a biologist not a programmer, so what can you expect?
#!/usr/bin/perl -w use strict; my (@seq, @rep, $i, $n, $l, $t); open (SEQ, "<$ARGV[0]"); open (REP, "<$ARGV[1]"); open (OUT, ">$ARGV[2]"); $i=0; $n=0; $l=0; while (<SEQ>){ chomp(); $seq[$i] = $_; $i++; } while (<REP>){ $rep[$n] = $_; $n++; } while ($l < $i){ $t=0; while ($t < $n){ print OUT $rep[$t] if $rep[$t] =~ /$seq[$l]/; $t++; } $l++; } close (SEQ); close (REP); close (OUT);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Simple filter from rows of input file
by toolic (Bishop) on Aug 13, 2014 at 20:25 UTC | |
|
Re: Simple filter from rows of input file
by Laurent_R (Canon) on Aug 13, 2014 at 21:51 UTC | |
|
Re: Simple filter from rows of input file
by 2teez (Vicar) on Aug 13, 2014 at 20:32 UTC | |
|
Re: Simple filter from rows of input file
by Anonymous Monk on Aug 13, 2014 at 23:39 UTC | |
|
Re: Simple filter from rows of input file
by Anonymous Monk on Aug 13, 2014 at 20:25 UTC |