G'day Teju,

Welcome to the monastery.

I think this is closer to what you want:

#!/usr/bin/env perl use strict; use warnings; use autodie; open my $id_fh, '<', 'sample_ID.txt'; my %ids = map { s/^>//; $_ } grep { length } split /\s+/ => do { local + $/; <$id_fh> }; close $id_fh; { local $/ = "\n>"; open my $seq_fh, '<', 'sample_reads.fasta'; while (<$seq_fh>) { (my $key = (split)[0]) =~ s/^>//; next unless exists $ids{$key}; my ($head, $seq) = split /\n/, $_, 2; print '>' unless $head =~ /^>/; print "${head}_weight=$ids{$key}\n"; $seq =~ y/> \n//d; print "$seq\n"; } close $seq_fh; }

I only used the first five blocks of data from each file for my test. Here's the output:

>comp10003_c0_seq1 len=166 path=[748:0-22 1004:23-46 2527:47-165]_weig +ht=41 AAGTAGCCTATGCGCTACAGTAAGAAAGACAGGTGAAAAAATGGAAGTAAAACAATTAGATGACTACTTT +GGATATACAGAAAAGGGCAGTTCCTTAGAGGGGGAATTACGAGCAGGACTAACGACATTCTTGACAATG +GCGTACATTCTGTTTGTGAACCCAGAC >comp10004_c0_seq1 len=143 path=[2167:0-44 2322:45-68 2508:69-142]_wei +ght=25 AATCTTTAATTTAAACTTAAAAAAAATTAACTTTTGAAAGGAATTAAAATGGAAAAAGAAATGTTAGTAG +TAGCTAAATTAAAAGAAGGTACATTTGAAAAATTTATGGGTTTCATGCAATCGCCTGAAGGTTTAGCAG +AAAG

-- Ken


In reply to Re: A program to extract the reads and modify the seq ID by kcott
in thread A program to extract the reads and modify the seq ID by Teju

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.