Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Stuck in Perl.. Partial code, but it needs more improvement.. Any suggestions, please?

by Marshall (Canon)
on May 31, 2021 at 23:43 UTC ( #11133338=note: print w/replies, xml ) Need Help??


in reply to Stuck in Perl.. Partial code, but it needs more improvement.. Any suggestions, please?

Your problem description didn't mention how your code fails. So, my first step was to add a line "exit;" right at the start of your code and then try to run the code. I put that exit statement in just to see compile errors. Your code does not come anywhere close to compiling. Perl gives up after the first 34 compile errors!

I would strongly recommend investigating BioPerl. Due to the regex matching capabilities of Perl, Perl excels at DNA bio stuff.

You should be aware that a FORTRAN or C style loop, eg. for ($start=0; $start <= $index_max; $start++) is rare in Perl. While this is legal syntax, the very most common error in programming is the "off by one error". Perl can iterate over an array without using index values.

Again, I recommend that you investigate bioperl. Without any experience or proof, I HIGHLY suspect that parsing a record like shown below is a basic function of that universe of programs and modules.

I recoded part of what I think you are trying to do below.
I did not code the option to eliminate the "sig_peptide" line from @CDS.
See Flipin good, or a total flop? for more details of how to do that.

Without more data like shown below, I am unable to help further.

use strict; use warnings; $|=1; my @CDS; my @ORIGIN; while (my $line =<DATA>) { next unless ($line =~ /\S/); #skip blank data lines push (@CDS,$line) if ( $line =~ /^\s+CDS/ ... $line =~/^\s*[a-z]+/ +); push (@ORIGIN, $line) if ($line =~ /^\s*ORIGIN/...$line !~/\s*\d/); + } print "CDS section:\n"; print @CDS; print "\nORIGIN section:\n"; print @ORIGIN; =PRINTS: ########## a copy from my command line output #### CDS section: CDS 10..1011 /gene="hemoglobin" /codon_start=1 /product="hemoglobin" /protein_id="AAA29796.1" /translation="MHSSIVLATVLFVAIASASKTRELCMKSLEHAKVG +TSKEAKQDG IDLYKHMFEHYPAMKKYFKHRENYTPADVQKDPFFIKQGQNILLACHVL +CATYDDRET FDAYVGELMARHERDHVKVPNDVWNHFWEHFIEFLGSKTTLDEPTKHAW +QEIGKEFSH EISHHGRHSVRDHCMNSLEYIAIGDKEHQKQNGIDLYKHMFEHYPHMRK +AFKGRENFT KEDVQKDAFFVNKDTRFCWPFVCCDSSYDDEPTFDYFVDALMDRHIKDD +IHLPQEQWH EFWKLFAEYLNEKSHQHLTEAEKHAWSTIGEDFAHEADKHAKAEKDHHE +GEHKEEHH" sig_peptide 10..63 ORIGIN section: ORIGIN 1 ggaaccatta tgcactcttc aatagttttg gccaccgtgc tctttgtagc gattg +cttca 61 gcatcaaaaa cgcgagagct atgcatgaaa tcgctcgagc atgccaaggt tggca +ccagc =cut ## Data is abbreviated from https://www.ncbi.nlm.nih.gov/nuccore/M8505 +0.1 ## example URL courtesty of [glycine] __DATA__ COMMENT Original source text: Pseudoterranova decipiens larval cDN +A to mRNA. FEATURES Location/Qualifiers source 1..1353 /organism="Pseudoterranova decipiens" /mol_type="mRNA" /db_xref="taxon:6271" /dev_stage="larval" gene 1..1353 /gene="hemoglobin" 5'UTR 1..9 /gene="hemoglobin" CDS 10..1011 /gene="hemoglobin" /codon_start=1 /product="hemoglobin" /protein_id="AAA29796.1" /translation="MHSSIVLATVLFVAIASASKTRELCMKSLEHAKVG +TSKEAKQDG IDLYKHMFEHYPAMKKYFKHRENYTPADVQKDPFFIKQGQNILLACHVL +CATYDDRET FDAYVGELMARHERDHVKVPNDVWNHFWEHFIEFLGSKTTLDEPTKHAW +QEIGKEFSH EISHHGRHSVRDHCMNSLEYIAIGDKEHQKQNGIDLYKHMFEHYPHMRK +AFKGRENFT KEDVQKDAFFVNKDTRFCWPFVCCDSSYDDEPTFDYFVDALMDRHIKDD +IHLPQEQWH EFWKLFAEYLNEKSHQHLTEAEKHAWSTIGEDFAHEADKHAKAEKDHHE +GEHKEEHH" sig_peptide 10..63 /gene="hemoglobin" mat_peptide 64..1008 /gene="hemoglobin" /product="hemoglobin" misc_feature 696..737 /gene="hemoglobin" /phenotype="'altered epitope (frameshift)'" 3'UTR 1013..1353 /gene="hemoglobin" ORIGIN 1 ggaaccatta tgcactcttc aatagttttg gccaccgtgc tctttgtagc gattg +cttca 61 gcatcaaaaa cgcgagagct atgcatgaaa tcgctcgagc atgccaaggt tggca +ccagc
  • Comment on Re: Stuck in Perl.. Partial code, but it needs more improvement.. Any suggestions, please?
  • Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11133338]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2021-08-06 01:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)








    Results (44 votes). Check out past polls.

    Notices?