Answers.Body: <p>Given that you're aligning human mitochondrial DNA sequences, consider aligning each sequence to the Reconstructed Sapiens Reference Sequence (RSRS) as a base for alignment:</p>
  <p><a href="http://phylotree.org/resources/RSRS_annotated.htm" rel="nofollow noreferrer">http://phylotree.org/resources/RSRS_annotated.htm</a></p>
  <p>Aligning to <a href="https://doi.org/10.1016/j.ajhg.2012.03.002" rel="nofollow noreferrer">a well-curated outgroup</a> should give you a better estimate of DNA age, and make it easier to compare variants.</p>
  <p>My preference when aligning large sequences is to use LAST, because it produces good base-level matching, and can be trained and/or tweaked as needed to improve alignment accuracy in unusual situations. LAST will produce alignments including [only] the aligned part as its default MAF output:</p>
  <p><a href="https://gitlab.com/mcfrith/last" rel="nofollow noreferrer">https://gitlab.com/mcfrith/last</a></p>
  <p>Information on how to use it can be found in the <a href="https://gitlab.com/mcfrith/last/-/blob/main/doc/last-cookbook.rst" rel="nofollow noreferrer">cookbook</a>. It generally follows the process for most aligners:</p>
  <ol>
  <li>Generate an index for the reference sequence</li>
  <li>Align the query sequences to the generated reference</li>
  </ol>
  <p>In the case of LAST, an additional training step can be added after index generation; the process is as follows:</p>
  <pre><code>$ lastdb RSRS.fa RSRS.fa
  $ last-train RSRS.fa query_sequences.fa &gt; trained.mat
  $ lastal -p trained.mat RSRS.fa query_sequences.fa &gt; query_aligned.maf
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-07-16T22:30:27.567Z
Answers.LastActivityDate: 2024-07-17T22:08:21.067Z
Answers.LastEditDate: 2024-07-17T22:08:21.067Z
Answers.UserDisplayName: gringer
Answers.Body: <p>When a phylogenetics calculation goes wrong the bug is almost certainly the alignment - so that bit of the question I understand. This suggests a machine learning algorithm is being used. In that case it's the vectorisation of the alignment. If thats the program then the alignment needs to absolutely as occurred in the original training data (if its ML). That could be the problem.</p>
  <p>The key to the question is understanding the &quot;classifier&quot; because its understanding the input into that algorithm.</p>
  <p>Anyway, any aligner will do MAFFT or Muscle 5 -superfast option. Simply input sequences in fasta format and click or activate the &quot;align&quot; function. Including an example of the original sequence the ML (you mentioned it was a &quot;classifier&quot;) was based on is very good idea.</p>
  <p>Automated editing is via trimal using <code>-nogaps</code> option. However, you should manually inspect your alignment and edit it prior using trimal and Sequtron (Macs) is cool. Manually editing the alignment is standard practice.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-07-16T19:31:22.600Z
Answers.Text: Do you recommend any aligner in specific? Some that I could use in command line to add it to the pipeline in my python code. I've tried to use bowtie2, but it gives me an error: "Error: reads file does not look like a FASTQ file"
Answers.UserDisplayName: dyxcvi
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-07-16T22:01:41.327Z
Answers.Text: This is an "assembler" not an "aligner" in my definitions, bwa-mem2 is a highly memory efficient assembler. bowtie2 hasn't been recommended for some time.
Answers.UserDisplayName: M__
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-07-16T22:17:51.913Z
Answers.Text: bowtie2 and bwa-mem are aligners, not assemblers
Answers.UserDisplayName: gringer
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-07-16T22:19:53.433Z
Answers.Text: Not in my field. An aligner is MAFFT, Muscle, Clustal.
Answers.UserDisplayName: M__
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-07-16T17:26:24.507Z
Answers.LastActivityDate: 2024-07-16T17:36:41.830Z
Answers.LastEditDate: 2024-07-16T17:36:41.830Z
Answers.UserDisplayName: M__
Body: <p>I have two fastas and I'd like to align them to extract the aligned part. I've just found examples (Several of them) of alignment of FASTQs using FASTA references, so I'm not sure if what I want really makes sense.
  Just to give a context, I want to find the alignment between the FASTAs, then extract the aligned part to feed a classifier that will use this data to estimate the DNA age based on the age range labels of the fastas I have in the database. I'm currently having an error larger than the expected, and I'm trying to find out if it is caused by the differences between the sequences, so I'd like to use just the aligned part in the classifier.</p>
  <p>Is it possible/Does it make sense to align the FASTA sequences, and which would be the best tool for that?</p>
  <p>EDIT: All the sequences are from human mitochondrial DNA. We have some complete modern samples and some ancient non-complete, damaged samples. They are expected to be similar, but we are expecting that the age range estimations can be derived from the DNA modifications that happens with time. We have several samples for validation, we expect most of the validation samples to be partially aligned, since we have several ancient damaged samples. So we discard the parts with poor alignment and hopefully we'll have a more reliable material for the classifier.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-07-16T17:08:29.807Z
Comments.Text: I've added the information you recommended. Well, maybe the aligners have some threshold so we discard the parts based on the quality? Does it exist?
Comments.UserDisplayName: dyxcvi
Tags: <phylogenetics><fasta>
Title: How to align two FASTAs and extract the aligned part?
ThreadText: # How to align two FASTAs and extract the aligned part?
  
  (Asked by: username_0 on 2024-07-16)
  
  I have two fastas and I'd like to align them to extract the aligned part. I've just found examples (Several of them) of alignment of FASTQs using FASTA references, so I'm not sure if what I want really makes sense.
  Just to give a context, I want to find the alignment between the FASTAs, then extract the aligned part to feed a classifier that will use this data to estimate the DNA age based on the age range labels of the fastas I have in the database. I'm currently having an error larger than the expected, and I'm trying to find out if it is caused by the differences between the sequences, so I'd like to use just the aligned part in the classifier.
  
  Is it possible/Does it make sense to align the FASTA sequences, and which would be the best tool for that?
  
  EDIT: All the sequences are from human mitochondrial DNA. We have some complete modern samples and some ancient non-complete, damaged samples. They are expected to be similar, but we are expecting that the age range estimations can be derived from the DNA modifications that happens with time. We have several samples for validation, we expect most of the validation samples to be partially aligned, since we have several ancient damaged samples. So we discard the parts with poor alignment and hopefully we'll have a more reliable material for the classifier.
  
  **Tags:** phylogenetics, fasta
  
  > **Comments:**
  > **username_0**: I've added the information you recommended. Well, maybe the aligners have some threshold so we discard the parts based on the quality? Does it exist?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2024-07-16. Score: 1 | Accepted answer
  
  Given that you're aligning human mitochondrial DNA sequences, consider aligning each sequence to the Reconstructed Sapiens Reference Sequence (RSRS) as a base for alignment:
  
  <http://phylotree.org/resources/RSRS_annotated.htm>
  
  Aligning to [a well-curated outgroup](https://doi.org/10.1016/j.ajhg.2012.03.002) should give you a better estimate of DNA age, and make it easier to compare variants.
  
  My preference when aligning large sequences is to use LAST, because it produces good base-level matching, and can be trained and/or tweaked as needed to improve alignment accuracy in unusual situations. LAST will produce alignments including [only] the aligned part as its default MAF output:
  
  <https://gitlab.com/mcfrith/last>
  
  Information on how to use it can be found in the [cookbook](https://gitlab.com/mcfrith/last/-/blob/main/doc/last-cookbook.rst). It generally follows the process for most aligners:
  
  1. Generate an index for the reference sequence
  2. Align the query sequences to the generated reference
  
  In the case of LAST, an additional training step can be added after index generation; the process is as follows:
  
  ```
  $ lastdb RSRS.fa RSRS.fa
  $ last-train RSRS.fa query_sequences.fa > trained.mat
  $ lastal -p trained.mat RSRS.fa query_sequences.fa > query_aligned.maf
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2024-07-16. Score: 0
  
  When a phylogenetics calculation goes wrong the bug is almost certainly the alignment - so that bit of the question I understand. This suggests a machine learning algorithm is being used. In that case it's the vectorisation of the alignment. If thats the program then the alignment needs to absolutely as occurred in the original training data (if its ML). That could be the problem.
  
  The key to the question is understanding the "classifier" because its understanding the input into that algorithm.
  
  Anyway, any aligner will do MAFFT or Muscle 5 -superfast option. Simply input sequences in fasta format and click or activate the "align" function. Including an example of the original sequence the ML (you mentioned it was a "classifier") was based on is very good idea.
  
  Automated editing is via trimal using `-nogaps` option. However, you should manually inspect your alignment and edit it prior using trimal and Sequtron (Macs) is cool. Manually editing the alignment is standard practice.
  
  > **Comments:**
  > **username_0**: Do you recommend any aligner in specific? Some that I could use in command line to add it to the pipeline in my python code. I've tried to use bowtie2, but it gives me an error: "Error: reads file does not look like a FASTQ file"  
  > **username_2**: This is an "assembler" not an "aligner" in my definitions, bwa-mem2 is a highly memory efficient assembler. bowtie2 hasn't been recommended for some time.  
  > **username_1**: bowtie2 and bwa-mem are aligners, not assemblers  
  > **username_2**: Not in my field. An aligner is MAFFT, Muscle, Clustal.  
  
  ---
  
  