Exemplo n.º 1
0
def generate_authority_file(taxa_list, fileinfo):
    ''' generates the csv file of the authority file'''

    csv_filename = fileinfo.csv_filename("authority_file")

    # Create a csv file
    f = CSVFile.CSVFile(csv_filename)

    # add the header
    header = [
        "", "Family", "Subfamily", "Tribe", "Genus", "SpecificEpithet",
        "SubspecificEpithet", "InfraspecificRank", "InfraspecificEpithet",
        "Authorship"
    ]

    f.add_line(header)

    # creates the records for each taxon in the list
    for i, taxa in enumerate(taxa_list):
        if i == 0:
            line = ["1"]
        else:
            line = [f"=A{i + 1} + 1"]

        line += [taxa.family]
        line += [prep_field(taxa.subfamily)]
        line += [prep_field(taxa.tribe)]
        line += [prep_field(taxa.genus)]

        # if is a genus the specie will be marked as "sp."
        if taxa.rank == Taxa.Taxa.rank_genus:
            line += ["sp."]
        else:
            line += [prep_field(taxa.specie)]

        line += [prep_field(taxa.subspecie)]
        line += [""]
        line += [""]
        line += [prep_field(taxa.author)]
        line += ["".join(f'{link}, ' for link in taxa.links)[:-2]]

        f.add_line(line)

    f.write()
    logger.log_short_report("Authority file saved file in:" + csv_filename)
Exemplo n.º 2
0
    def parse_file(self):

        if self.pathfile and os.path.isfile(self.pathfile):

            # read the CSV file containing higher taxonomy
            f = CSVFile.CSVFile(self.pathfile)
            lines = f.get_table()

            # store the already retrived subfamilies and tribes (these are
            # lists of AssociatedTaxa)
            subfamilies = []
            tribes = []

            def add_associate(in_higher_tax, rank_name, ranks, genus):

                # check if the higher taxonomy (subfamily or tribe) already
                # exists and if so add the corresponding genus
                # if it doesnt exist add a new higher taxonomy record and
                # add the genus to it
                for rank in ranks:
                    if rank.main_taxa == in_higher_tax:
                        rank.add_associate(genus)
                        break
                else:
                    new_rank = TaxaList.AssociatedTaxa(in_higher_tax,
                                                       rank_name)
                    new_rank.add_associate(genus)
                    ranks.append(new_rank)

            # skip the file header
            for subfamily, tribe, genus in lines[1:]:

                add_associate(subfamily, "subfamily", subfamilies, genus)
                add_associate(tribe, "tribe", tribes, genus)

            logger.log_short_report(
                "--- Additional taxonomical information ---")
            logger.log_short_report("Retrived subfamilies: " +
                                    str(len(subfamilies)))
            logger.log_short_report("Retrived tribes: " + str(len(tribes)))
            logger.log_short_report("From file:" + self.pathfile)

            return subfamilies, tribes
        else:
            return None
import sys
import CSVFile

file = CSVFile.CSVFile(sys.argv[1])

file.load()

data = file.getColumn(int(sys.argv[2]), float)

print('Maximo: ' + str(max(data)))
print('Minimo: ' + str(min(data)))
Exemplo n.º 4
0
    family_name = "Nepticulidae"

    ass = Associations()

    subfamilies, tribes = ass.find_associations(family_name)

    print("--- subfamilies ---")
    for sub in subfamilies:
        print(sub)

    print("--- tribes ---")
    for tribe in tribes:
        print(tribe)

    csv = CSVFile.CSVFile("./funet/" + family_name + "_subfamiles_tribes.csv")

    csv.add_line(["Subfamily", "Tribe", "Genus"])

    tot_genus = []

    for sub in subfamilies:
        for genus in sub.associates:
            tot_genus.append(genus)

    for tribe in tribes:
        for genus in tribe.associates:
            if genus not in tot_genus:
                tot_genus.append(genus)

    for genus in tot_genus:
Exemplo n.º 5
0
        lists['PERCENTPESQS'].append(float(b / t))
        lists['PERCENTRANK'].append(float(r) / maximo)

    return lists


def getNiveis(listaBolsistas):
    niveis = {'SR': [], '1A': [], '1B': [], '1C': [], '1D': [], '2': []}

    for bolsista, nivel in listaBolsistas:
        niveis[nivel].append(bolsista)

    return niveis


todos = CSVFile.CSVFile(sys.argv[1])
bolsistas = CSVFile.CSVFile(sys.argv[2])

todos.load()
bolsistas.load()

listaBolsistas = bolsistas.getColumns([(2, int), (4, str)])

niveis = getNiveis(listaBolsistas)

n1 = niveis['1A'] + niveis['1B'] + niveis['1C'] + niveis['1D']
codes = n1 + niveis['SR'] + niveis['2']

codes = set(codes)

PR = contaRank(todos, codes, 2)
import sys
import CSVFile

bolsistas = CSVFile.CSVFile(sys.argv[1])

bolsistas.load()

ranks = bolsistas.getColumn(3, int)

top100 = 0
top1k = 0
top10k = 0

for rank in ranks:
    if rank <= 10000:
        top10k = top10k + 1

        if rank <= 1000:
            top1k = top1k + 1

            if rank <= 100:
                top100 = top100 + 1

print("Top 100: " + str(top100))
print("Top 1k: " + str(top1k))
print("Top 10k: " + str(top10k))
import sys
import CSVFile
from operator import itemgetter as getter

def calculateRank(todos, codes):
	for pesq in todos:
		

todos = CSVFile.CSVFile(sys.argv[1])
bolsistas = CSVFile.CSVFile(sys.argv[2])

todos.load()
bolsistas.load()

codes = bolsistas.getColumn(1, int)

todosRankeados = CSVFile.CSVFile()