Ejemplo n.º 1
0
def get_task_parameters(args: argparse.Namespace, running_time) -> \
        TaskParameters:
    """Returns TaskParameters object based on parsed arguments."""

    return TaskParameters(
        running_time=running_time,
        multialignment_file_path=args.multialignment.filename,
        multialignment_format=str(type(args.multialignment).__name__),
        datatype=args.datatype.name,
        metadata_file_path=args.metadata.filename if args.metadata else None,
        blosum_file_path=args.blosum.filepath if args.blosum else None,
        output_path=args.output_dir,
        output_po=bool(args.output_po),
        output_fasta=bool(args.output_fasta),
        output_with_nodes=bool(args.output_full),
        verbose=bool(args.verbose),
        raw_maf=bool(args.raw_maf),
        fasta_provider=args.fasta_provider
        if args.fasta_provider else 'ConstSymbol',
        cache=bool(args.cache),
        missing_base_symbol=args.missing_symbol.value
        if args.missing_symbol else missings.MissingBase().value,
        fasta_source_file=str(args.fasta_path),
        consensus_type=args.affinity,
        hbmin=args.hbmin.value if args.hbmin else None,
        stop=args.stop.value if args.stop else None,
        p=args.p.value if args.p else None)
Ejemplo n.º 2
0
 def setUp(self) -> None:
     self.csv_files_dir = Path(__file__).parent.joinpath(
         "csv_files").resolve()
     self.alignment_files_dir = Path(__file__).parent.joinpath(
         "alignment_files").resolve()
     self.fasta_provider = missings.ConstBaseProvider(
         missings.MissingBase())
    def test_1_no_symbol_provided(self):
        missing_symbol = missings.MissingBase()
        const_symbol_provider = missings.ConstBaseProvider(missing_symbol)

        expected_symbol = graph.Base('?')
        actual_symbol = const_symbol_provider.get_base(msa.SequenceID('s'), 0)
        self.assertEqual(expected_symbol, actual_symbol)
    def test_3_incorrect_missing_symbol(self):
        with self.assertRaises(ValueError) as e:
            _ = missings.MissingBase('**')

        expected_message = 'Missing symbol must be a single character.'
        actual_message = str(e.exception)
        self.assertEqual(expected_message, actual_message)
Ejemplo n.º 5
0
def build_from_dagmaf(maf: msa.Maf,
                      fasta_provider: Optional[missings.FastaProvider] = missings.ConstBaseProvider(
                          missings.MissingBase()),
                      metadata: Optional[msa.MetadataCSV] = None,
                      datatype: Optional[graph.DataType] = graph.DataType.Nucleotides) -> \
        Tuple[graph.Poagraph, DAGMaf.DAGMaf]:
    """Converts MAF to DagMaf and builds poagraph from MAF file.

    Args:
        maf: Multialignment as MAF file.
        fasta_provider: Provider of bases missing in DagMaf.
        metadata: Metadata of sequences present in MAF.
        datatype: Type of the processed data (nucleotides/proteins).

    Returns:
        Tuple: poagraph based on given input data and dagmaf created
            from input MAF.
    """

    dagmaf = maf2dagmaf.get_dagmaf(maf)
    nodes, sequences = dagmaf2poagraph.get_poagraph(dagmaf,
                                                    fasta_provider,
                                                    metadata)
    p = graph.Poagraph(nodes, sequences)
    if metadata:
        graph.Poagraph.complement_metadata_for_sequences_absent_in_metadata_provided(p, metadata)
    p.datatype = datatype
    return p, dagmaf
 def setUp(self):
     metadata_path = Path(__file__).parent.joinpath(
         "../seq_metadata.csv").resolve()
     self.metadatacsv = msa.MetadataCSV(
         pathtools.get_file_content_stringio(metadata_path), metadata_path)
     self.maf_files_dir = Path(__file__).parent.joinpath(
         "maf_files_with_gaps").resolve()
     self.missing_n = missings.MissingBase()
Ejemplo n.º 7
0
def resolve_fasta_provider(args: argparse.Namespace) -> \
        missings.FastaProvider:
    """Returns fasta provider based on parsed arguments."""

    if args.fasta_provider is None:
        if args.missing_symbol is None:
            return missings.ConstBaseProvider(missings.MissingBase())
        else:
            return missings.ConstBaseProvider(args.missing_symbol)
    elif args.fasta_provider == 'ncbi':
        use_cache = args.cache if args.cache else False
        return missings.FromNCBI(use_cache)
    elif args.fasta_provider == 'file':
        if args.fasta_path is None:
            raise Exception("""Fasta file source must be specified.
                               It must be provided when fasta source
                               is \'local\'.""")
        return missings.FromFile(args.fasta_path)
    else:
        raise Exception("""Not known fasta provider.
                           Should be \'ncbi\' or \'file\' or None.
                           Cannot build graph.""")
 def setUp(self):
     metadata_path = Path(__file__).parent.joinpath("../seq_metadata.csv").resolve()
     self.metadatacsv = msa.MetadataCSV(pathtools.get_file_content_stringio(metadata_path), metadata_path)
     self.maf_files_dir = Path(__file__).parent.joinpath("maf_files_with_cycles_or_reversion").resolve()
     self.fasta_provider = missings.ConstBaseProvider(missings.MissingBase())