linux command in a perl script problem (sam to fastq)
2
0
Entering edit mode
9.9 years ago
rob234king ▴ 610

I'm trying to run this linux command which converts a sam file to fastq reads file and works on the command line to work from a perl script (the sam to fastq tool I found does not work in this instance hence why using the command line) but I think I'm having some issues getting the perl version to work:

cat A.sam | grep -v ^@ | awk '{print "@"$1"\n"$10"\n+\n"$11}' > A.fastq
system("cat $SAMdata[$i].sam | grep -v ^\@ | awk \'{print \"\@\"\$1\"\n\"\$10\"\n+\n\"\$11}\' > $SAMdata[$i].fastq ") == 0 or die "system convert sam to Fastq: $?";

I've been staring at this for a while and can't get it to work and tried a few things but I think I'm missing something obvious, so hopefully someone will see the mistake that I'm missing which I can correct?

perl • 3.7k views
ADD COMMENT
3
Entering edit mode
9.9 years ago

instead of using grep+awk you could use awk only:

/^@/ { printf("@%s\n%s\n+\n%s\n",$1,$10,$11);}");}

why on earth calling awk inside perl?

sometimes when calling system, your software doesn't know the value of ${PATH}

don't you need to escape the '$' in '$1, $10, $11'

ADD COMMENT
0
Entering edit mode

just corrected the escaping $ plus a few others but now got this error:

awk: {print "@"$1"
awk:             ^ unterminated string

I'll have a go a just awk.

ADD REPLY
0
Entering edit mode

worked it out, need to escape \n so \\n and for } instead \}

Thanks for the input it helped me to think

ADD REPLY
3
Entering edit mode
9.9 years ago
JC 13k

Or simply use Perl for everything:

cat A.sam | perl -lane 'print "\@$F[0]\n$F[9]\n+\n$F[10]" unless (/^@/)' > A.fastq
ADD COMMENT

Login before adding your answer.

Traffic: 1970 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6