Dear Perl Monks,
I am trying to "hack" (not a real coder)a script to break a text file like this:
>Long_DNA_Scaffold
atgctagsctgtagctagctagtcgatgctagtagct
ttagctagctgatgctagtcgatgctagtcatctagc
NNNNNNNNNNNNNNNNNNN
tagctagctagctgatcgtagctagtcgtagctagct
ggtcgatgctgatcgtagctgatgctagtcgatgcta
>Long_DNA_Scaffold2
atgctagsctgtagctagctagtcgatgctagtagct
tagctagctgatcgtagctagctgatgctagctagtc
NNNNNNNNNNNNNNNNNN
tagctagctagctgatgctagctagtcgatcgtagct
ggctagtgctagtgctagctgatgctagtcgtagctg
Into this:
>Long_DNA_Scaffold.0
atgctagsctgtagctagctagtcgatgctagtagct
ttagctagctgatgctagtcgatgctagtcatctagc
>Long_DNA_Scaffold.1
tagctagctagctgatcgtagctagtcgtagctagct
ggtcgatgctgatcgtagctgatgctagtcgatgcta
>Long_DNA_Scaffold2.0
atgctagsctgtagctagctagtcgatgctagtagct
tagctagctgatcgtagctagctgatgctagctagtc
>Long_DNA_Scaffold2.1
tagctagctagctgatgctagctagtcgatcgtagct
ggctagtgctagtgctagctgatgctagtcgtagctg
This is what a friend and I have tried:
#!/usr/bin/perl -w
open (IN, "$ARGV[0]");
$/=">";
$i=0;
while (<IN>) {
if(/^(\S+)?.*?\n(.*)/ms) {
$i++;
$seq[$i]=$2;
$name[$i]=$1;
}
}
close IN;
for $j(1..$i){
$j++;
tr/>//,$name[$j];
tr/>//,$seq[$j];
@sequence=split(/N+/,$seq[$j]);
$n=length(@sequence);
$seqs_to_print=$n-1;
# print "$name[$j]\tLength of seqs:$n\n";
for $x(0..$seqs_to_print){
print ">$name[$j].$x\n";
print "$sequence[$x]\n";
}
}
It "partially" works and I get a lot of "uninitialized value in transliteration" errors.
I will appreciate any help/poiners etc to get it to work
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.