Here's a start, since you've not (yet?) replied to Kenosis' very proper request that you show us what you've tried (and how it failed to satisfy your needs, with error and warning messages, verbatim) as tokens of good faith that you're here to learn; not simply to have others do your work:
#!/usr/bin/perl use 5.016; use warnings; # 1068826 my $data = '>b_comp_seq1 ACGCGGGGGAATTT >b_comp_seq2 ACGGAATT >b_comp_ +seq3 GGGGGCTTTCACC >b_comp_seq4 TACCGGGAATT'; my @data1 = split /\s/, $data; my $i=0; my ($data1, $fh, $fn); for $_(@data1) { $_ =~ />(.*)/; $fn = $1; if ( $i%2 == 0 ) { open $fh, ">", $fn or warn "Can't open $fh for write, $!"; ++$i; print $fh "$fn \t $data1[$i]"; say " DEBUG: \$fn, \$data1[$i]: $fn, $data1[$i]"; close $fh; } else { ++$i; #ALSO -- # consider how to revert to writing to the first file for comp +_seq_5 # if that's the way you wish to order the elements; otherwise, + revise # the code above to put the first four sequences and their sou +rce # id's into the first file written. } } =head output files contain... b_comp_seq1 ACGCGGGGGAATTT b_comp_seq2 ACGGAATT b_comp_seq3 GGGGGCTTTCACC b_comp_seq4 TACCGGGAATT =cut
Left as a challenge for crayfish: adding sequences (and identifiers?) to the four files created here. Hint: hashes might be one way to go.
In reply to Re: separate files
by ww
in thread separate files
by crayfish
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |