Skip to content

Commit

Permalink
Minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mcamagna committed Nov 7, 2023
1 parent c2a8642 commit 3eafca5
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions Pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def runStringtie(gff_file, mapping_folder="mapping", outfolder="abundance/"):
name = file.split(".bam")[0].split(".sam")[0]

cmd = f"stringtie -e -B -p {threads} {mapping_folder+file} -G {gff_file}"
cmd+= f"-A {outfolder + name}/{name}_gene_expression.tsv"
cmd+= f" -A {outfolder + name}/{name}_gene_expression.tsv"
cmd+= f" -o {outfolder+name}/{name}.gtf"

print(cmd)
Expand Down Expand Up @@ -455,10 +455,7 @@ def convertToBAM(folder):
continue

name = file.split(".sam")[0]

cmd = "samtools sort -@ "+ str(threads)
cmd += " -o "+folder+name+".bam "
cmd += folder+file
cmd = f"samtools sort -@ {threads} -o {folder+name}.bam {folder+file}"

print(cmd)
returnCode = os.system(cmd)
Expand All @@ -477,7 +474,6 @@ def prepareReads(folder=".", arePaired=False):

for r in reads:
basename = getBasenameOfRead(r)
#print(basename)
entry = sample_dict.get(basename)

if entry is None:
Expand All @@ -487,7 +483,6 @@ def prepareReads(folder=".", arePaired=False):

sample_dict[basename] = entry

#print(sample_dict)

samples = []
for basename, reads in sample_dict.items():
Expand Down Expand Up @@ -575,12 +570,15 @@ def checkIfAllPrerequisitesInstalled():

parser = argparse.ArgumentParser()
parser.add_argument("--skip_mapping", help="Skip mapping to genome", action="store_true")
parser.add_argument("--outfolder", help="The folder where the results will be written to", default="./")
parser.add_argument("--reads_folder", help="The folder where the reads are located", default="./reads")
parser.add_argument("--genome_folder", help="The folder where the genome is located", default="./genome")
parser.add_argument("--threads", help="The number of threads used", default=f"{os.cpu_count()}")

args = parser.parse_args()

folder = args.outfolder

reads_folder = args.reads_folder
reads_folder = assureFolderEndsWithSlash(reads_folder)

Expand Down Expand Up @@ -638,26 +636,26 @@ def checkIfAllPrerequisitesInstalled():

genome = lookForGenome(genome_folder)
if genome is not None:
if not genomeIsAlreadyIndexed(genome_folder):
print("Building the genome index.")
print()

buildIndex(genome)
else:
reindex = input("I found a genome index in the genome folder. Do you want to skip building the index? (yes/no) ")
if "n" in reindex.lower():
if not args.skip_mapping:
if not genomeIsAlreadyIndexed(genome_folder):
print("Building the genome index.")
print()

buildIndex(genome)
else:
reindex = input("I found a genome index in the genome folder. Do you want to skip building the index? (yes/no) ")
if "n" in reindex.lower():
print("Building the genome index.")
print()
buildIndex(genome)

else:
print("Could not find a genome file in the genomes folder. Exiting")
quit()


print()
if not os.path.exists(folder+"mapping"):
os.mkdir(folder+"mapping")
os.makedirs(folder+"mapping", exist_ok=True)

if not args.skip_mapping:
mapToGenome(samples, genome, folder+"mapping")
Expand Down

0 comments on commit 3eafca5

Please sign in to comment.