text
stringlengths 0
828
|
---|
topcore = sorted(resultdict.items(), key=operator.itemgetter(1), reverse=True)
|
# If there are no results, populate negative results
|
if not resultdict:
|
sample[analysistype].blastresults = 'NA'
|
# If results, add a string of the best number of hits, and a string of the total number of genes
|
# This is currently 1013. If this changes, I may re-implement a dynamic method of determining
|
# this value
|
else:
|
sample[analysistype].blastresults[topcore[0][0]] = (str(topcore[0][1]), str(1013))
|
except FileNotFoundError:
|
sample[analysistype].blastresults = 'NA'
|
return metadata"
|
84,"def reporter(metadata, analysistype, reportpath):
|
""""""
|
Create the core genome report
|
:param metadata: type LIST: List of metadata objects
|
:param analysistype: type STR: Current analysis type
|
:param reportpath: type STR: Absolute path to folder in which the reports are to be created
|
:return:
|
""""""
|
header = 'Strain,ClosestRef,GenesPresent/Total,\n'
|
data = str()
|
for sample in metadata:
|
try:
|
if sample[analysistype].blastresults != 'NA':
|
if sample.general.closestrefseqgenus == 'Listeria':
|
# Write the sample name, closest ref genome, and the # of genes found / total # of genes
|
closestref = list(sample[analysistype].blastresults.items())[0][0]
|
coregenes = list(sample[analysistype].blastresults.items())[0][1][0]
|
# Find the closest reference file
|
try:
|
ref = glob(os.path.join(sample[analysistype].targetpath, '{fasta}*'
|
.format(fasta=closestref)))[0]
|
except IndexError:
|
# Replace underscores with dashes to find files
|
closestref = closestref.replace('_', '-')
|
ref = glob(os.path.join(sample[analysistype].targetpath, '{fasta}*'
|
.format(fasta=closestref)))[0]
|
# Determine the number of core genes present in the closest reference file
|
totalcore = 0
|
for _ in SeqIO.parse(ref, 'fasta'):
|
totalcore += 1
|
# Add the data to the object
|
sample[analysistype].targetspresent = coregenes
|
sample[analysistype].totaltargets = totalcore
|
sample[analysistype].coreresults = '{cg}/{tc}'.format(cg=coregenes,
|
tc=totalcore)
|
row = '{sn},{cr},{cg}/{tc}\n'.format(sn=sample.name,
|
cr=closestref,
|
cg=coregenes,
|
tc=totalcore)
|
# Open the report
|
with open(os.path.join(sample[analysistype].reportdir,
|
'{sn}_{at}.csv'.format(sn=sample.name,
|
at=analysistype)), 'w') as report:
|
# Write the row to the report
|
report.write(header)
|
report.write(row)
|
data += row
|
else:
|
sample[analysistype].targetspresent = 'NA'
|
sample[analysistype].totaltargets = 'NA'
|
sample[analysistype].coreresults = 'NA'
|
except KeyError:
|
sample[analysistype].targetspresent = 'NA'
|
sample[analysistype].totaltargets = 'NA'
|
sample[analysistype].coreresults = 'NA'
|
with open(os.path.join(reportpath, 'coregenome.csv'), 'w') as report:
|
# Write the data to the report
|
report.write(header)
|
report.write(data)"
|
85,"def annotatedcore(self):
|
""""""
|
Calculates the core genome of organisms using custom databases
|
""""""
|
logging.info('Calculating annotated core')
|
# Determine the total number of core genes
|
self.total_core()
|
# Iterate through all the samples, and process all Escherichia
|
for sample in self.metadata:
|
if sample.general.bestassemblyfile != 'NA':
|
# Create a set to store the names of all the core genes in this strain
|
sample[self.analysistype].coreset = set()
|
if sample.general.referencegenus == 'Escherichia':
|
# Add the Escherichia sample to the runmetadata
|
self.runmetadata.samples.append(sample)
|
# Parse the BLAST report
|
try:
|
report = sample[self.analysistype].report
|
self.blastparser(report=report,
|
sample=sample,
|
fieldnames=self.fieldnames)
|
except KeyError:
|
sample[self.analysistype].coreset = list()
|
# Create the report
|
self.reporter()"
|
86,"def total_core(self):
|
""""""
|
Determine the total number of core genes present
|
""""""
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.