lairel has asked for the wisdom of the Perl Monks concerning the following question:
I have the majority of my code running properly, but I am getting repeats of the header for each corresponding output instead of one iteration of the header for all corresponding output. I don't think I am explaining that well, so I have included my current output with the desired output. My code
#!/usr/bin/perl use strict; use warnings; use diagnostics; unless (open (INFILE, "<", "/scratch/SampleDataFiles/test.fasta")){ die "Unable to open file", $!; } local $/ = ">"; #find and print desired sequence while (<INFILE>) { chomp; #always chomp if ( $_ =~ /^(.*?)$(.*)$/ms ) { #match first line as h +eader my $header = $1; #assign the parts of the matc +h my $seq = $2; $seq =~ s/\n//g; #get rid of whitespace while($seq =~ /([VILMFWCA]{8,})/g){ #s +earch for desired sequence my $location = pos($seq); #fin +d location my $length = length($1 +); #determine length print "Hydrophobic str +etch found in: ", $header, "\n"; #printing outputs for results print $1, "\n"; print "The match was at positi +on: ", $location - $length + 1, "\n\n"; } } } close INFILE;
The output is supposed to look like this:
Hydrophobic stretch found in: P30450 | Homo sapiens (Human). | NCBI_Ta +xID=9606; | 365 | Name=HLA-A; Synonyms=HLAA; AVVAAVMW The match was at position: 325 Hydrophobic stretch found in: A7MBM2 | Homo sapiens (Human). | NCBI_Ta +xID=9606; | 1401 | Name=DISP2; Synonyms=DISPB, KIAA1742; VAVLMLCLAVIFLC The match was at position: 170 LLALVAIFF The match was at position: 493 IWICWFAALAA The match was at position: 705 LALALAFA The match was at position: 970
but my current output is like this:
Hydrophobic stretch found in: P30450 | Homo sapiens (Human). | NCBI_Ta +xID=9606; | 365 | Name=HLA-A; Synonyms=HLAA; AVVAAVMW The match was at position: 325 Hydrophobic stretch found in: A7MBM2 | Homo sapiens (Human). | NCBI_Ta +xID=9606; | 1401 | Name=DISP2; Synonyms=DISPB, KIAA1742; VAVLMLCLAVIFLC The match was at position: 170 Hydrophobic stretch found in: A7MBM2 | Homo sapiens (Human). | NCBI_Ta +xID=9606; | 1401 | Name=DISP2; Synonyms=DISPB, KIAA1742; LLALVAIFF The match was at position: 493 Hydrophobic stretch found in: A7MBM2 | Homo sapiens (Human). | NCBI_Ta +xID=9606; | 1401 | Name=DISP2; Synonyms=DISPB, KIAA1742; IWICWFAALAA The match was at position: 705 Hydrophobic stretch found in: A7MBM2 | Homo sapiens (Human). | NCBI_Ta +xID=9606; | 1401 | Name=DISP2; Synonyms=DISPB, KIAA1742; LALALAFA The match was at position: 970
I'm so close
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: One header for multiple results
by AppleFritter (Vicar) on Oct 21, 2015 at 14:51 UTC | |
by lairel (Novice) on Oct 21, 2015 at 15:09 UTC | |
|
Re: One header for multiple results
by AnomalousMonk (Archbishop) on Oct 21, 2015 at 15:00 UTC | |
|
Re: One header for multiple results
by Laurent_R (Canon) on Oct 21, 2015 at 14:40 UTC | |
|
Re: One header for multiple results
by GotToBTru (Prior) on Oct 21, 2015 at 14:58 UTC | |
by lairel (Novice) on Oct 21, 2015 at 15:08 UTC | |
by GotToBTru (Prior) on Oct 21, 2015 at 15:11 UTC |