Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
530 changes: 383 additions & 147 deletions reform.py

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions test_data/17/gold.fa
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
>X
ZZZZABBBBBDDDDDCCCCCIIIIIKKKKK
>Y
AAAATTTTGGGGCCCC
8 changes: 8 additions & 0 deletions test_data/17/gold.gtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
X ref exon 5 25 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
X ref CDS 8 22 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
X ref start_codon 5 7 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
X ref stop_codon 23 25 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
Y ref exon 1 16 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
Y ref CDS 4 14 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
Y ref start_codon 1 3 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
Y ref stop_codon 14 16 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
2 changes: 2 additions & 0 deletions test_data/17/in.fa
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
>Y
AAAATTTTGGGGCCCC
4 changes: 4 additions & 0 deletions test_data/17/in.gtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Y ref exon 1 16 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
Y ref CDS 4 14 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
Y ref start_codon 1 3 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
Y ref stop_codon 14 16 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
2 changes: 2 additions & 0 deletions test_data/17/ref.fa
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
>X
ZZZZABBBBBDDDDDCCCCCIIIIIKKKKK
4 changes: 4 additions & 0 deletions test_data/17/ref.gtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
X ref exon 5 25 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
X ref CDS 8 22 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
X ref start_codon 5 7 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
X ref stop_codon 23 25 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
8 changes: 8 additions & 0 deletions test_data/18/gold.fa
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
>X
ZZZZABBBBBDDDDDCCCCCIIIIIKKKKK
>Y
AAAATTTTGGGGCCCC
>H
GGGGAATTCCCCGGGG
>M
CCCCGGGGAAAATTTT
18 changes: 18 additions & 0 deletions test_data/18/gold.gtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
X ref exon 5 25 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
X ref CDS 8 22 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
X ref start_codon 5 7 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
X ref stop_codon 23 25 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
##sequence-region Y 1 16
Y ref exon 1 16 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
Y ref CDS 4 14 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
Y ref start_codon 1 3 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
Y ref stop_codon 14 16 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
##sequence-region H 1 16
H ref exon 1 16 . + 0 gene_id "gene2"; transcript_id "gene2.1";
H ref CDS 4 14 . + 0 gene_id "gene2"; transcript_id "gene2.1";
H ref start_codon 1 3 . + 0 gene_id "gene2"; transcript_id "gene2.1";
H ref stop_codon 14 16 . + 0 gene_id "gene2"; transcript_id "gene2.1";
M ref exon 1 16 . + 0 gene_id "gene4"; transcript_id "gene4.1";
M ref CDS 4 14 . + 0 gene_id "gene4"; transcript_id "gene4.1";
M ref start_codon 1 3 . + 0 gene_id "gene4"; transcript_id "gene4.1";
M ref stop_codon 14 16 . + 0 gene_id "gene4"; transcript_id "gene4.1";
2 changes: 2 additions & 0 deletions test_data/18/in1.fa
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
>Y
AAAATTTTGGGGCCCC
5 changes: 5 additions & 0 deletions test_data/18/in1.gtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
##sequence-region Y.11 1 16
Y ref exon 1 16 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
Y ref CDS 4 14 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
Y ref start_codon 1 3 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
Y ref stop_codon 14 16 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
2 changes: 2 additions & 0 deletions test_data/18/in2.fa
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
>H
GGGGAATTCCCCGGGG
5 changes: 5 additions & 0 deletions test_data/18/in2.gtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
##sequence-region F.11 3 27
H ref exon 1 16 . + 0 gene_id "gene2"; transcript_id "gene2.1";
H ref CDS 4 14 . + 0 gene_id "gene2"; transcript_id "gene2.1";
H ref start_codon 1 3 . + 0 gene_id "gene2"; transcript_id "gene2.1";
H ref stop_codon 14 16 . + 0 gene_id "gene2"; transcript_id "gene2.1";
2 changes: 2 additions & 0 deletions test_data/18/in3.fa
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
>M
CCCCGGGGAAAATTTT
4 changes: 4 additions & 0 deletions test_data/18/in3.gtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
M ref exon 1 16 . + 0 gene_id "gene4"; transcript_id "gene4.1";
M ref CDS 4 14 . + 0 gene_id "gene4"; transcript_id "gene4.1";
M ref start_codon 1 3 . + 0 gene_id "gene4"; transcript_id "gene4.1";
M ref stop_codon 14 16 . + 0 gene_id "gene4"; transcript_id "gene4.1";
2 changes: 2 additions & 0 deletions test_data/18/ref.fa
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
>X
ZZZZABBBBBDDDDDCCCCCIIIIIKKKKK
4 changes: 4 additions & 0 deletions test_data/18/ref.gtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
X ref exon 5 25 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
X ref CDS 8 22 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
X ref start_codon 5 7 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
X ref stop_codon 23 25 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
8 changes: 8 additions & 0 deletions test_data/19/gold.fa
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
>X
ZZZZABBBBBDDDDDCCCCCIIIIIKKKKK
>Y
AAAATTTTGGGGCCCC
>H
GGGGAATTCCCCGGGG
>M
CCCCGGGGAAAATTTT
18 changes: 18 additions & 0 deletions test_data/19/gold.gtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
X ref exon 5 25 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
X ref CDS 8 22 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
X ref start_codon 5 7 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
X ref stop_codon 23 25 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
##sequence-region Y 1 16
Y ref exon 1 16 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
Y ref CDS 4 14 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
Y ref start_codon 1 3 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
Y ref stop_codon 14 16 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
##sequence-region H 1 16
H ref exon 1 16 . + 0 gene_id "gene2"; transcript_id "gene2.1";
H ref CDS 4 14 . + 0 gene_id "gene2"; transcript_id "gene2.1";
H ref start_codon 1 3 . + 0 gene_id "gene2"; transcript_id "gene2.1";
H ref stop_codon 14 16 . + 0 gene_id "gene2"; transcript_id "gene2.1";
M ref exon 1 16 . + 0 gene_id "gene4"; transcript_id "gene4.1";
M ref CDS 4 14 . + 0 gene_id "gene4"; transcript_id "gene4.1";
M ref start_codon 1 3 . + 0 gene_id "gene4"; transcript_id "gene4.1";
M ref stop_codon 14 16 . + 0 gene_id "gene4"; transcript_id "gene4.1";
2 changes: 2 additions & 0 deletions test_data/19/in1.fa
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
>Z
AAAATTTTGGGGCCCC
5 changes: 5 additions & 0 deletions test_data/19/in1.gtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
##sequence-region Y.11 1 16
Z ref exon 1 16 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
Z ref CDS 4 14 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
Z ref start_codon 1 3 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
Z ref stop_codon 14 16 . + 0 gene_id "new_gene"; transcript_id "new_gene.1";
2 changes: 2 additions & 0 deletions test_data/19/in2.fa
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
>Y
GGGGAATTCCCCGGGG
5 changes: 5 additions & 0 deletions test_data/19/in2.gtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
##sequence-region F.11 3 27
H ref exon 1 16 . + 0 gene_id "gene2"; transcript_id "gene2.1";
H ref CDS 4 14 . + 0 gene_id "gene2"; transcript_id "gene2.1";
H ref start_codon 1 3 . + 0 gene_id "gene2"; transcript_id "gene2.1";
H ref stop_codon 14 16 . + 0 gene_id "gene2"; transcript_id "gene2.1";
2 changes: 2 additions & 0 deletions test_data/19/in3.fa
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
>M
CCCCGGGGAAAATTTT
5 changes: 5 additions & 0 deletions test_data/19/in3.gtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
##Test Data
M ref exon 1 16 . + 0 gene_id "gene4"; transcript_id "gene4.1";
K ref CDS 4 14 . + 0 gene_id "gene4"; transcript_id "gene4.1";
Z ref start_codon 1 3 . + 0 gene_id "gene4"; transcript_id "gene4.1";
M ref stop_codon 14 16 . + 0 gene_id "gene4"; transcript_id "gene4.1";
2 changes: 2 additions & 0 deletions test_data/19/ref.fa
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
>X
ZZZZABBBBBDDDDDCCCCCIIIIIKKKKK
4 changes: 4 additions & 0 deletions test_data/19/ref.gtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
X ref exon 5 25 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
X ref CDS 8 22 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
X ref start_codon 5 7 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
X ref stop_codon 23 25 . + 0 gene_id "ref_gene"; transcript_id "ref_gene.1";
118 changes: 118 additions & 0 deletions test_reform.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,5 +684,123 @@ def test_case_16(self):

os.chdir(wd)

def test_case_17(self):
"""
Case 17:
Testing Reform which adding new chrom
"""

wd = os.getcwd()
os.chdir('test_data/17/')

command = """
python3 ../../reform.py \
--new_chrom="Y" \
--in_fasta=in.fa \
--in_gff=in.gtf \
--ref_fasta=ref.fa \
--ref_gff=ref.gtf
"""

response = subprocess.getoutput(command)
print(response)

with open('gold.gtf', 'r') as f:
gold_gff = f.read()
with open('ref_reformed.gtf', 'r') as f:
new_gff = f.read()
print("Testing gtf")
self.assertListEqual(list(gold_gff), list(new_gff))
print("Done")

with open('gold.fa', 'r') as f:
gold_fa = f.read()
with open('ref_reformed.fa', 'r') as f:
new_fa = f.read()
print("Testing Fasta")
self.assertListEqual(list(gold_fa), list(new_fa))
print("Done")

os.chdir(wd)

def test_case_18(self):
"""
Case 18:
Testing Reform which adding multiple new chroms
"""

wd = os.getcwd()
os.chdir('test_data/18/')

command = """
python3 ../../reform.py \
--new_chrom="Y,H,M" \
--in_fasta=in1.fa,in2.fa,in3.fa \
--in_gff=in1.gtf,in2.gtf,in3.gtf \
--ref_fasta=ref.fa \
--ref_gff=ref.gtf
"""

response = subprocess.getoutput(command)
print(response)

with open('gold.gtf', 'r') as f:
gold_gff = f.read()
with open('ref_reformed.gtf', 'r') as f:
new_gff = f.read()
print("Testing gtf")
self.assertListEqual(list(gold_gff), list(new_gff))
print("Done")

with open('gold.fa', 'r') as f:
gold_fa = f.read()
with open('ref_reformed.fa', 'r') as f:
new_fa = f.read()
print("Testing Fasta")
self.assertListEqual(list(gold_fa), list(new_fa))
print("Done")

os.chdir(wd)

def test_case_19(self):
"""
Case 19:
Testing Reform with incorrect new chrom and comments in input FASTA
and annotation files. Also, testing reform with more formal printing
"""

wd = os.getcwd()
os.chdir('test_data/19/')

command = """
python3 ../../reform.py \
--new_chrom="Y,H,M" \
--in_fasta=in1.fa,in2.fa,in3.fa \
--in_gff=in1.gtf,in2.gtf,in3.gtf \
--ref_fasta=ref.fa \
--ref_gff=ref.gtf
"""

response = subprocess.getoutput(command)
print(response)

with open('gold.gtf', 'r') as f:
gold_gff = f.read()
with open('ref_reformed.gtf', 'r') as f:
new_gff = f.read()
print("Testing gtf")
self.assertListEqual(list(gold_gff), list(new_gff))
print("Done")

with open('gold.fa', 'r') as f:
gold_fa = f.read()
with open('ref_reformed.fa', 'r') as f:
new_fa = f.read()
print("Testing Fasta")
self.assertListEqual(list(gold_fa), list(new_fa))
print("Done")

os.chdir(wd)

if __name__ == '__main__':
unittest.main()