Example #1
0
    def test_tree_integrity_ascii(self):
        with open('test_data/tree_example.p', 'rb') as file:
            test_tree = pickle.load(file)


        TaxTree.ranked_lineage_filepath = '../../bin/database/taxonomy/rankedlineage.dmp'

        rootNode = TaxTree.TaxNode("ROOT")
        TaxTree.loadRankedLineage(species_indexes,rootNode)
        rootNode.countChildren()
        ETETree = TaxTree.create_ETE_tree(rootNode)
        ascii = TaxTree.get_ASCII_tree(ETETree)

        self.assertEqual(ascii, test_tree)
Example #2
0
    def test_extract_data(self):
        test_lineage = "1805293	|	Candidatus Pacearchaeota archaeon CG1_02_30_18	|		|		|		|		|		|		|		|	Archaea	|"
        test_list = ['1805293 ', ' Candidatus Pacearchaeota archaeon CG1_02_30_18 ', ' ', ' ', ' ', ' ', ' ', ' ',
                     ' ', ' Archaea ']

        result_list = TaxTree.extract_data(test_lineage)
        self.assertEqual(result_list, test_list)
Example #3
0
    def test_least(self):
        with open('test_data/least_example.p', 'rb') as file:
            least_test = pickle.load(file)

        TaxTree.ranked_lineage_filepath = '../../bin/database/taxonomy/rankedlineage.dmp'

        rootNode = TaxTree.TaxNode("ROOT")
        TaxTree.loadRankedLineage(species_indexes, rootNode)
        rootNode.countChildren()

        ranks = ['Species', 'Genus', 'Family', 'Order',
                 'Class', 'Phylum', 'Kingdom', 'Superkingdom', 'All']

        f = io.StringIO()
        with redirect_stdout(f):
            for r in ranks:
                rootNode.calculateCommonnessByRank(r, 5, rootNode, False)
        output = f.getvalue()

        self.assertEqual(least_test, output)
Example #4
0
    def test_lineage_fix(self):

        original_lineage = [['Name', ' Human immunodeficiency virus 1 '], ['Species', ' '], ['Genus', ' Lentivirus '],
                        ['Family', ' Retroviridae '], ['Order', ' '], ['Class', ' '], ['Phylum', ' '], ['Kingdom', ' '],
                        ['Superkingdom', ' Viruses ']]
        fixed_lineage = [['Name', ' Human immunodeficiency virus 1 '], ['Species', ' Human immunodeficiency virus 1 '],
                         ['Genus', ' Lentivirus '], ['Family', ' Retroviridae '], ['Superkingdom', ' Viruses ']]

        test_lineage = TaxTree.fixLineage(original_lineage)

        self.assertEqual(test_lineage,fixed_lineage)
Example #5
0
    def test_ETETree(self):

        with open('test_data/ETETree_example.p', 'rb') as file:
            ETETree_example = pickle.load(file)
        TaxTree.ranked_lineage_filepath = '../../bin/database/taxonomy/rankedlineage.dmp'
        rootNode = TaxTree.TaxNode("ROOT")
        TaxTree.loadRankedLineage(species_indexes, rootNode)
        rootNode.countChildren()
        ETETree = TaxTree.create_ETE_tree(rootNode)

        f = io.StringIO()
        with redirect_stdout(f):
            ETETree.describe()
        ETE_describe = f.getvalue()

        t = io.StringIO()
        with redirect_stdout(t):
            ETETree_example.describe()
        ETE_test_describe = t.getvalue()

        self.assertEqual(ETE_describe,ETE_test_describe)
Example #6
0
start = time.time()

# Initial safety checks.
args = parser.parse_args()
check_tree_args(args)
args.most = check_indexing_args(args.most)
args.least = check_indexing_args(args.least)

blastXMLRecords = open_BLAST_XML_file(args)  #BLAST Output + extra stats
match_names = blast_parse(blastXMLRecords)

if (args.most or args.least or args.visualise or args.ascii
        or args.save_ascii):  #last second fix, do refactor

    species_indexes = TaxMatch.match_results_to_taxonomy(
        match_names)  # Matching for most/least & tree work.
    TaxTree.main(species_indexes, args)
# Sample tree used in the unit tests.
#species_indexes = ["9606","63221","741158","11676","7157","842271","1350382","1289305","1427098","1042"]
# There may come a time that tree functionality will be expanded to the point of needing to generate new pickles.
# Use the above to generate them.
#

end = time.time()
print("Finished in", end - start)

#Personal reference for Tabular Output
#Query ID, Subject ID, Percentage of Identical Matches, Alignment Length, Number Of Mismatches, Number Of Gap Openings,
#Start Of Alignment Query, End Of Alignment Query, Start Of Alignment Subject, End Of Alignment Subject, Expect Value, Bit Score
# also known as:
#qseqid sseqid pident length mismatch gapopen qstart qend sstart send evalue bitscore