Question: linux command in a perl script problem (sam to fastq)
0
gravatar for rob234king
6.8 years ago by
rob234king600
UK/Harpenden/Rothamsted Research
rob234king600 wrote:

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 • 2.9k views
ADD COMMENTlink modified 6.8 years ago by JC12k • written 6.8 years ago by rob234king600
3
gravatar for Pierre Lindenbaum
6.8 years ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum134k wrote:

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 COMMENTlink modified 14 months ago by Ram32k • written 6.8 years ago by Pierre Lindenbaum134k

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 REPLYlink modified 14 months ago by Ram32k • written 6.8 years ago by rob234king600

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

Thanks for the input it helped me to think

ADD REPLYlink modified 14 months ago by Ram32k • written 6.8 years ago by rob234king600
3
gravatar for JC
6.8 years ago by
JC12k
Mexico
JC12k wrote:

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 COMMENTlink modified 14 months ago by Ram32k • written 6.8 years ago by JC12k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2637 users visited in the last hour
_