88from Bio .SeqRecord import SeqRecord
99try :
1010 import pgzip as gzip_module
11- print ("Using pgzip for gzip operations." )
11+ print ("\n Using pgzip for gzip operations.\n " )
1212except ImportError :
1313 import gzip as gzip_module
14- print ("pgzip not found, falling back to gzip." )
14+ print ("\n pgzip not found, falling back to gzip.\n " )
1515
1616
1717def main ():
@@ -27,16 +27,32 @@ def main():
2727
2828 ## Sequential processing
2929 for index in range (iterations ):
30- ## Read the new fasta (to be inserted into the ref genome)
30+ # Start interation
31+ print ("-------------------------------------------" )
32+ print (f"Begin modification from in{ index + 1 } .fa" )
33+ print ("-------------------------------------------" )
34+ ## Read the new fasta (to be inserted into the ref genome)
3135 try :
36+ filename_fa = in_arg .in_fasta [index ]
37+ if not os .path .exists (filename_fa ):
38+ raise FileNotFoundError (f"Error: File { filename_fa } does not exist." )
39+ real_path_fa = os .path .realpath (filename_fa )
3240 record = list (SeqIO .parse (in_arg .in_fasta [index ], "fasta" ))[0 ]
3341 except IndexError :
34- filename = in_arg .in_fasta [index ].name
35- raise ValueError (f"Error: { filename } is not a valid FASTA file." )
42+ raise ValueError (f"Error: { filename_fa } is not a valid FASTA file." )
3643 except Exception as e :
3744 raise ValueError (f"Error parsing FASTA file: { str (e )} " )
45+ print ("Preparing to create new FASTA file" )
46+ print (f"Original FASTA: { real_path_fa } " )
47+ filename_gff = in_arg .in_gff [index ]
48+ if not os .path .exists (filename_gff ):
49+ raise FileNotFoundError (f"Error: File { filename_gff } does not exist." )
50+ real_path_gff = os .path .realpath (filename_gff )
51+ print ("Preparing to create new annotation file" )
52+ print (f"Original Annotation: { real_path_gff } " )
53+ print () ### print new line
3854
39- ## Generate index of sequences from ref reference fasta
55+ ## Generate index of sequences from ref reference fasta
4056 if prev_fasta_path :
4157 chrom_seqs = index_fasta (prev_fasta_path )
4258 os .remove (prev_fasta_path )
@@ -91,16 +107,12 @@ def main():
91107 SeqIO .write ([new_record ], f , "fasta" )
92108 else :
93109 SeqIO .write ([chrom_seqs [s ]], f , "fasta" )
94- print ("New fasta file created: " , new_fasta )
95-
96- print ("Preparing to create new annotation file" )
97110
98111 ## Read in new GFF features from in_gff
99112 in_gff_lines = get_in_gff_lines (in_arg .in_gff [index ])
100113
101114 ## Create a temp file for gff, if index is not equal to last iteration
102115 annotation_name , annotation_ext = get_ref_basename (in_arg .ref_gff )
103- print (in_arg .ref_gff )
104116 if index < iterations - 1 :
105117 temp_gff = tempfile .NamedTemporaryFile (delete = False , mode = 'w' , suffix = annotation_ext )
106118 temp_gff_name = temp_gff .name
@@ -117,7 +129,12 @@ def main():
117129 else :
118130 new_gff_path = create_new_gff (new_gff_name , in_arg .ref_gff , in_gff_lines , position , down_position , seq .id , len (str (record .seq )))
119131 prev_gff_path = new_gff_path
120- print ("New {} file created: {} " .format (annotation_ext .upper (), prev_gff_path ))
132+ if (index == iterations - 1 ):
133+ print ("------------------------------------------" )
134+ print ("Reform Complete" )
135+ print ("------------------------------------------" )
136+ print (f"New .fa file created: { os .path .realpath (new_fasta )} " )
137+ print (f"New { annotation_ext } file created: { os .path .realpath (new_gff_path )} " )
121138
122139
123140def index_fasta (fasta_path ):
@@ -394,6 +411,7 @@ def create_new_gff(new_gff_name, ref_gff, in_gff_lines, position, down_position,
394411 # and ends after down_position
395412 elif gff_feat_start <= position and gff_feat_end > down_position :
396413 print ("Feature split" )
414+ print (line )
397415 # Which side of the feature depends on the strand (we add this as a comment)
398416 (x , y ) = ("5" , "3" ) if gff_feat_strand == "+" else ("3" , "5" )
399417
0 commit comments