Exemple #1
0
def filter_alignment_positions(aligned_sequences_file: AlignedDNAFASTAFormat,
                               maximum_gap_frequency: str,
                               maximum_position_entropy: str) -> \
        AlignedDNAFASTAFormat:
    aligned_sequences_fh = aligned_sequences_file.open()

    fasta_file = AlignedDNAFASTAFormat()

    skbio.write(filter_positions(aligned_sequences_fh, maximum_gap_frequency,
                                 maximum_position_entropy),
                into=str(fasta_file),
                format='fasta')

    return fasta_file
Exemple #2
0
def extract_fungi(
        aligned_silva_file: AlignedDNAFASTAFormat,
        accession_file: SilvaAccessionFormat,
        taxonomy_file: SilvaTaxonomyFormat,
        ) -> AlignedDNAFASTAFormat:

    aligned_silva_fh = aligned_silva_file.open()
    accession_fh = accession_file.open()
    taxonomy_fh = taxonomy_file.open()

    fasta_file = AlignedDNAFASTAFormat()
    skbio.write(fungi_from_fasta(aligned_silva_fh, accession_fh,
                taxonomy_fh), into=str(fasta_file), format='fasta')

    # TODO this code is a good example of pithy return for plugins
    # TODO redo other functions in the same way by instantiating a

    return fasta_file
Exemple #3
0
def _trim_all_sequences(aligned_sequences: AlignedDNAFASTAFormat,
                        trim_positions: dict) -> AlignedDNAFASTAFormat:
    """
    Trim all sequences within given alignment based on provided positions.

    Arguments:
        aligned_sequences (AlignedDNAFASTAFormat): original, aligned sequences
        trim_positions (dict): dictionary containing positions for trimming

    Returns:
        result (AlignedDNAFASTAFormat): trimmed aligned sequences
    """

    result = AlignedDNAFASTAFormat()
    with result.open() as out_fasta:
        for seq in aligned_sequences.view(AlignedDNAIterator):
            seq_trimmed = _trim_sequence(seq, trim_positions["start"],
                                         trim_positions["end"])
            seq_trimmed.write(out_fasta)
    return result