Ejemplo n.º 1
0
 def __init__(self, metassembledir, refphylfile, refstatsfile, contigs_to_refs_file, sep="\t"):
     self.metassembledir = metassembledir.rstrip('/')
     self.refphylfile = refphylfile
     self.refstatsfile = refstatsfile
     self.contigs_to_refs_file = contigs_to_refs_file
     self.contigs_to_refs_dict = read_2col_table(contigs_to_refs_file, sep=sep)
     self.refs = ReferenceSet(refphylfile, refstatsfile, self.contigs_to_refs_dict)
Ejemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        self.bamref = kwargs.pop("bamref", None)
        self.bamasm = kwargs.pop("bamasm", None)
        self.refs = kwargs.pop("referenceset", None)
        refstatsfile = kwargs.pop("refstatsfile", None)
        refphylfile = kwargs.pop("refphylfile", None)
        self.covbedasm = kwargs.pop("covbedasm", None)
        self.cut_off = kwargs.pop("cut_off", 100)
        self.missing_value = kwargs.pop("missing_value", "N/A")
        contigs_to_refs_table = kwargs.pop("contigs_to_refs_table", None)
        self.jellyfish_output = kwargs.pop("jellyfish_output", None)
        self.jellyfish_reffa = kwargs.pop("jellyfish_reffa", None)
        if contigs_to_refs_table:
            self.contigs_to_refs_dict = read_2col_table(contigs_to_refs_table, sep="\t")
        else:
            self.contigs_to_refs_table = None
        if len(kwargs) > 0:
            raise(Exception("Unexpected keyword argument found %s" % kwargs))

        self.asmfa = args[0]
        self.coordsfile = args[1]

        # Determine reference metagenome
        if not self.refs:
            if refphylfile and refstatsfile:
                self.refs = ReferenceSet(refphylfile, refstatsfile, contigs_to_refs_dict=self.contigs_to_refs_dict)
            else:
                raise(Exception("Either supply refphylfile and refstatsfile or an existing reference set"))

        # Determine read-contig and read-reference mappings from bam files if
        # available
        if self.bamref and self.bamasm and self.covbedasm:
            self.reads, self.contigs = assembly.get_read_contig_mappings(self.bamref,
                                                                         self.bamasm,
                                                                         self.refs,
                                                                         self.asmfa,
                                                                         self.cut_off)
            self.contigs.parse_cov_bed(self.covbedasm)
        else:
            self.contigs = assembly.ContigDict()
            self.contigs.parse_fasta_lengths(self.asmfa)

        # Calculate stats from nucmer alignments
        self.coords = nucmer.Coords(self.coordsfile)
        self.coords.calc_max_aln_purity_per_contig(self.contigs, self.cut_off)

        if self.jellyfish_output and self.jellyfish_reffa:
            self.jfr = jellyfish.JellyfishRef(args.jellyfish_reffa, args.jellyfish_output)