Skip to content

Commit

Permalink
Adds invert match
Browse files Browse the repository at this point in the history
  • Loading branch information
netbofia committed Oct 14, 2018
1 parent 5f84781 commit 3904d11
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions scripts/sequenceFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@
dest='outputFile',
required=False,
help='This is the output file. If output is sent to stdout')
parser.add_argument('--invert','-v',
action='store_true',
dest='invert',
required=False,
help='Invert match, does the inverse of the default action')


args = parser.parse_args()


sequences=args.sequences
data=args.data
stdout=False
Expand All @@ -46,6 +53,7 @@



invert=args.invert
if args.outputFile is None:
stdout=True
else:
Expand Down Expand Up @@ -76,16 +84,31 @@
fw.flush()
sequence=sequence.strip()
try:
outputLine=sequence+"\t"+d[sequence]+"\n"
if stdout:
print(outputLine.strip())
if invert:
del d[sequence]
else:
fw.write(outputLine)
outputLine=sequence+"\t"+d[sequence]+"\n"
if stdout:
print(outputLine.strip())
else:
fw.write(outputLine)
except KeyError:
pass

if not stdout:
fw.flush()
fw.close()
sequences.close()
data.close()
if invert:
for key in d:
outputLine=key+'\t'+d[key]+'\n'
if stdout:
print(outputLine.strip())
else:
counter+=1
if counter== buffer:
couter=0
fw.flush()
fw.write(outputLine)
else:
if not stdout:
fw.flush()
fw.close()
sequences.close()
data.close()

0 comments on commit 3904d11

Please sign in to comment.