Answers.Body: <p>Honestly, I wouldn't do it with a one-liner like this.  Make a proper bash script, so you can spend a couple of lines to get the naming just right.  Then you can use the bash script over and over again.  Easier to document too if the command line used is in a file, not just in terminal history.</p>
  <p>Also, yes, piping to convert to bam is almost certainly what you want to do.  But piping into a sort commmand is better.  And I think samtools sort will output a bam by itself if you ask it to.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-28T22:35:18.483Z
Answers.LastActivityDate: 2023-04-28T22:35:18.483Z
Answers.UserDisplayName: swbarnes2
Answers.Body: <p>I would recommend</p>
  <pre class="lang-sh prettyprint-override"><code>ls test/*.fastq|sed s,.fastq$,,|xargs -i echo ./minimap2 -ax map-ont reference.fna {}.fastq \&gt; {}.sam|sh
  </code></pre>
  <p>Replace trailing &quot;sh&quot; with <a href="https://www.gnu.org/software/parallel/" rel="nofollow noreferrer">GNU parallel</a> for concurrent jobs on the same node; replace with <a href="https://github.com/lh3/asub" rel="nofollow noreferrer">asub</a> for submitting array jobs to Slurm/LSF/SGE.</p>
  <p>Once you get used to this, you can do a variety of tasks quickly, like renaming files in batch, gzipping all files in parallel, format conversion in batch, aligning 100 files on a cluster, etc.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-29T04:17:18.933Z
Answers.LastActivityDate: 2023-04-29T04:17:18.933Z
Answers.UserDisplayName: user172818
Answers.Body: <p>The command is fine, it is just a suffix. If you want to trim the suffix then use <code>${i%.fastq}.sam</code> for the output, or even better convert the output from minimap2 to bam directly as this saves space:</p>
  <pre><code>./minimap2 -ax map-ont reference.fna &quot;<span class="math-container">${i}" | samtools view -o "$</span>{i%.fastq}&quot;.bam
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-29T23:31:27.720Z
Answers.Text: piping through `samtools sort` will save time as well as space
Answers.UserDisplayName: gringer
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-01T01:51:46.320Z
Answers.Text: @gringer Thank you for the suggestion.
Answers.UserDisplayName: hgf
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-28T07:06:11.663Z
Answers.LastActivityDate: 2023-04-28T11:53:23.417Z
Answers.LastEditDate: 2023-04-28T11:53:23.417Z
Answers.UserDisplayName: ATpoint
Body: <p>I am trying to do mapping with multiple sequences against a reference genome. I tried the following code: The outputfile is .fastq.sam. I need only .sam. How do I get it?</p>
  <pre><code>for i in test/*.fastq; 
  do
   ./minimap2 -ax map-ont reference.fna <span class="math-container">$i &gt; $</span>i.sam;
   done
  </code></pre>
  
Tags: <read-mapping>
Title: mapping nucleotide sequences
ThreadText: # mapping nucleotide sequences
  
  (Asked by: username_0 on 2023-04-28)
  
  I am trying to do mapping with multiple sequences against a reference genome. I tried the following code: The outputfile is .fastq.sam. I need only .sam. How do I get it?
  
  ```
  for i in test/*.fastq; 
  do
   ./minimap2 -ax map-ont reference.fna $i > $i.sam;
   done
  
  ```
  
  **Tags:** read-mapping
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_3 on 2023-04-28. Score: 5 | Accepted answer
  
  The command is fine, it is just a suffix. If you want to trim the suffix then use `${i%.fastq}.sam` for the output, or even better convert the output from minimap2 to bam directly as this saves space:
  
  ```
  ./minimap2 -ax map-ont reference.fna "${i}" | samtools view -o "${i%.fastq}".bam
  
  ```
  
  > **Comments:**
  > **username_4**: piping through `samtools sort` will save time as well as space  
  > **username_0**: @username_4 Thank you for the suggestion.  
  
  ---
  
  ### Answer by username_1 on 2023-04-28. Score: 1
  
  Honestly, I wouldn't do it with a one-liner like this. Make a proper bash script, so you can spend a couple of lines to get the naming just right. Then you can use the bash script over and over again. Easier to document too if the command line used is in a file, not just in terminal history.
  
  Also, yes, piping to convert to bam is almost certainly what you want to do. But piping into a sort commmand is better. And I think samtools sort will output a bam by itself if you ask it to.
  
  
  ---
  
  ### Answer by username_2 on 2023-04-29. Score: 1
  
  I would recommend
  
  ```sh
  ls test/*.fastq|sed s,.fastq$,,|xargs -i echo ./minimap2 -ax map-ont reference.fna {}.fastq \> {}.sam|sh
  
  ```
  
  Replace trailing "sh" with [GNU parallel](https://www.gnu.org/software/parallel/) for concurrent jobs on the same node; replace with [asub](https://github.com/lh3/asub) for submitting array jobs to Slurm/LSF/SGE.
  
  Once you get used to this, you can do a variety of tasks quickly, like renaming files in batch, gzipping all files in parallel, format conversion in batch, aligning 100 files on a cluster, etc.
  
  
  ---
  
  